Results 1 to 5 of 5

Thread: avoid flicker for panel control upon cursor mousemove

  1. #1
    ridhwaans is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    33
    Reputation
    14

    avoid flicker for panel control upon cursor mousemove

    Code:
    Imports System.Drawing.Drawing2D
    
    Public Class Form1
        Private myPath As New GraphicsPath
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.DoubleBuffered = True
        End Sub
    
        Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If myPath.IsVisible(e.X, e.Y) = True Then
    
                Panel1.Visible = True
                Panel1.Location = New Point(e.X, e.Y - Panel1.Height)
            Else
                Panel1.Visible = False
            End If
    
        End Sub
    
        Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
            myPath.AddRectangle(New Rectangle(457, 428, 602 - 457, 472 - 428))
            Dim myPen As New Pen(Color.Black, 1)
            e.Graphics.DrawPath(myPen, myPath)
        End Sub
    End Class
    I've got a picturebox in a wpf, in which I've drawn a rectangle (and polygons) using graphics path. If the user mouses over the rectangle area, determined by the isVisible property, a panel pops up (like a tooltip) and displayed, and its location moved along the cursor position while the cursor is within the area. The panel has got a bunch of labels as attributes
    I've used panel visible property to achieve this, but as the panel moves with the cursor, there is a lot of flickering. Is there any way to avoid flickering? I've tried using doublebuffered and setstyles
    Please advise
    thanks

  2. #2
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    Not within the program as it stands. You're asking for a complete repaint every time the cursor moves so much as a pixel's width. This might be OK with a superfast graphics card but for the average display flicker is almost inevitable. It certainly doesn't help that you're checking the myPath visible property within the MouseMove sub in addition to all the other happenings.

  3. #3
    ridhwaans is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2012
    Posts
    33
    Reputation
    14
    Quote Originally Posted by Dunfiddlin View Post
    Not within the program as it stands. You're asking for a complete repaint every time the cursor moves so much as a pixel's width. This might be OK with a superfast graphics card but for the average display flicker is almost inevitable. It certainly doesn't help that you're checking the myPath visible property within the MouseMove sub in addition to all the other happenings.
    yeah I know,
    do you know of an alternative, to suggest if any?

  4. #4
    Dunfiddlin's Avatar
    Dunfiddlin is offline VB.NET Forum Master
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2012
    Posts
    253
    Reputation
    31
    Couldn't the panel be static? Does it really have to move with the cursor? Take a look at the status bar on MSPaint for example. People are more than used to looking away from the cursor to get information.

  5. #5
    VicJ is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2008
    Posts
    68
    Reputation
    127
    Quote Originally Posted by ridhwaans View Post
    yeah I know,
    do you know of an alternative, to suggest if any?
    The reason the panel is flickering is because you are adding a new rectangle to the graphics path every time the Paint event fires. That happens every time the panel moves over the picture box. Within a few seconds you may have added hundreds of rectangles to the path, even if they are all the same dimensions. That makes it really slow for myPath.IsVisible to do its work, so that there is a delay every time you try to show the panel. Answer: move myPath.AddRectangle to the form's Load or Shown event sub.


    Vic

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking