y_zyx
y_zyx

Reputation: 642

graphics panel in c#

Instead of setting image using 'background' property, I would like to draw the image using Graphics class on a panel. How can I do it in C#.Net?

Upvotes: 2

Views: 1784

Answers (2)

crypted
crypted

Reputation: 10306

you can try following piece of code.

 public class ImagePanel:Panel
{
    private Image image;

    public Image Image
    {
        get { return image; }
        set
        {

            image = value;
            Refresh();
        }
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        if(Image!=null)
        {
            e.Graphics.DrawImage(this.Image,Point.Empty);
        }
        base.OnPaint(e);
    }
}

Upvotes: 1

Pranay Rana
Pranay Rana

Reputation: 176946

Make use of System.Drawing.Graphics class to draw the things.

Details : http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx related to drawing

example : http://www.techotopia.com/index.php/Drawing_Graphics_in_C_Sharp

Upvotes: 1

Related Questions