开发者

graphics panel in c#

开发者 https://www.devze.com 2023-03-04 04:48 出处:网络
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.

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

精彩评论

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