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 Drawing in C#

Flicker Free Drawing in C#

Scheduled Pinned Locked Moved C#
csharpgraphicstutorial
11 Posts 4 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.
  • A Offline
    A Offline
    AB7771
    wrote on last edited by
    #1

    Hi all can anyone tell me how to draw a line without flickering the screen Thanks Pramod

    M 1 Reply Last reply
    0
    • A AB7771

      Hi all can anyone tell me how to draw a line without flickering the screen Thanks Pramod

      M Offline
      M Offline
      Marc 0
      wrote on last edited by
      #2

      In your constructor (of the control that is drawn upon):

      base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint);

      Did this from the top of my head, so maybe the enums are not spelled correctly, but it should point you in the right direction. Also make sure you do the painting in OnPaint, not GreateGraphics. HTH! :)


      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


      || Fold With Us! || Pensieve || VG.Net ||

      A 1 Reply Last reply
      0
      • M Marc 0

        In your constructor (of the control that is drawn upon):

        base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint);

        Did this from the top of my head, so maybe the enums are not spelled correctly, but it should point you in the right direction. Also make sure you do the painting in OnPaint, not GreateGraphics. HTH! :)


        "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


        || Fold With Us! || Pensieve || VG.Net ||

        A Offline
        A Offline
        AB7771
        wrote on last edited by
        #3

        Hi Marc, Thanks for the suggestion but i am using a RichtextBox and it does not has a setStyle method any other suggestions will be appreciated Waiting for your quick reply. Thanks Pramod

        J 1 Reply Last reply
        0
        • A AB7771

          Hi Marc, Thanks for the suggestion but i am using a RichtextBox and it does not has a setStyle method any other suggestions will be appreciated Waiting for your quick reply. Thanks Pramod

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          RichTextBox does have a SetStyle method (it is inherited from Control), but it is protected so only accessible from a derived class. As was suggested above, to get the functionality you require you must inherit from RichTextBox, set the relevant style flags in your constructor and do your painting in the overriden OnPaint method. Im pretty sure you are using Graphics g = Graphics.CreateGraphics(yourRTBInstance) to draw, which in this case is the wrong way. -- modified at 8:29 Wednesday 11th January, 2006

          M A 2 Replies Last reply
          0
          • J J4amieC

            RichTextBox does have a SetStyle method (it is inherited from Control), but it is protected so only accessible from a derived class. As was suggested above, to get the functionality you require you must inherit from RichTextBox, set the relevant style flags in your constructor and do your painting in the overriden OnPaint method. Im pretty sure you are using Graphics g = Graphics.CreateGraphics(yourRTBInstance) to draw, which in this case is the wrong way. -- modified at 8:29 Wednesday 11th January, 2006

            M Offline
            M Offline
            Marc 0
            wrote on last edited by
            #5

            Oh yeah it's protected, i had forgotten that :doh:


            "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


            || Fold With Us! || Pensieve || VG.Net ||

            A 1 Reply Last reply
            0
            • M Marc 0

              Oh yeah it's protected, i had forgotten that :doh:


              "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


              || Fold With Us! || Pensieve || VG.Net ||

              A Offline
              A Offline
              AB7771
              wrote on last edited by
              #6

              Hi, can anyone of you send me the code please Thanks PRamod

              1 Reply Last reply
              0
              • J J4amieC

                RichTextBox does have a SetStyle method (it is inherited from Control), but it is protected so only accessible from a derived class. As was suggested above, to get the functionality you require you must inherit from RichTextBox, set the relevant style flags in your constructor and do your painting in the overriden OnPaint method. Im pretty sure you are using Graphics g = Graphics.CreateGraphics(yourRTBInstance) to draw, which in this case is the wrong way. -- modified at 8:29 Wednesday 11th January, 2006

                A Offline
                A Offline
                AB7771
                wrote on last edited by
                #7

                Hi, CAn u send me the code Thanks Pramod

                A 1 Reply Last reply
                0
                • A AB7771

                  Hi, CAn u send me the code Thanks Pramod

                  A Offline
                  A Offline
                  AB7771
                  wrote on last edited by
                  #8

                  Hi Marc, i got it and now the drawing is done fine but still some flickering is there. This has also caused one more problem\, Due to this code now if i type something in the Richtextbox it does not shows the text instead white spaces are shown any suggestions to avoid this Thanks

                  M 1 Reply Last reply
                  0
                  • A AB7771

                    Hi Marc, i got it and now the drawing is done fine but still some flickering is there. This has also caused one more problem\, Due to this code now if i type something in the Richtextbox it does not shows the text instead white spaces are shown any suggestions to avoid this Thanks

                    M Offline
                    M Offline
                    Marc 0
                    wrote on last edited by
                    #9

                    I have no experience with RichTextBoxes, only owner-drawn controls, so i dont think i can help you that much. You can try fiddling with the SetStyle flags.

                    base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

                    base.Setstyle(ControlStyles.DoubleBuffer, true);
                    or
                    base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
                    or
                    base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);

                    Sorry i can't help you any further...


                    "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


                    || Fold With Us! || Pensieve || VG.Net ||

                    A 1 Reply Last reply
                    0
                    • M Marc 0

                      I have no experience with RichTextBoxes, only owner-drawn controls, so i dont think i can help you that much. You can try fiddling with the SetStyle flags.

                      base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

                      base.Setstyle(ControlStyles.DoubleBuffer, true);
                      or
                      base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
                      or
                      base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);

                      Sorry i can't help you any further...


                      "..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick


                      || Fold With Us! || Pensieve || VG.Net ||

                      A Offline
                      A Offline
                      AB7771
                      wrote on last edited by
                      #10

                      i tried all the options but none of them are working for me Anyways Thanks for the suggestions :) Pramod

                      S 1 Reply Last reply
                      0
                      • A AB7771

                        i tried all the options but none of them are working for me Anyways Thanks for the suggestions :) Pramod

                        S Offline
                        S Offline
                        SwitcherSoft
                        wrote on last edited by
                        #11

                        Did you try this?

                        public class MyRichText : RichTextBox
                        {
                        public MyRichText()
                        {
                        //by setting Double Buffer, the painting will finish before its redenered
                        SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                        SetStyle(ControlStyles.ResizeRedraw, true);
                        SetStyle(ControlStyles.Selectable, true);

                            }
                        }
                        

                        Jordan

                        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