c# GDI画矩形
c是一个pictruebox控件。Graphicsg=c.CreateGraphics();Brushb=newSolidBrush(Color.Black);m_Top...
c是一个pictruebox控件。
Graphics g = c.CreateGraphics();
Brush b = new SolidBrush(Color.Black);
m_TopCenter=new Rectangle(0,0,100,100);
g.FillRectangle(b, m_TopCenter);
b.Dispose();
g.Dispose();
为什么这段程序画不出一个矩形。编译通过了 展开
Graphics g = c.CreateGraphics();
Brush b = new SolidBrush(Color.Black);
m_TopCenter=new Rectangle(0,0,100,100);
g.FillRectangle(b, m_TopCenter);
b.Dispose();
g.Dispose();
为什么这段程序画不出一个矩形。编译通过了 展开
2个回答
展开全部
绘图代码需要放在Picturebox的Paint事件里完成,使用的绘图对象应该是事件参数里的Graphics.
PictureBox pbx = new PictureBox();
pbx.Paint += new PaintEventHandler(pbx_Paint);
void pbx_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawRectangle(new Pen(Color.Red, 2.0f), new Rectangle(10, 10, 300, 300));
}
PictureBox pbx = new PictureBox();
pbx.Paint += new PaintEventHandler(pbx_Paint);
void pbx_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawRectangle(new Pen(Color.Red, 2.0f), new Rectangle(10, 10, 300, 300));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询