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
精彩评论