图片框的paintEvent与其他方法 [英] PictureBox PaintEvent with other method
问题描述
有只有一个在我的PictureBox的形式,我想用这个图片框的方法来画圆,但我不能做到这一点,而不是working.The方法是:
私人位图圈()
{
BMP位图;
显卡GFX;
SolidBrush firca_dis =新SolidBrush(Color.FromArgb(192,0,192)); BMP =新位图(40,40);
GFX = Graphics.FromImage(BMP);
gfx.FillRectangle(firca_dis,0,0,40,40); 返回BMP;
}
图片框
私人无效pictureBox2_Paint(对象发件人,PaintEventArgs的E)
{
显卡GFX = Graphics.FromImage(圆());
GFX = e.Graphics;
}
您需要决定你想要做什么:
- 绘制的进入图片或
- 吸取到控制?!
您code是两者的混合,这就是为什么它不工作..!
下面是如何绘制的到的控制
:
私人无效pictureBox1_Paint(对象发件人,PaintEventArgs的E)
{
e.Graphics.DrawEllipse(Pens.Red,新的Rectangle(3,4,44,44));
..
}
下面是如何绘制的到的图片
的图片框
::
无效drawIntoImage()
{
使用(图形G = Graphics.FromImage(pictureBox1.Image))
{
G.DrawEllipse(Pens.Orange,新的Rectangle(13,14,44,44));
..
}
//当donw所有图纸可以通过调用执行显示更新:
pictureBox1.Refresh();
}
画这两种方式是永久性的。后者改变图像的像素,前者不
因此,如果像素被绘制成图像和缩放,拉伸或迁移的图像像素会去用它。绘制在顶部PictureBox控件的像素不会那么做的!
当然,这两种方法来绘制,你可以改变所有常用的部件,如绘图命令,可能添加 FillEllipse函数
在 DrawEllipse
的笔
和刷子
与他们的画笔类型和颜色
和尺寸。
There is only one picturebox in my form and I want to drawcircle with a method on this picturebox but I cant do that and not working.The method is:
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;
}
Picturebox
private void pictureBox2_Paint(object sender, PaintEventArgs e)
{
Graphics gfx= Graphics.FromImage(Circle());
gfx=e.Graphics;
}
You need to decide what you want to do:
- Draw into the Image or
- draw onto the Control?!
Your code is a mix of both, which is why it doesn't work..!
Here is how to draw onto the Control
:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44));
..
}
Here is how to draw into the Image
of the PictureBox
::
void drawIntoImage()
{
using (Graphics G = Graphics.FromImage(pictureBox1.Image))
{
G.DrawEllipse(Pens.Orange, new Rectangle(13, 14, 44, 44));
..
}
// when donw with all drawing you can enforce the display update by calling:
pictureBox1.Refresh();
}
Both ways to draw are persistent. The latter changes to pixels of the Image, the former doesn't.
So if the pixels are drawn into the Image and you zoom, stretch or shift the Image the pixel will go with it. Pixels drawn onto the Top of the PictureBox control won't do that!
Of course for both ways to draw, you can alter all the usual parts like the drawing command, maybe add a FillEllipse
before the DrawEllipse
, the Pens
and Brushes
with their Brush type and Colors
and the dimensions..
这篇关于图片框的paintEvent与其他方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!