根据比较现有一些白板软件,发现有几家的有个快速转轮菜单,觉得很好玩,也比较有创意,所以也想进行简单模仿,现只实现了圆轮的实现算法。
主面板使用Canvas 然后定位中间点作为圆心:
1 private void button1_Click(object sender, RoutedEventArgs e)
2 {
3 double centerX = Canvas.GetLeft(this.cbElli) + this.cbElli.Width / 2.0;
4 double centerY = Canvas.GetTop(this.cbElli) + this.cbElli.Height / 2.0;
5 double R = 80;
6 double angleAll = 360;
7 int angleNum = 12;
8 double stepAngle = angleAll / angleNum;
9 Point beginPoint = new Point(centerX + R, centerY - 50.0 / 2.0);
10
11 for (int i = 0; i < angleNum; i++)
12 {
13 Matrix mtr = new Matrix();
14 mtr.RotateAt(stepAngle * i, centerX, centerY);
15 Point postion = Point.Multiply(beginPoint, mtr);
16 CreatButton(postion.X, postion.Y, stepAngle * i);
17 }
18 }
19
20 //生成按钮的方法
21 private Button CreatButton(double left, double top, double angle)
22 {
23 Button btn = new Button();
24 btn.Height = btn.Width = 50;
25 btn.Content = "地图";
26 Canvas.SetLeft(btn, left);
27 Canvas.SetTop(btn, top);
28 this.mainCan.Children.Add(btn);
29 RotateTransform rot = new RotateTransform();
30 rot.Angle = angle;
31 btn.RenderTransform = rot;
32 btn.Click += new RoutedEventHandler(btn_Click);
33 return btn;
34 }
除了旋转基本按钮之外,还要计算按钮的位置,通过Point提供的向量变换即可