实现步骤
如下:
1. 建立winform应用程序
2. 找到窗体的Load事件,双击进行编辑
3. 编写方法,主要的代码如下:
- class BitmapRegion {
- public BitmapRegion() { }
- /// <summary> /// Create and apply the region on the supplied control
- /// 创建支持位图区域的控件(目前有button和form) /// </summary>
- /// <param name="control">The Control object to apply the region to控件</param> /// <param name="bitmap">The Bitmap object to create the region from位图</param>
- public static void CreateControlRegion(Control control, Bitmap bitmap) {
- // Return if control and bitmap are null //判断是否存在控件和位图
- if (control == null || bitmap == null) return;
- // Set our control''s size to be the same as the bitmap
- //设置控件大小为位图大小 control.Width = bitmap.Width;
- control.Height = bitmap.Height; // Check if we are dealing with Form here
- //当控件是form时 if (control is System.Windows.Forms.Form)
- { // Cast to a Form object
- //强制转换为FORM Form form = (Form)control;
- // Set our form''s size to be a little larger that the bitmap just // in case the form''s border style is not set to none in the first place
- //当FORM的边界FormBorderStyle不为NONE时,应将FORM的大小设置成比位图大小稍大一点 form.Width = control.Width;
- form.Height = control.Height; // No border
- //没有边界 form.FormBorderStyle = FormBorderStyle.None;










