1.Canvas面板
class="brush:csharp;collapse:true;;gutter:true;">using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Input; using System.Windows.Shapes; namespace LY.PaintTheButton { public class PaintTheButton:Window { [STAThread] public static void Main() { new Application().Run(new PaintTheButton()); } public PaintTheButton() { Title = "Paint The Button"; Button btn = new Button(); btn.HorizontalAlignment = HorizontalAlignment.Center; btn.VerticalAlignment = VerticalAlignment.Center; Content = btn; Canvas canv = new Canvas(); canv.Width = 144; canv.Height = 144; btn.Content = canv; Rectangle rect = new Rectangle(); rect.Width = canv.Width; rect.Height = canv.Height; //使矩形的角变圆 rect.RadiusX = 24; rect.RadiusY = 24; rect.Fill = Brushes.Blue; canv.Children.Add(rect); //根据坐标位置放置控件 Canvas.SetLeft(rect, 0); Canvas.SetTop(rect, 0); Polygon poly = new Polygon(); poly.Fill = Brushes.Yellow; //颜色填充规则 poly.FillRule = FillRule.Nonzero; //poly.Points=new PointCollection(); for (int i = 0; i < 5; i++) { double angle = i * 4 * Math.PI / 5; Point pt = new Point(48 * Math.Sin(angle), -48 * Math.Cos(angle)); poly.Points.Add(pt); } canv.Children.Add(poly); Canvas.SetLeft(poly, canv.Width / 2); Canvas.SetTop(poly, canv.Height / 2); } } }
Canvas面板是根据坐标放置控件。