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



 button按扭初始问题??????????????????????????????????????????


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


button按扭初始问题??????????????????????????????????????????[已结贴,结贴人:nikefly]
发表于:2007-12-27 08:47:03 楼主
button按扭初始问题

using   system;  
using   system.collections.generic;  
using   system.componentmodel;  
using   system.data;  
using   system.drawing;  
using   system.text;  
using   system.windows.forms;  

namespace   windowsapplication6  
{  
public   partial   class   form1   :   form  
{  
public   form1()  
{  
initializecomponent();  
}  
private   void   button1_paint(object   sender,   system.windows.forms.painteventargs   e)  
{  
//初始化一个graphicspath类的对象  
system.drawing.drawing2d.graphicspath   mygraphicspath   =   new   system.drawing.drawing2d.graphicspath();  
//确定一个字符串,该字符串就是控件的形状  
string   stringtext   =   "arial";  
//确定字符串的字体  
fontfamily   family   =   new   fontfamily(stringtext);  
//确定字符串的风格  
int   fontstyle   =   (int)fontstyle.bold;  
//确定字符串的高度  
int   emsize   =   35;  
//确定字符串的起始位置,它是从控件开始计算而非窗体  
pointf   origin   =   new   pointf(0,   0);  
//一个stringformat对象来确定字符串的字间距以及对齐方式  
stringformat   format   =   new   stringformat(stringformat.genericdefault);  
//用addstring方法创建字符串  
mygraphicspath.addstring(stringtext,   family,   fontstyle,   emsize,   origin,   format);  
//将控件的region属性设置为上面创建的graphicspath对象  
custombutton.region   =   new   region(mygraphicspath);  
}  
private   void   button1_click(object   sender,   eventargs   e)  
{  

}  
}  
}  
上面的代码是初始按扭的造型   为什么运行时候显示不出   如果把button1_paint代码放在button1_click下,然后运行点击可以看到效果   但这不是我想要的结果   我想一开始能看到彩色无筐字体的按扭,到底哪不对????
发表于:2007-12-27 09:16:021楼 得分:7
把代码写到一个函数里,在load事件里调用一下
发表于:2007-12-27 09:18:032楼 得分:0
paint事件在程序运行是不会自动触发的  
发表于:2007-12-27 09:19:463楼 得分:8
开始的时候不显示的话,只能说明button1_paint没有被执行,如果button1_paint事件写得正确的话,在load的时候执行一次button1.refresh()可能就可以了
发表于:2007-12-27 09:19:574楼 得分:15
设置按钮的形状不要在paint事件中,自己从button派生一个类,在构造函数中设置button形状。
发表于:2007-12-27 09:25:025楼 得分:0
同意4楼的说法
发表于:2007-12-27 11:01:396楼 得分:0
学习。。。。
发表于:2007-12-27 12:12:027楼 得分:0
不要在paint中设置形状,这从根本方向上就错了。自己从button派生。
发表于:2007-12-27 12:12:538楼 得分:0
而且这样做的话,每个paint事件中。。都会计算,设置形状,,效率低下,浪费资源。
发表于:2007-12-28 08:58:219楼 得分:0
感谢已经冲破极限~~~~~~~~~~~~哈哈哈


快速检索

最新资讯
热门点击