0
我试着做在C#窗口形式的一些custombuttons,我已经有一个pieshaped按钮,这是源代码Pieshaped按钮形成C#
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Drawing;
namespace WindowsFormsApplication1
{
public class RoundButton : Button
{
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
GraphicsPath grPath = new GraphicsPath();
grPath.AddPie(new Rectangle(10, 10, 500, 500), 180, 18);
this.Region = new System.Drawing.Region(grPath);
base.OnPaint(e);
}
}
}
的问题是位置和大小修复,但我希望他们能够变化,如果有人能帮助我,那将会很棒。
当然,它只是将尺寸转换为RoundButton类中属性的一种情况,以便您可以将它们设置为其他内容? –
是的,但我不知道如何去做它我想它像 PSEUDOCODE grPath.AddPie(新的矩形(PositionX,PositionY,SizeX,SizeY),StartingAngle,大小),它应该可以通过Mousedrag – user2518891
OnPaint()应该**从不**包含导致生成另一个油漆的代码。你应该在构造函数中设置Region属性。或者在OnResize()中。当然,您可以通过使用新的矩形(Point.Empty,this.Size)来确定饼图的大小。 –