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
  1. Home
  2. General Programming
  3. C#
  4. Flicker free panel

Flicker free panel

Scheduled Pinned Locked Moved C#
graphicsquestion
6 Posts 3 Posters 0 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.
  • P Offline
    P Offline
    PrebKlok
    wrote on last edited by
    #1

    I am using these lines, to avoid flicker in my program: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); private void timer1_Tick(object sender, System.EventArgs e) { Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... } However, it dont work for panels, only for the main window, if i try like this: private void timer1_Tick(object sender, System.EventArgs e) { panel1.Invalidate(); } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... } It there a simple way to make panels flicker free?

    M H 2 Replies Last reply
    0
    • P PrebKlok

      I am using these lines, to avoid flicker in my program: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); private void timer1_Tick(object sender, System.EventArgs e) { Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... } However, it dont work for panels, only for the main window, if i try like this: private void timer1_Tick(object sender, System.EventArgs e) { panel1.Invalidate(); } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... } It there a simple way to make panels flicker free?

      M Offline
      M Offline
      Meysam Mahfouzi
      wrote on last edited by
      #2

      I wonder where you have written these lines of code:

      SetStyle(ControlStyles.UserPaint, true);
      SetStyle(ControlStyles.DoubleBuffer, true);
      SetStyle(ControlStyles.AllPaintingInWmPaint, true);

      If you created your custom panel, so it should work flicker free.


      My Weblog

      P 1 Reply Last reply
      0
      • M Meysam Mahfouzi

        I wonder where you have written these lines of code:

        SetStyle(ControlStyles.UserPaint, true);
        SetStyle(ControlStyles.DoubleBuffer, true);
        SetStyle(ControlStyles.AllPaintingInWmPaint, true);

        If you created your custom panel, so it should work flicker free.


        My Weblog

        P Offline
        P Offline
        PrebKlok
        wrote on last edited by
        #3

        custom panel? I just drag a panel from the toolbox. The lines a placed in the constructor.

        M 1 Reply Last reply
        0
        • P PrebKlok

          custom panel? I just drag a panel from the toolbox. The lines a placed in the constructor.

          M Offline
          M Offline
          Meysam Mahfouzi
          wrote on last edited by
          #4

          That's why it's not flicker free. You should make a custom panel, which derives from Panel control, and then you just need to add those lines of code in the constructor of your custom panel. After compiling and adding it to your form, it will work flicker free. This article may help you: Flicker free drawing using GDI+ and C#[^]


          My Weblog

          1 Reply Last reply
          0
          • P PrebKlok

            I am using these lines, to avoid flicker in my program: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); private void timer1_Tick(object sender, System.EventArgs e) { Invalidate(); } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... } However, it dont work for panels, only for the main window, if i try like this: private void timer1_Tick(object sender, System.EventArgs e) { panel1.Invalidate(); } private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; ... } It there a simple way to make panels flicker free?

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            To note, it's much faster to use SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);. This results in fewer calls since all three enumerations are OR'd together at compile time. That's what the FlagsAttribute allows on an enumeration like ControlStyles (all enumerations denoting plurality in the .NET FCL typically have the FlagsAttribute).

            Microsoft MVP, Visual C# My Articles

            M 1 Reply Last reply
            0
            • H Heath Stewart

              To note, it's much faster to use SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);. This results in fewer calls since all three enumerations are OR'd together at compile time. That's what the FlagsAttribute allows on an enumeration like ControlStyles (all enumerations denoting plurality in the .NET FCL typically have the FlagsAttribute).

              Microsoft MVP, Visual C# My Articles

              M Offline
              M Offline
              Meysam Mahfouzi
              wrote on last edited by
              #6

              Nice point to mention


              My Weblog

              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