将C#中的代码替换为wpf [英] replace code in c# to wpf
本文介绍了将C#中的代码替换为wpf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#中有此代码,我想将其替换为wpf.我该怎么办?:
受保护的 覆盖 void OnPaint(PaintEventArgs pe)
{
GraphicsPath p = 新 GraphicsPath();
笔borderPen = 新 Pen(Color.Red, 3 );
p.AddPolygon(新 Point []
{
新点(-3,此.高度* 13/22),
新点(此.宽度* 2/13,-3),
新点(此.宽度* 9/11, 0 ),
新点(此 .Width,此高度* 2/5),
新点(此.宽度* 6/7,此.高度* 170/171),
新点(此.宽度* 2/11,此.高度* 170/171)
});
此.Region= 新 Region(p);
如果(粗体)
{
Point [] point = 新 Point []
{
新点( 1 ,此.高度* 13/22),
新建点(此.宽度* 2/13, 1 ),
新建点(此.宽度* 9/11, 1 ),
新建点(此.宽度* 11/17,此.高度* 13/22)
};
pe.Graphics.DrawPolygon(borderPen,point);
}
基本 .OnPaint(pe);
}
解决方案
一个大概的想法是:PointCollection points = new PointCollection( { 新点(-3,此.高度* 13/22), 新点(此.宽度* 2/13,-3), 新点(此.宽度* 9/11, 0 ), 新点(此 .Width,此高度* 2/5), 新点(此.宽度* 6/7,此.高度* 170/171), 新建点(此.宽度* 2/11,此.高度* 170/171) }); Polygon多边形= 新 Polygon(); polygon.Points =点; polygon.Stroke = Brushes.Red; 多边形.StrokeThickness = 3 ; 多边形.Width = 此 .Width; 然后,您需要做的就是将其添加到XAML中设置的任何Container中.假设它是一个名为LayoutRoot
的Grid
,您将使用LayoutRoot.Children.Add(polygon);我留给您添加
isBold
的内容是因为如此相似.
I have this code in c# and I want to replace it to wpf. how can I do it?:
protected override void OnPaint(PaintEventArgs pe)
{
GraphicsPath p = new GraphicsPath();
Pen borderPen = new Pen(Color.Red, 3);
p.AddPolygon(new Point[]
{
new Point(-3, this.Height *13/22),
new Point(this.Width *2/13, -3),
new Point(this.Width*9/11,0),
new Point(this.Width,this.Height*2/5),
new Point(this.Width*6/7,this.Height*170/171),
new Point(this.Width*2/11,this.Height*170/171)
});
this.Region = new Region(p);
if (bold)
{
Point[] point = new Point[]
{
new Point(1,this.Height *13/22),
new Point(this.Width *2/13, 1),
new Point(this.Width*9/11,1),
new Point(this.Width*11/17,this.Height *13/22)
};
pe.Graphics.DrawPolygon(borderPen, point);
}
base.OnPaint(pe);
}
解决方案
The rough idea is this:PointCollection points = new PointCollection( { new Point(-3, this.Height *13/22), new Point(this.Width *2/13, -3), new Point(this.Width*9/11,0), new Point(this.Width,this.Height*2/5), new Point(this.Width*6/7,this.Height*170/171), new Point(this.Width*2/11,this.Height*170/171) }); Polygon polygon = new Polygon(); polygon.Points = points; polygon.Stroke = Brushes.Red; polygon.StrokeThickness = 3; polygon.Width = this.Width; polygon.Height = this.Height;Then all you need to do is add it to whatever Container you have set in your XAML. Suppose it''s a
Grid
calledLayoutRoot
, you''d useLayoutRoot.Children.Add(polygon);I leave you to add the
isBold
stuff because that''s so similar.
这篇关于将C#中的代码替换为wpf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文