private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
NumberOfBets++;
if ((e.X >= 40 && e.X <= 125) && (e.Y >= 0 && e.Y <= 26))
{
bettingStatus[0]++;
for (int x; x < 10; x++)
{
Graphics graphic = (???)
}
}
I'm trying to draw an image in this MouseDown method. I have NO clue what goes in the "(???)" part.
-
You need to get the
Graphics
from somewhere, probablypictureBox1
in your case:Graphics graphic = pictureBox1.CreateGraphics();
...But are you sure you want to be drawing in a
MouseDown
event handler? It won't be repainted if any part gets redrawn. You'd probably be better off doing all your drawing in aPaint
event handler and setting a flag inMouseDown
instead. Then invalidate the region you want to be redrawn to draw the new image.Or, if your images are going to be more static, you can create a
Bitmap
, draw on that, then set theImage
of yourPictureBox
to point to theBitmap
instead. For example:Bitmap bmp = new Bitmap(200, 100); Graphics graphics = Graphics.FromImage(bmp); //do drawing here pictureBox1.Image = bmp;
-
// Create a Graphics object for the pictureBox1 control. Graphics g = pictureBox1.CreateGraphics();
Read more: MSDN: Graphics Class
You should draw in the Paint event, because if you don't, you will loose your drawings if the control is repainted. The PaintEventArgs passed to the Paint event handler has a Property named Graphics (of type System.Drawing.Graphics) which you can draw on.
0 comments:
Post a Comment