将C#中的代码替换为wpf [英] replace code in c# to wpf

查看:104
本文介绍了将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中.假设它是一个名为LayoutRootGrid,您将使用

 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 called LayoutRoot, you''d use

LayoutRoot.Children.Add(polygon);

I leave you to add the isBold stuff because that''s so similar.


这篇关于将C#中的代码替换为wpf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆