c# 中gdi 绘不出图形

来源:百度知道 编辑:UC知道 时间:2024/06/14 12:27:17
想在picturebox1中绘制图形,却画不出东西。
大致代码如下:
Bitmap bmp = new Bitmap(500,500);
Graphics g = Graphics.FromImage(bmp);
Brush brush = new SolidBrush(color);
g.FillPie(brush,pictureBox1.ClientRectangle, startAngle, sweepAngle);

而且不止是pictureBox,在很多地方都绘不出东西,只有绘图区域为ClientRectangle时才能绘出东西,但这个时候还会被其他控件挡住。

请问这是为什么?
backgroundImage=bmp;
以后确实可以解决,但是好奇怪,我的代码明明是希望直接把图画在pictureBox这个控件上的(g.FillPie(brush,pictureBox1.ClientRectangle, startAngle, sweepAngle); )
而不是希望说先画好一个bmp然后再把它做为picturebox的背景存在的。(pictureBox1.BackgroundImage = bmp; )
有人能告诉我为什么吗?

pictureBox没和BMP绑定,在你的代码最后加上
pictureBox1.BackgroundImage = bmp;
试试

TextRenderer是用来在图片上加文本的

试试TextRenderer的方法
我从你程序上不知道你要画什么。这个是画字符串的。
TextRenderer.DrawText(Graphics g, string s,Font font, Rectangle rectangle, Color color, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);