您的位置:程序门 -> .net技术 -> vb.net



如何改变groupbox的边框线颜色?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何改变groupbox的边框线颜色?
发表于:2008-03-19 20:08:39 楼主
如何改变groupbox的边框线颜色?是否需要重写groupbox?具体怎样实现?
发表于:2008-03-20 08:30:361楼 得分:0
自己写一个吧
vb.net code
imports system.componentmodel public class groupboxcontrol inherits panel private lbl as label private mbordercolor as color = color.blue <browsable(true)> _ public overrides property text() as string get return lbl.text end get setbyval value as string) lbl.text = value me.invalidate() end set end property public property bordercolor() as color get return mbordercolor end get setbyval value as color) mbordercolor = value me.invalidate() end set end property private sub groupboxcontrol_controladded(byval sender as object, byval e as system.windows.forms.controleventargs) handles me.controladded if e.control.left < 5 then e.control.left = 5 if e.control.top < 15 then e.control.top = 15 if e.control.right > me.width - 10 then e.control.left = me.width - 10 - e.control.width if e.control.bottom > me.height - 10 then e.control.top = me.height - 10 - e.control.height end sub private sub groupboxcontrol_paint(byval sender as object, byval e as system.windows.forms.painteventargs) handles me.paint e.graphics.drawrectangle(new pen(mbordercolor), new rectangle(2, 8, me.width - 5, me.height - 12)) end sub public sub new() lbl = new label lbl.autosize = true lbl.text = "groupbox" me.controls.add(lbl) end sub private sub groupboxcontrol_resize(byval sender as object, byval e as system.eventargs) handles me.resize lbl.location = new point(10, 1) end sub end class
发表于:2008-03-20 14:55:202楼 得分:0
还不如把边框设为不显示
然后自己画4条线上去
发表于:2008-03-20 17:02:133楼 得分:0
这样变通的方法当然都能实现。我现在的问题是:不用自己画,就用groupbox这个控件,通过重写的方法能否实现改变边框线的颜色?
发表于:2008-03-20 21:08:034楼 得分:0
除了我上面提到的方法外,再提供给lz一个简单方法吧
vb.net code
public class form1 dim withevents testgroupbox as new groupbox private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load testgroupbox.text = "testgroupbox1" testgroupbox.visible = true me.controls.add(testgroupbox) end sub private sub testgroupbox_paint(byval sender as object, byval e as system.windows.forms.painteventargs) handles testgroupbox.paint e.graphics.clear(testgroupbox.backcolor) e.graphics.drawstring(testgroupbox.text, testgroupbox.font, brushes.red, 10, 1) e.graphics.drawline(pens.blue, 1, 7, 8, 7) e.graphics.drawline(pens.blue, 90, 7, testgroupbox.width - 2, 7) e.graphics.drawline(pens.blue, 1, 7, 1, testgroupbox.height - 2) e.graphics.drawline(pens.blue, 1, testgroupbox.height - 2, testgroupbox.width - 2, testgroupbox.height - 2) e.graphics.drawline(pens.blue, testgroupbox.width - 2, 7, testgroupbox.width - 2, testgroupbox.height - 2) end sub end class




快速检索

最新资讯
热门点击