WPF公章制作之2
早前,我曾写过一篇:“在WPF中制作正圆形公章”(http://blog.csdn.net/johnsuna/archive/2007/10/12/1821531.aspx)。
有空再次研究,使用C#将此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
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
使用VisualTreeHelper.GetDrawing(Visual v)枚举所有Visual内容的对象
原文: 使用VisualTreeHelper.GetDrawing(Visual v)枚举所有Visual内容的对象 C#代码:public void RetrieveDrawing(Visual v){ DrawingGroup dGroup = VisualTreeHelper.GetDrawing(v); EnumDrawingGroup(dGroup);} public void EnumDrawingGroup(DrawingGroup drawingGroup){ DrawingCollection dc = drawingGroup.Children; foreach (Drawing drawing in dc) { // 如果是DrawingGroup,递归枚举 if (drawing.GetType() == typeof(DrawingGroup)) { EnumDrawingGroup((DrawingGroup)drawing); } else if (drawing.GetType() == typeof(GeometryDrawing)) { // 处理...
- 下一篇
Overview of Kotlin & Comparison Between Kotlin and Java
Overview of Kotlin & Comparison Between Kotlin and Java by Navdeep Singh Gill What is Kotlin? Kotlin is a new programming language from JetBrains. It first appeared in 2011 when JetBrains unveiled their project named “Kotlin”. Kotlin is an Open-Source Language. Basically like Java, C and C++ - Kotlin is also “statically typed programming language”. Statically typed programming languages are those languages in which variables need not be defined before they are used. This means that static ty...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS关闭SELinux安全模块
- CentOS7设置SWAP分区,小内存服务器的救世主
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Mario游戏-低调大师作品