Guys i'm trying to print text over the top of a background graphic where the mouse is clicked on a click event, so for instance if the radio button is true where ever the mouse is clicked it will print "DL" on the screen.
Something like:
if (radioButton_DL == true)
{
Print "DL" at mouse coordinates on screen.
}
What would be the best way to achieve this?
Loading
VulpesPosted Aug 20, 2011, 8:13 AM
Yes, if you want the drawing to be persisted when you save the image, you have to draw on the image in the picturebox rather than over the top of it.
I couldn't really see why you needed two Graphics objects. One should be enough:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
Bitmap myBitmap = new Bitmap(pictureBox1.Image);
Graphics g = Graphics.FromImage(myBitmap);
g.DrawString("D", new Font("Arial", 20), Brushes.Red, e.Location);
g.Dispose();
pictureBox1.Image = myBitmap;
}
mike DelvottiPosted Aug 20, 2011, 7:19 AM
Bitmap myBitmap = new Bitmap(pictureBox1.Image);
Graphics g1 = Graphics.FromImage(myBitmap);
Graphics g2 = this.pictureBox1.CreateGraphics();
g1.DrawString("D", new Font("Arial", 20), Brushes.Red, e.Location);
g2.DrawString("D", new Font("Arial", 20), Brushes.Red, e.Location);
g1.Dispose();
g2.Dispose();
this.pictureBox1.Image = myBitmap;
mike DelvottiPosted Aug 20, 2011, 6:28 AM
Could I be missing another function?
mike DelvottiPosted Aug 18, 2011, 12:21 PM
Ah, I worked it out on this line:
Graphics
g = this.splitContainer1.Panel1.CreateGraphics();VulpesPosted Aug 18, 2011, 12:21 PM
Roy SPosted Aug 18, 2011, 12:07 PM
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (radDL.Checked)
{
Graphics g = this.CreateGraphics();
g.DrawString("DL", new Font("Arial", 20), Brushes.Red, e.Location);
}
}