开发者

graphics panel in c#

Instead of setting image using 'background' property, I would like to draw the image using Graphic开发者_运维百科s class on a panel. How can I do it in C#.Net?


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);
    }
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜