WPF公章制作之2

WPF研究 专栏收录该内容
114 篇文章 3 订阅

早前,我曾写过一篇:“在WPF中制作正圆形公章”(http://blog.csdn.net/johnsuna/archive/2007/10/12/1821531.aspx)。
有空再次研究,使用C#将此WPF程序写了出来。

运行效果图:
WPF下正圆形公章制作示例

关键C#代码:
// OfficialSeal.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using brawdrawSharp = BrawDraw.Com.Utility.PublicClasses.Shape;

namespace BrawDraw.Com.WPF.PublicControls.Demo
{
    public class OfficialSeal : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new OfficialSeal());
        }

        public OfficialSeal()
        {
            string officialSealText = "BRAWDRAW图文印章示例";
            Title = officialSealText;

            Canvas canv = new Canvas();
            Content = canv;
            Ellipse ellipse = new Ellipse();
            ellipse.Width = 400;
            ellipse.Height = 400;
            ellipse.Stroke = new SolidColorBrush(Colors.Red);
            ellipse.StrokeThickness = 2;
            Canvas.SetLeft(ellipse, 10);
            canv.Children.Add(ellipse);

            double angleAdd = 236.00 / officialSealText.Length;
            int i = 0;
            for (double angle = -112; angle < 123; angle += angleAdd)
            {
                TextBlock txtblk = new TextBlock();
                txtblk.FontFamily = new FontFamily("方正大标宋简体,黑体,宋体");
                txtblk.FontSize = 56;
                txtblk.Foreground = new SolidColorBrush(Colors.Red);
                txtblk.Text = officialSealText[i].ToString();
                txtblk.RenderTransformOrigin = new Point(0.5, 0);
                TransformGroup tg = new TransformGroup();
                ScaleTransform st = new ScaleTransform(0.66, 1);
                TranslateTransform tt = new TranslateTransform(0, -188);
                tg.Children.Add(st);
                tg.Children.Add(tt);
                tg.Children.Add(new RotateTransform(angle));
                txtblk.RenderTransform = tg;
                canv.Children.Add(txtblk);
                Canvas.SetLeft(txtblk, 180);
                Canvas.SetTop(txtblk, 200);
                i++;
            }

            Path myPath = new Path();
            myPath.Stroke = Brushes.Red;
            myPath.StrokeThickness = 1;

// 正五角星
            StreamGeometry theGeometry = BuildPentagonalStars(new Point(180, 168), 80, 80);
            theGeometry.FillRule = FillRule.EvenOdd;
            theGeometry.Freeze();
            myPath.Data = theGeometry;
            myPath.Fill = Brushes.Red;
            canv.Children.Add(myPath);
        }

        StreamGeometry BuildPentagonalStars(Point location, int width, int height)
        {
            Point[] pointsPentagonalStars = brawdrawSharp.RegularPolygon.GetStarPoints(location, width, height);
            StreamGeometry geometry = new StreamGeometry();

            using (StreamGeometryContext ctx = geometry.Open())
            {
                ctx.BeginFigure(new Point(pointsPentagonalStars[0].X, pointsPentagonalStars[0].Y), true, true);
                for (int i = 0; i < pointsPentagonalStars.Length; i++)
                {
                    ctx.LineTo(pointsPentagonalStars[i], true, false);
                }
            }

            return geometry;
        }

    }
}

关于StreamGeometry相关文章参考:
如何:使用 StreamGeometry 创建形状 http://msdn2.microsoft.com/zh-cn/library/ms742199.aspx
WPF中图形表示语法详解(Path之Data属性语法)http://blog.csdn.net/johnsuna/archive/2007/11/14/1885597.aspx

  • 0
    点赞
  • 5
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 成长之路 设计师:Amelia_0503 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值