Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Screen Flickers When I Move Mouse

Screen Flickers When I Move Mouse

Scheduled Pinned Locked Moved C#
helpgraphicsdata-structuresquestion
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • . Offline
    . Offline
    ...---...
    wrote on last edited by
    #1

    Hi, I am writing some code (for fun) that will display the mouse coordinates in real time on a WinForm. The "e.X, e.Y" coordinate text is displayed next to the position of the cursor. Problem is, every time I move the mouse the graph that I've drawn to "run" the coordinates over keeps getting re-drawn (flicker?) until I stop moving the mouse-- and then the coordinates are displayed over the graph I've drawn. Is there any way to fix this? ps- many people have very helpful to my questions --> I am very grateful. //////////////////////////////////////////////////////////// Here are the relevant code fragments....1)Paint, 2)MouseMove, 3)override OnPaint /////////////////////////////////////////////////////////// void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; g.DrawRectangle(graphPen, xIndent, yIndent, 400,400); g.FillRectangle(graphBrush, xIndent, yIndent, 400, 400); g.DrawLine(graphPen, xIndent + 200, yIndent, xIndent + 200, yIndent + 400); g.DrawLine(graphPen, xIndent, yIndent + 200, xIndent + 400, yIndent + 200); DrawGraphLines(g); DrawXYAxes(g); if(m_bFlag1) DrawComplexLineA(g); if(m_bFlag2) DrawComplexLineB(g); if(m_bAddFlag) DrawComplexAdd(g); } /////////////////////////////////////////////////////////////////////////// private Point mousePoints; protected override void OnMouseMove(MouseEventArgs e) { // TODO: Add Form1.OnMouseMove implementation mousePoints = new Point(e.X,e.Y); Invalidate(); base.OnMouseMove (e); } //////////////////////////////////////////////////////////////////////////// protected override void OnPaint(PaintEventArgs e) { // TODO: Add Form1.OnPaint implementation base.OnPaint (e); Point screen = PointToScreen(mousePoints); string location = screen.ToString(); e.Graphics.DrawString("[Screen: " + location + "]", new Font("Arial",8), SystemBrushes.ControlText, (PointF)mousePoints); } /////////////////////////////////////////////////////////

    C 1 Reply Last reply
    0
    • . ...---...

      Hi, I am writing some code (for fun) that will display the mouse coordinates in real time on a WinForm. The "e.X, e.Y" coordinate text is displayed next to the position of the cursor. Problem is, every time I move the mouse the graph that I've drawn to "run" the coordinates over keeps getting re-drawn (flicker?) until I stop moving the mouse-- and then the coordinates are displayed over the graph I've drawn. Is there any way to fix this? ps- many people have very helpful to my questions --> I am very grateful. //////////////////////////////////////////////////////////// Here are the relevant code fragments....1)Paint, 2)MouseMove, 3)override OnPaint /////////////////////////////////////////////////////////// void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; g.DrawRectangle(graphPen, xIndent, yIndent, 400,400); g.FillRectangle(graphBrush, xIndent, yIndent, 400, 400); g.DrawLine(graphPen, xIndent + 200, yIndent, xIndent + 200, yIndent + 400); g.DrawLine(graphPen, xIndent, yIndent + 200, xIndent + 400, yIndent + 200); DrawGraphLines(g); DrawXYAxes(g); if(m_bFlag1) DrawComplexLineA(g); if(m_bFlag2) DrawComplexLineB(g); if(m_bAddFlag) DrawComplexAdd(g); } /////////////////////////////////////////////////////////////////////////// private Point mousePoints; protected override void OnMouseMove(MouseEventArgs e) { // TODO: Add Form1.OnMouseMove implementation mousePoints = new Point(e.X,e.Y); Invalidate(); base.OnMouseMove (e); } //////////////////////////////////////////////////////////////////////////// protected override void OnPaint(PaintEventArgs e) { // TODO: Add Form1.OnPaint implementation base.OnPaint (e); Point screen = PointToScreen(mousePoints); string location = screen.ToString(); e.Graphics.DrawString("[Screen: " + location + "]", new Font("Arial",8), SystemBrushes.ControlText, (PointF)mousePoints); } /////////////////////////////////////////////////////////

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Turn on double buffering: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true); Christian Graus - Microsoft MVP - C++

      . 1 Reply Last reply
      0
      • C Christian Graus

        Turn on double buffering: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true); Christian Graus - Microsoft MVP - C++

        . Offline
        . Offline
        ...---...
        wrote on last edited by
        #3

        Christian, Thanks-- In which/where (method?) do I "turn on double buffering"? what's "this."? - An instantiated "what"? I'm a bit behind the learning curve here but very appreciative of your response-- thanks again....

        M C 2 Replies Last reply
        0
        • . ...---...

          Christian, Thanks-- In which/where (method?) do I "turn on double buffering"? what's "this."? - An instantiated "what"? I'm a bit behind the learning curve here but very appreciative of your response-- thanks again....

          M Offline
          M Offline
          microsoc
          wrote on last edited by
          #4

          sorry for the interruption... just call the method(what christian gave you) on the constructor of your control. Hope that helps! :)

          1 Reply Last reply
          0
          • . ...---...

            Christian, Thanks-- In which/where (method?) do I "turn on double buffering"? what's "this."? - An instantiated "what"? I'm a bit behind the learning curve here but very appreciative of your response-- thanks again....

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            this means the class that the code is written in. You don't need it, actually. Christian Graus - Microsoft MVP - C++

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups