Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 16044

VS 2015 Fluctuating Problem on Invalidating Panel

$
0
0
Hello Everyone,

I am trying to create rectangle on a panel to be used as crop tool. So that when ever I move mouse after pressing right button a new rectangle will draw on panel but to remove last rectangle I have to invalidate the panel . So when the mouse moves to draw a rectangle as selection area for cropping , panel gets invalidate on every mouse move event which cause a fluctuation effect on panel picture.

So please help me in getting out of this fluctuation problem I shall be very thankful.

I am attaching my code sample below:-

Code:


    Dim start_position As Point
    Dim end_position As Point
    Dim Measurement_Picture As Bitmap = New Bitmap(100, 100)
 
  Private Sub Plotting_Panel_MouseDown(sender As Object, e As MouseEventArgs) Handles Plotting_Panel.MouseDown
     
        If Measurement = True Then
            Draw_Measurement_Selection = True
        Else
            Draw_Measurement_Selection = False
        End If
        start_position = e.Location
     
    End Sub

    Private Sub Plotting_Panel_MouseMove(sender As Object, e As MouseEventArgs) Handles      Plotting_Panel.MouseMove
     
      If Draw_Measurement_Selection = True Then


            end_position = e.Location
            Plotting_Panel.Invalidate()
       

        End If



    End Sub


    Dim Measurement_Rect As Rectangle
 
    Private Function GetRectangle()

        Measurement_Rect.X = Math.Min(start_position.X, end_position.X)
        Measurement_Rect.Y = Math.Min(start_position.Y, end_position.Y)
        Measurement_Rect.Width = Math.Abs(start_position.X - end_position.X)
        Measurement_Rect.Height = Math.Abs(start_position.Y - end_position.Y)

        Return Measurement_Rect

    End Function

  Private Sub Plotting_Panel_Paint(sender As Object, e As PaintEventArgs) Handles  Plotting_Panel.Paint
   
  e.Graphics.DrawImage(Plotting_Signal, 0, 0)
   
        If Measurement = True Then
            If Draw_Measurement_Selection = True Then
                e.Graphics.DrawRectangle(Pens.Red, GetRectangle())
            End If
        End If
    End Sub


Viewing all articles
Browse latest Browse all 16044

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>