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. CustomControl.Paint Not Firing

CustomControl.Paint Not Firing

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.
  • S Offline
    S Offline
    Sukhjinder_K
    wrote on last edited by
    #1

    Hi I've created a Custom Control "YoLabel" with SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); and drawing it inside OnPaint(...) method. The Control draws itself fine. Now I need to paint something more from outside the label such as YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs) { // My Painting logic }; Now the above Event Handler is not firing. Inside YoLabel Control I'm using invalidate whenever Text, Color, etc properties are changed to repaint it. So what is missing. Please Advice. Thanks...

    L L 2 Replies Last reply
    0
    • S Sukhjinder_K

      Hi I've created a Custom Control "YoLabel" with SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); and drawing it inside OnPaint(...) method. The Control draws itself fine. Now I need to paint something more from outside the label such as YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs) { // My Painting logic }; Now the above Event Handler is not firing. Inside YoLabel Control I'm using invalidate whenever Text, Color, etc properties are changed to repaint it. So what is missing. Please Advice. Thanks...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      do you call base.OnPaint in your override of OnPaint? the Paint - Event is fired from there.

      S 1 Reply Last reply
      0
      • L Lost User

        do you call base.OnPaint in your override of OnPaint? the Paint - Event is fired from there.

        S Offline
        S Offline
        Sukhjinder_K
        wrote on last edited by
        #3

        Thanks m@u it worked fine...

        1 Reply Last reply
        0
        • S Sukhjinder_K

          Hi I've created a Custom Control "YoLabel" with SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); and drawing it inside OnPaint(...) method. The Control draws itself fine. Now I need to paint something more from outside the label such as YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs) { // My Painting logic }; Now the above Event Handler is not firing. Inside YoLabel Control I'm using invalidate whenever Text, Color, etc properties are changed to repaint it. So what is missing. Please Advice. Thanks...

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi,

          Sukhjinder_K wrote:

          YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs

          it seems like you have two YoLabels now, one got added to Form.Controls and paints fine thru OnPaint, the second one is not part of any Control collection, hence will never become visible or get its Paint event fired. You should not create a second YoLabel, you should add your painting delegate to the Paint event of the existing YoLabel. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


          S 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi,

            Sukhjinder_K wrote:

            YoLabel lbl = new YoLabel(); lbl.Paint += delegate(object s, PaintEventArgs

            it seems like you have two YoLabels now, one got added to Form.Controls and paints fine thru OnPaint, the second one is not part of any Control collection, hence will never become visible or get its Paint event fired. You should not create a second YoLabel, you should add your painting delegate to the Paint event of the existing YoLabel. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


            S Offline
            S Offline
            Sukhjinder_K
            wrote on last edited by
            #5

            Thanks for the interest codeproject. I'm creating a YoLabel as MyForm : Form { MyForm() { YoLabel lbl = new YoLabel(); lbl.Paint += delegate(...); //I can have another event delegate as lbl.MouseUp += delegate(...) this.Controls.Add(lbl); this.lbl.BringToFront();//I need to do this to show it on top of another control } } So I have only one YoLabel...

            L 1 Reply Last reply
            0
            • S Sukhjinder_K

              Thanks for the interest codeproject. I'm creating a YoLabel as MyForm : Form { MyForm() { YoLabel lbl = new YoLabel(); lbl.Paint += delegate(...); //I can have another event delegate as lbl.MouseUp += delegate(...) this.Controls.Add(lbl); this.lbl.BringToFront();//I need to do this to show it on top of another control } } So I have only one YoLabel...

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              then all is fine, as long as you call base.OnPaint() as the other reply mentioned. some people by mistake create a new instance to invoke a method or add a delegate, which obviously does not produce the result they are after. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


              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