如何使用c#代码在wpf中排列圆形按钮?

时间:2014-01-13 06:01:31

标签: c# wpf

我是WPF的新手,想要以圆形形状动态排列几个按钮。可以使用任何面板(目前使用Canvas)。

1 个答案:

答案 0 :(得分:3)

它的c#代码可能会帮助你

Point cntr = new Point(this.Width/2, this.Height/2); // cntr Points Center of Circle
// Count gives Number of Buttons        
int count = 25; 
// angle gives angle Between each Button
double angle = 360/(double)count; 
int radius = 150; // Circle's Radius
for (int i = 0; i < count; i++)
{
    Button button = new Button();
    button.Text = "Button " + i;
    button.Location = new Point((int)(cntr.X + radius * Math.Cos((angle * i) * Math.PI / 180)),
        (int)(cntr.Y + radius * Math.Sin((angle * i) * Math.PI / 180)));
    this.Panle1.Controls.Add(button);
}
相关问题