Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i want to draw a resistor image after knowing a value in ohm inside a picturebox control. i cannnot access creategraphics inside picture box. how do i do that? please help.
Posted
Comments
spirosvp 5-Jul-12 8:44am    
Did u finally draw the resistor?And if u did can u post the code? I am having the same problem.Tx!

You should use the Graphics of the PictureBox.Image, not of the Picturebox itself. Like this:
C#
Graphics g = Graphics.FromImage(pictureBox1.Image);
 
Share this answer
 
You could simply subclass the PictureBox class and use that.
An override on the OnPaint method should allow you to draw whatever you want.

Something like this should do the trick:

class CustomPictureBox : PictureBox
{
    protected override void OnPaint(PaintEventArgs pe)
    {
        base.OnPaint(pe);

        pe.Graphics.DrawRectangle(Pens.Aquamarine, new Rectangle(0, 0, 4, 4));
    }
}


Hope this helps,
Fredrik Bornander
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900