悬停包括另一条线的所有最近点时如何更改线的颜色

时间:2018-11-05 06:47:58

标签: c# wpf winforms gdi+

我只想问一下如何动态改变悬停线的颜色和该线的最近点。

private void Solid_Green_MouseMove_NotDown(object sender, MouseEventArgs e)
    {
        Pen red = new Pen(Color.Red, 1);
        red.DashPattern = new float[] { 5.0F, 5.0F, 5.0F, 5.0F };
        Pen Red = new Pen(Color.Red, 1);
        Graphics g = this.CreateGraphics();
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        Point hit_point;
        int segment_number;
        if (MouseIsOverEndpoint(e.Location, out segment_number, out hit_point))
        {
            g.DrawLine(Red, Pt1[segment_number], Pt2[segment_number]);
        }
        else if (MouseIsOverSegment(e.Location, out segment_number))
        {

            g.DrawLine(Red, Pt1[segment_number], Pt2[segment_number]);
            int other_side;
            int other_other_side;
            int other_other_other_side;
            int other_other_other_other_side;
            if (MouseIsOverSegment(Pt1[segment_number], out other_side) || MouseIsOverSegment(Pt2[segment_number], out other_side))
            {
                g.DrawLine(Red, Pt1[other_side], Pt2[other_side]);
                if (MouseIsOverSegment(Pt1[other_side], out other_other_side) || MouseIsOverSegment(Pt2[other_side], out other_other_side))
                {
                    g.DrawLine(Red, Pt1[other_other_side], Pt2[other_other_side]);
                    if (MouseIsOverSegment(Pt1[other_other_side], out other_other_other_side))
                    {
                        g.DrawLine(Red, Pt1[other_other_other_side], Pt2[other_other_other_side]);
                        if (MouseIsOverSegment(Pt1[other_other_other_side], out other_other_other_other_side))
                        {
                            g.DrawLine(Red, Pt1[other_other_other_other_side], Pt2[other_other_other_other_side]);
                        }
                    }
                }
            }

        }}

到目前为止,这是我的代码。我想改进它,例如尽量减少if else条件的使用并变得动态。

0 个答案:

没有答案