如何实现自定义按扭功能????

nyucv 2004-06-10 05:31:30
把按扭变为圆形,立体自定义形状!请问如何用C#实现!谢谢!
...全文
136 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
互通互联 2004-06-25
  • 打赏
  • 举报
回复
经典。
boytomato 2004-06-25
  • 打赏
  • 举报
回复
private void button1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath buttonPath =
new System.Drawing.Drawing2D.GraphicsPath();

// Set a new rectangle to the same size as the button's
// ClientRectangle property.
System.Drawing.Rectangle newRectangle = button1.ClientRectangle;

// Decrease the size of the rectangle.
newRectangle.Inflate(-10, -10);
// Draw the button's border.
e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

// Increase the size of the rectangle to include the border.
newRectangle.Inflate( 1, 1);

// Create a circle within the new rectangle.
buttonPath.AddEllipse(newRectangle);
// Set the button's Region property to the newly created
// circle region.
button1.Region = new System.Drawing.Region(buttonPath);
}
nyucv 2004-06-24
  • 打赏
  • 举报
回复
晕倒!谢谢楼上兄台!
我一点按扭。边框就出现了。好难看呀!
sharpdew 2004-06-10
  • 打赏
  • 举报
回复
Rectangle rect=this.button1.ClientRectangle;
System.Drawing.Drawing2D.GraphicsPath gPath=new System.Drawing.Drawing2D.GraphicsPath();
int r=15;
gPath.AddLine(rect.Left+r,rect.Top,rect.Right-r,rect.Top);
gPath.AddArc(rect.Right-2*r,rect.Top,2*r,2*r,270,90);
gPath.AddLine(rect.Right,rect.Top+r,rect.Right,rect.Bottom-r);
gPath.AddArc(rect.Right-2*r,rect.Bottom-2*r,2*r,2*r,0,90);
gPath.AddLine(rect.Right-r,rect.Bottom,rect.Left+r,rect.Bottom);
gPath.AddArc(rect.Left,rect.Bottom-2*r,2*r,2*r,90,90);
gPath.AddLine(rect.Left,rect.Bottom-r,rect.Left,rect.Top+r);
gPath.AddArc(rect.Left,rect.Top,2*r,2*r,180,90);
Region reg=new Region(gPath);
this.button1.Region=reg;
cimoka 2004-06-10
  • 打赏
  • 举报
回复
继承一个button类,重写绘图事件。这样最合适了
网上有写自定义控件的例子
renrenqq 2004-06-10
  • 打赏
  • 举报
回复
用ImageButton加图片
Essence_zhx 2004-06-10
  • 打赏
  • 举报
回复
设置button的region属性就可以了

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧