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

VulpesRank #55 · 29.2K reputationPosted Aug 20, 2011, 4:13 AM EDT
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;
}
Roy S194 reputationPosted Aug 18, 2011, 8:07 AM EDT
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);
}
}
VulpesRank #55 · 29.2K reputationPosted Aug 18, 2011, 8:21 AM EDT
mike DelvottiRank #7,298 · 244 reputationPosted Aug 18, 2011, 8:21 AM EDT
Ah, I worked it out on this line:
Graphics
g = this.splitContainer1.Panel1.CreateGraphics();mike DelvottiRank #7,298 · 244 reputationPosted Aug 20, 2011, 2:28 AM EDT
Could I be missing another function?
mike DelvottiRank #7,298 · 244 reputationPosted Aug 20, 2011, 3:19 AM EDT
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;