2008年(884)
分类: C/C++
2008-08-06 10:03:05
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) {//先创建路径,在路径中画个椭圆,然后用这个路径创建区域,最后把区域给按钮并设置按钮的范围 System::Drawing::Drawing2D::GraphicsPath *path=new System::Drawing::Drawing2D::GraphicsPath();//创建路径 path->AddEllipse(Rectangle(10,10,80,80));//在路径中画椭圆 System::Drawing::Region *reg=new System::Drawing::Region(path);//利用路径创建区域 button1->Bounds=System::Drawing::Rectangle(50,50,100,100);//设定按钮显示位置和最大响应范围,只能是矩形 button1->Region=reg;//设定按钮的实际控制区域,可以是任意形状 } //下面的内容就简单了,设置按钮在不同状态下的不同样式,没有响应焦点状态,就当作留给读者的作业吧^_^ private: System::Void button1_MouseDown(System::Object * sender, System::Windows::Forms::MouseEventArgs * e) { button1->Image=Image::FromFile("bitmap.bmp"); } private: System::Void button1_MouseUp(System::Object * sender, System::Windows::Forms::MouseEventArgs * e) { button1->BackColor=SystemColors::AppWorkspace; button1->Image=NULL; } private: System::Void button1_MouseEnter(System::Object * sender, System::EventArgs * e) { button1->BackColor=SystemColors::AppWorkspace; button1->Image=NULL; } private: System::Void button1_MouseLeave(System::Object * sender, System::EventArgs * e) { button1->BackColor=SystemColors::ActiveBorder; button1->Image=NULL; }