您现在的位置是:首页 > 文章详情

WPF公章制作之2

日期:2018-10-24点击:430
原文: WPF公章制作之2

早前,我曾写过一篇:“在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

原文链接:https://yq.aliyun.com/articles/676815
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章