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;
}
Graphics
as a parameter. – PogeyPaint
method, you should only ever draw to thee.Graphics
instance. But what do you want to do here? Do you want to draw a circle every time thePictureBox
'sPaint
event is raised? Do you want thePictureBox.Image
property to be set to aBitmap
where you've already drawn a circle? Something else? See stackoverflow.com/help/how-to-ask and stackoverflow.com/help/mcve – TrymaCircle()
method almost does that. ChangeFillRectangle()
toFillCircle()
, and you'll get a circle instead. Then just assign the return value of that method to thepictureBox2.Image
property (e.g. in yourForm
constructor). You can get rid of thePaint
event handler altogether. If you want a real answer, you need to post a better code example. See stackoverflow.com/help/mcve – Tryma