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
Graphicsfrom somewhere, probablypictureBox1in your case:Graphics graphic = pictureBox1.CreateGraphics();...But are you sure you want to be drawing in a
MouseDownevent handler? It won't be repainted if any part gets redrawn. You'd probably be better off doing all your drawing in aPaintevent handler and setting a flag inMouseDowninstead. 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 theImageof yourPictureBoxto point to theBitmapinstead. 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