我的表单中只有一个picturebox,我想在这个picturebox上画一个方法,但是我不能这样做,而不是working.The方法:
private Bitmap Circle()
{
Bitmap bmp;
Graphics gfx;
SolidBrush firca_dis=new SolidBrush(Color.FromArgb(192,0,192));
bmp = new Bitmap(40, 40);
gfx = Graphics.FromImage(bmp);
gfx.FillRectangle(firca_dis, 0, 0, 40, 40);
return bmp;
}图片盒
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
Graphics gfx= Graphics.FromImage(Circle());
gfx=e.Graphics;
}发布于 2014-12-07 10:40:28
你需要决定你想做什么:
您的代码是两者的混合,这就是它不能工作的原因。
下面是如何将绘制到 Control上
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44));
..
}下面是如何将绘制到中-- PictureBox的Image
void drawIntoImage()
{
using (Graphics G = Graphics.FromImage(pictureBox1.Image))
{
G.DrawEllipse(Pens.Orange, new Rectangle(13, 14, 44, 44));
..
}
// when done with all drawing you can enforce the display update by calling:
pictureBox1.Refresh();
}这两种绘画方式都是持久的。后者改变为图像的像素,前者不改变。
因此,如果像素被绘制到图像中,然后缩放、拉伸或移动图像,像素就会随之而去。绘制到PictureBox控件顶部的像素不会这样做!
当然,对于这两种绘制方式,您都可以更改所有常用的部分,比如绘图命令,可以在FillEllipse之前添加一个DrawEllipse,Pens和Brushes,以及它们的刷类型和Colors以及维度。
发布于 2014-12-07 02:24:51
private static void DrawCircle(Graphics gfx)
{
SolidBrush firca_dis = new SolidBrush(Color.FromArgb(192, 0, 192));
Rectangle rec = new Rectangle(0, 0, 40, 40); //Size and location of the Circle
gfx.FillEllipse(firca_dis, rec); //Draw a Circle and fill it
gfx.DrawEllipse(new Pen(firca_dis), rec); //draw a the border of the cicle your choice
}https://stackoverflow.com/questions/27337825
复制相似问题