在窗体上绘背景图案
在一个窗体上绘制背景图,是一项很有用的功能
首先在你的工程里添加背景图片,然后右击选择生成类型为嵌入式资源
记得添加名称空间
using System.Reflection;
然后获取嵌入式图片资源
首先在你的工程里添加背景图片,然后右击选择生成类型为嵌入式资源
记得添加名称空间
using System.Reflection;
然后获取嵌入式图片资源
1
private Image backgroundImage;
2
backgroundImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("BkgndImage.7009.gif"));
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
最后一步就是绘制背景了
1
protected override void OnPaint(PaintEventArgs e)
2
{
3
e.Graphics.DrawImage(backgroundImage, this.ClientRectangle, new Rectangle(0, 0, this.backgroundImage.Width, this.backgroundImage.Height), GraphicsUnit.Pixel);
4
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)