群组框的边框和颜色 [英] Groupbox Border and Colour

查看:383
本文介绍了群组框的边框和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Windows窗体应用程序中编码组框的边框和边框颜色?

How can I code the border and border colour of a groupbox in a Windows Form Application?

推荐答案

您可以通过向其添加一些图形呈现来装饰任何控件.这是通过处理事件System.Windows.Forms.Control.Paint或在派生类中覆盖虚拟方法System.Windows.Forms.Control.OnPaint来完成的.
不要重复一个常见的错误:不要创建System.Drawing.Graphics的实例! —从事件参数中获取一个实例.

请参阅 http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx [ ^ ].

一个更好的提示:由于需要边框,因此调整DisplayRectangle会非常有帮助.您可以在派生类中重写此虚拟属性,以防止子元素与边框重叠,这会在边缘附近占用一些空间.

请参阅 http://msdn.microsoft.com/en-us/library/system.windows.forms.control.displayrectangle.aspx [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [在mdi子表单之间画线 [在面板上捕获图形 [
You can decorate any control by adding some graphical rendering to it. This is done by handling the event System.Windows.Forms.Control.Paint or overriding the virtual method System.Windows.Forms.Control.OnPaint in a derived class.

Don''t repeat a common mistake: don''t create an instance of System.Drawing.Graphics! — take an instance from event arguments.

Please see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.aspx[^].

One finer hint: as you need a border, it will be very helpful to adjust the DisplayRectangle. You can override this virtual property in derived class to prevent overlapping of the children with your border which will take up some room near the edges.

Please see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.displayrectangle.aspx[^].

For more advanced information on rendering, please see my past answers:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^].

—SA




尝试点击以下链接:

http://social.msdn.microsoft.com /forums/zh-CN/winforms/thread/cfd34dd1-b6e5-4b56-9901-0dc3d2ca5788/ [
Hi,

try to chcek following link:

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/cfd34dd1-b6e5-4b56-9901-0dc3d2ca5788/[^]

Regards
Robert


通过重写OnPaint(PaintEventArgs e)方法

默认OnPaint方法的源代码是
可从Microsoft获得 [
By overriding the OnPaint(PaintEventArgs e) method

The source code for the default OnPaint method is available from Microsoft[^]

Best regards
Espen Harlinn


这篇关于群组框的边框和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆