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;
}
Graphicsas a parameter.Paintmethod, you should only ever draw to thee.Graphicsinstance. But what do you want to do here? Do you want to draw a circle every time thePictureBox'sPaintevent is raised? Do you want thePictureBox.Imageproperty to be set to aBitmapwhere you've already drawn a circle? Something else? See stackoverflow.com/help/how-to-ask and stackoverflow.com/help/mcveCircle()method almost does that. ChangeFillRectangle()toFillCircle(), and you'll get a circle instead. Then just assign the return value of that method to thepictureBox2.Imageproperty (e.g. in yourFormconstructor). You can get rid of thePaintevent handler altogether. If you want a real answer, you need to post a better code example. See stackoverflow.com/help/mcve