GDI+:自定义控件时如何使用Region来输出特定区域
来源:互联网 发布:网络兼职什么意思 编辑:程序博客网 时间:2024/06/06 20:12
这是我的一个小工具中用到的一个功能。这个工具需要能对图片进行一些编辑和保存
我我们的一个功能就是,在图片的任意位置双击之后,都会添加一个附加的控件出来,并且显示在图片上
看起来很不错,但是那个白色的正方形背景是在不好看,能不能只是用那个圆圈呢?下面这样显然更加好一些
那这是如何做到的呢?按说所有的Windows Forms控件在Render出来的时候,都会有一个矩形的区域的。看看下面代码吧
protected override void OnPaint(PaintEventArgs e) { Graphics g = this.CreateGraphics(); g.DrawEllipse( new Pen(Color.Red), new Rectangle(new Point(0, 0), new Size(this.Width-5,this.Height-5))); if (Selected) g.FillEllipse(new SolidBrush(Color.Yellow), new Rectangle(new Point(0, 0), new Size(this.Width - 5, this.Height - 5))); GraphicsPath p = new GraphicsPath(); p.AddEllipse(new Rectangle(new Point(0, 0), new Size(this.Width - 5, this.Height - 5))); this.Region = new Region(p);//设置控件的区域是一个圆圈 g.Save(); }.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }
关于控件的Region属性,也可以参考 http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.region.aspx
按照这个思路,我们当然也可以画出某些带有圆角的控件,或者不规则的控件。尝试一下,你会改代码,让他输出下面这样的效果吗
- GDI+:自定义控件时如何使用Region来输出特定区域
- C++ GDI+ Region区域
- 自定义控件之绘图篇:区域(Region)
- 自定义控件使用GDI+画图片
- 如何使用自定义控件
- Region区域
- 【转】在GDI+使用区域
- MFC中使用GDI+绘制自定义的控件
- Drupal中添加自定义区域(Region)放置区块(Block)
- Drupal中添加自定义区域(Region)放置区块(Block)
- C# 自定义控件如何使用
- Android如何使用自定义控件
- 如何让 WebBrowser控件 使用BeforeNavigate2(...)屏蔽特定页面
- 如何让 WebBrowser控件 使用BeforeNavigate2(...)屏蔽特定页面
- 如何正确地使用#region指令
- Android自定义控件系列 十:利用添加自定义布局来搞定触摸事件的分发,解决组合界面中特定控件响应特定方向的事件
- Android自定义控件系列 十:利用添加自定义布局来搞定触摸事件的分发,解决组合界面中特定控件响应特定方向的事件
- Android自定义控件系列 十:利用添加自定义布局来搞定触摸事件的分发,解决组合界面中特定控件响应特定方向的事件
- Silverlight:设计器的问题
- Silverlight:如何在使用WCF的时候动态指定服务地址
- MVC:如何设计多语言支持
- MVC:如何使用站点地图
- GDI+:如何绘制透明色
- GDI+:自定义控件时如何使用Region来输出特定区域
- 为什么采用filter实现了字符集的统一编码
- Windows性能调优: Perfomn.exe 和Perfmon /res
- 分页的公共代码
- SQL Server:General guidelines to use to configure the MAXDOP option{转载}
- SQL Server:Trace and Replay Objects: A New API for SQL Server Tracing and Replay
- PowerCommands for Visual Studio 2008
- ASP.NET MVC 2
- ASP.NET MVC 2中的数据验证