win10下使用系统方法绘制虚线框问题 RRS feed

  • 问题

  • 我使用系统自带的方法  在控件上绘制虚线框

     private void MakeRegion_MouseMove(object sender, MouseEventArgs e)
                if (isDrag)
                    ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
                    Point endPoint = ((Control)sender).PointToScreen(new Point(e.X, e.Y));

                    int width = endPoint.X - startPoint.X;
                    int height = endPoint.Y - startPoint.Y;
                    theRectangle = new Rectangle(startPoint.X,startPoint.Y, width, height);
                    ControlPaint.DrawReversibleFrame(theRectangle,this.BackColor, FrameStyle.Dashed);



    2018年2月23日 5:54


  • Hi,


    你又没在进入mouse move函数之后,尝试隐藏之前绘制的矩形呢,然后再次计算尺寸,然后在绘制图形呢。 你可以参考下面的代码。

    void Form1_MouseMove(object sender, 
    System.Windows.Forms.MouseEventArgs e)
          // If the mouse is being dragged, 
    // undraw and redraw the rectangle as the mouse moves.
          if (isDrag)
              // Hide the previous rectangle by calling the 
    	// DrawReversibleFrame method with the same parameters.
    		this.BackColor, FrameStyle.Dashed);
              // Calculate the endpoint and dimensions for the new 
           // rectangle, again using the PointToScreen method.
              Point endPoint = ((Control) sender).PointToScreen(new Point(e.X, e.Y));
              int width = endPoint.X-startPoint.X;
              int height = endPoint.Y-startPoint.Y;
              theRectangle = new Rectangle(startPoint.X, 
    		startPoint.Y, width, height);
              // Draw the new rectangle by calling DrawReversibleFrame
    	// again.  
    		this.BackColor, FrameStyle.Dashed);

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    2018年2月23日 8:23
  • 我再mouseup尝试隐藏了  但是还是不会消失 但是在win7中是正常的
    2018年4月17日 10:10
  • 试下将ControlPaint改成MakeRegion.CreateGraphics()来调用绘图方法

    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2018年4月18日 0:42