首页 > 其他分享 >WPF公章制作之2

WPF公章制作之2

时间:2023-02-28 11:03:46浏览次数:59  
标签:公章 System myPath using new WPF txtblk 制作 ellipse


早前,我曾写过一篇:“在WPF中制作正圆形公章”。

有空再次研究,使用C#将此WPF程序写了出来。


运行效果图:

WPF公章制作之2_string



关键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属性语法)

标签:公章,System,myPath,using,new,WPF,txtblk,制作,ellipse
From: https://blog.51cto.com/JohnsonJu/6090442

相关文章

  • GDI+带农历的万年历(周历)之制作
    今天在网上无意中搜索到“Vista风格日历控件”。下载之后发现,略有BUG,于是进行改进。无意中,制作出来带农历的万年历(周历版)。运行如下图:​​​​​​主要的改进在://frmDemo.c......
  • WPF中的Frozen(冻结)与线程及其他相关问题
    System.Windows.Freezable类(在WindowsBase.dll中)定义一个对象,该对象具有可修改状态和只读(冻结)状态。派生自Freezable的类提供详细的更改通知,可以是不可变的,并且可以进行......
  • 关于.Net中的计时器及WPF中最适合的计时器问题
    .Net中,至少可以找出5个计时器类型:(1)System.Threading.Timer(2)System.Timers.Timer(3)System.Windows.Forms.Timer(4)System.Web.UI.Timer(5)System.Windows.Threading.Dis......
  • WPF 精修篇 拖拽 DragDrop
    WPF实现拖拽效果<Grid><Grid.ColumnDefinitions><ColumnDefinitionWidth="197*"/><ColumnDefinitionWidth="209*"/><Colum......
  • WPF 精修篇 依赖属性
    依赖属性使用场景1.希望可在样式中设置属性。2.希望属性支持数据绑定。3.希望可使用动态资源引用设置属性。4.希望从元素树中的父元素自动继承属性值。5.希望属性可进......
  • WPF下字体模糊的问题
    一直以来,发现WPF中的小字体下的文字变得比较模糊,比如:WPF与Winform字体显示比较:为了看到更清楚,我们放大点显示: 放得更大些:中文、日文等亚洲文字的显示也存在着类似的问题:在......
  • WPF中的文字修饰——上划线,中划线,基线与下划线
    我们知道,文字的修饰包括:空心字、立体字、划线字、阴影字、加粗、倾斜等。这里只说划线字的修饰方式,按划线的位置,我们可将之分为:上划线、中划线、基线与下划线。如图:从上至下......
  • 给WPF文字加多条修饰线
    这是上篇​​WPF中的文字修饰——上划线,中划线,基线与下划线​​效果图:XAML代码:<Pagexmlns="​​http://schemas.microsoft.com/winfx/2006/xaml/presentation​​​"xmlns......
  • WPF应用程序顶级标签一定是Window吗?
    WPF应用程序顶级标签一定是Window吗? 很多人误以为是。可是,答案却是否定的。我们不妨来测试一下。首先使用顶级标签为Window,这是最普通、也是最常见的情况。新建一个WPF应......
  • 距离北京奥运还有359天,发布WPF版本的北京2008标志(下)
    图片显示效果: XAML代码:<ViewboxWidth="463.548828"Height="370.816895"xmlns="​​​http://schemas.microsoft.com/winfx/2006/xaml/presentation​​​"xmlns:x=......