《WPF程序设计指南》读书笔记——第7章 Canvas_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 《WPF程序设计指南》读书笔记——第7章 Canvas

《WPF程序设计指南》读书笔记——第7章 Canvas

 2013/8/26 21:07:46  小p  博客园  我要评论(0)
  • 摘要:1.Canvas面板usingSystem;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Media;usingSystem.Windows.Input;usingSystem.Windows.Shapes;namespaceLY.PaintTheButton{publicclassPaintTheButton:Window{[STAThread]publicstaticvoidMain()
  • 标签:程序 笔记 读书笔记 can 设计

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面板是根据坐标放置控件。

上一篇: C++ Primer中文版(第5版) 下一篇: 没有下一篇了!
发表评论
用户名: 匿名