本文介绍了如何使用C#扩展两行以满足彼此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows窗体绘制了几行。



但是我希望通过扩展这些行来加入行。



有没有办法用Windows窗体扩展线



这里我的代码



  for  int  count =  0 ; count <   1 ; count ++)
{
int x1 = polyPt [ 0 ]。X;
int y1 = polyPt [ 0 ]。Y;
int x2 = polyPt [polyPt.Length-1] .X;
int y2 = polyPt [polyPt.Length-1] .Y;

var L = Math.Sqrt((x1 - x2)*(x1 - x2)+(y1 - y2)*(y1 - Y2));

var offsetPixels = -15。 0 ;


int x1p = Convert.ToInt32(x1 + offsetPixels *(y2-y1)/ L);
int x2p = Convert.ToInt32(x2 + offsetPixels *(y2-y1)/ L);
int y1p = Convert.ToInt32(y1 + offsetPixels *(x1 - x2)/ L);
int y2p = Convert.ToInt32(y2 + offsetPixels *(x1 - x2)/ L);


graphics.DrawLine( new Pen(Color.Red), new Point(x1p,y1p), new Point(x2p,y2p));
}
解决方案



I have drawn few lines using windows forms.

But I want to join lines by extending those line.

Is there any way to extend lines using windows forms

Here my code

for (int count = 0; count < 1; count++)
               {
                   int x1 = polyPt[0].X;
                   int y1 = polyPt[0].Y;
                   int x2 = polyPt[polyPt.Length-1].X;
                   int y2 = polyPt[polyPt.Length-1].Y;

                   var L = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

                   var offsetPixels = -15.0;


                   int x1p = Convert.ToInt32(x1 + offsetPixels * (y2 - y1) / L);
                   int x2p = Convert.ToInt32(x2 + offsetPixels * (y2 - y1) / L);
                   int y1p = Convert.ToInt32(y1 + offsetPixels * (x1 - x2) / L);
                   int y2p = Convert.ToInt32(y2 + offsetPixels * (x1 - x2) / L);


                   graphics.DrawLine(new Pen(Color.Red), new Point(x1p, y1p), new Point(x2p, y2p));
               }
解决方案



这篇关于如何使用C#扩展两行以满足彼此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:36