Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code in c# and I want to replace it to wpf. how can I do it?:
C#
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);
     }
Posted
Comments
ridoy 24-Aug-12 5:11am    
so strange question!

1 solution

The rough idea is this:
C#
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
C#
LayoutRoot.Children.Add(polygon);
I leave you to add the isBold stuff because that's so similar.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900