C#:生成基于WinForm的不规则窗体或控件
来源:互联网 发布:淘宝网店客服技巧 编辑:程序博客网 时间:2024/05/16 15:51
/* ----------------------------------------------------------文件名称:ImageControl.cs作者:秦建辉MSN:splashcn@msn.comQQ:36748897博客:http://blog.csdn.net/jhqin开发环境: Visual Studio V2010 .NET Framework 4 Client Profile版本历史: V1.12011年11月01日接口优化 V1.02010年08月02日生成基于WinForm的不规则窗体或控件------------------------------------------------------------ */using System.Drawing;using System.Drawing.Drawing2D;using System.Windows.Forms;namespace Splash.Drawing{ /// <summary> /// 生成基于WinForm的不规则窗体或控件 /// </summary> public static class ImageControl { /// <summary> /// 设置控件区域 /// </summary> /// <param name="control">要设置的控件</param> /// <param name="bitmap">要使用的图像</param> /// <remarks>Control的扩展方法</remarks> public static void SetRegion(this Control control, Bitmap bitmap) { // 判断是否存在控件和位图 if (control == null || bitmap == null) return; // 设置控件大小为位图大小 control.Size = bitmap.Size; if (control is Form) { // 当控件是Form时 // 强制转换为Form Form ImageForm = control as Form; // 当Form的边界FormBorderStyle不为NONE时,应将FORM的大小设置成比位图大小稍大一点 ImageForm.Size = control.Size; // 去掉边界 ImageForm.FormBorderStyle = FormBorderStyle.None; // 将位图设置成窗体背景图片 ImageForm.BackgroundImage = bitmap; // 计算位图中不透明部分的边界 GraphicsPath graphicsPath = CreateGraphicsPath(bitmap); // 应用新的区域 ImageForm.Region = new Region(graphicsPath); } else if (control is Button) { // 当控件是Button时 // 强制转换为Button Button ImageButton = control as Button; // 不显示Button Text ImageButton.Text = System.String.Empty; // 设置Button的背景图片 ImageButton.BackgroundImage = bitmap; // 计算位图中不透明部分的边界 GraphicsPath graphicsPath = CreateGraphicsPath(bitmap); // 应用新的区域 ImageButton.Region = new Region(graphicsPath); } } /// <summary> /// 创建图层路径 /// </summary> /// <param name="bitmap">用于创建图层路径的位图</param> /// <returns>图层路径</returns> /// <remarks>Bitmap的扩展方法</remarks> public static GraphicsPath CreateGraphicsPath(this Bitmap bitmap) { return CreateGraphicsPath(bitmap, Color.Empty); } /// <summary> /// 创建图层路径 /// </summary> /// <param name="bitmap">用于创建图层路径的位图</param> /// <param name="colorTransparent">透明色,如果为Color.Empty,则使用第一点作为透明色</param> /// <returns>图层路径</returns> /// <remarks>Bitmap的扩展方法</remarks> public static GraphicsPath CreateGraphicsPath(this Bitmap bitmap, Color colorTransparent) { // 创建GraphicsPath GraphicsPath graphicsPath = new GraphicsPath(); if (colorTransparent == Color.Empty) { // 使用左上角第一点的颜色作为透明色 colorTransparent = bitmap.GetPixel(0, 0); } // 遍历所有行(Y方向) for (int y = 0; y < bitmap.Height; y++) { // 遍历所有列(X方向) for (int x = 0; x < bitmap.Width; x++) { // 如果是不需要透明处理的点则标记,然后继续偏历 if (bitmap.GetPixel(x, y) != colorTransparent) { // 记录当前 int xBegin = x; int xEnd = x + 1; // 从找到的不透明点开始,继续寻找不透明点,一直到找到或则达到图片宽度 for (; xEnd < bitmap.Width; xEnd++) { if (bitmap.GetPixel(xEnd, y) == colorTransparent) { break; } } // 将不透明点加到GraphicsPath graphicsPath.AddRectangle(new Rectangle(xBegin, y, xEnd - xBegin, 1)); x = xEnd; } } } return graphicsPath; } }}
- C#:生成基于WinForm的不规则窗体或控件
- WinForm生成不规则窗体
- C# winform 实现(不规则)窗体或者控件的拖动
- C# winform 实现(不规则)窗体或者控件的拖动
- 不规则窗体或控件(想怎样不规则就怎样不规则)
- Winform中不规则窗体制作的解决方案
- Winform不规则窗体的实现心得
- winform移动窗体或窗体中的控件
- WinForm不规则窗体
- 【C#】[窗体]不规则窗体
- 【C#】c#winform 窗体及其控件的自适应
- 不规则窗体和控件的创建
- WinForm中创建不规则窗体
- WinForm界面设计(不规则窗体)
- C# winform制作不规则窗体
- [SY的专栏]C#WinForm制作异形窗体/控件
- 用C#(Winform)的Timer控件让窗体左右飘动
- C# winform中不规则窗体制作的解决方案
- JProfiler 5.1.2破解安装与使用
- UIAlertView的用法
- 用镜像理论去思考软件代码
- CONFIG_DM9000_BASE 0x20000000
- C++ 虚函数表解析
- C#:生成基于WinForm的不规则窗体或控件
- Oracle 绑定变量 示例
- ”凤毛麟角的ZendFramework“-ZendFramework使用Jquery第三方插件。
- Oracle 表三种连接方式介绍(SML + NL + HJ)
- Web.XML 配置详解
- ABCPdf的使用.
- Js判断图片是否存在
- doxygen--03--分组grouping
- 杭州朗新科技怎么样啊有什么发展前景啊