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. WinForms: programatically created control will not paint

WinForms: programatically created control will not paint

Scheduled Pinned Locked Moved C#
csharphelpvisual-studiowinforms
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
    SebbaP
    wrote on last edited by
    #1

    I have created a custom control, which I am trying to programatically add to my windows form. The problem is that the control's OnPaint method is never invoked, even though the control invalidates itself on regular intervals (it uses a timer). If the control is added to my form in Visual Studio's designer, all works perfectly. However, I can't add the control in the designer because I don't know how many instances of my control I will need until my application reaches a certain point. Any help is much appreciated! Thanks

    R 1 Reply Last reply
    0
    • S SebbaP

      I have created a custom control, which I am trying to programatically add to my windows form. The problem is that the control's OnPaint method is never invoked, even though the control invalidates itself on regular intervals (it uses a timer). If the control is added to my form in Visual Studio's designer, all works perfectly. However, I can't add the control in the designer because I don't know how many instances of my control I will need until my application reaches a certain point. Any help is much appreciated! Thanks

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      You are almost certainly overlooking some of the code the designer would create for you. Did you remember to add your new control to the form's controls collection? Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke

      S 1 Reply Last reply
      0
      • R Rob Graham

        You are almost certainly overlooking some of the code the designer would create for you. Did you remember to add your new control to the form's controls collection? Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke

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

        Thank you for your reply Rob!! Yes, I have added the control to the collection. I have tried to mimic what the designer does, but maybe I have missed some small detail anyway. Does the paint event have to be tied to something before it can be invoked after invalidation of the control? I guess the windows form's message pump is involved somehow...perhaps it is not setup properly. I don't know much about the inner workings of windows forms and their controls, so I'm quite confused.

        S R 2 Replies Last reply
        0
        • S SebbaP

          Thank you for your reply Rob!! Yes, I have added the control to the collection. I have tried to mimic what the designer does, but maybe I have missed some small detail anyway. Does the paint event have to be tied to something before it can be invoked after invalidation of the control? I guess the windows form's message pump is involved somehow...perhaps it is not setup properly. I don't know much about the inner workings of windows forms and their controls, so I'm quite confused.

          S Offline
          S Offline
          Sebrell
          wrote on last edited by
          #4

          A thought: does your code call the Invalidate() method of the parent control? This method has multiple overloads, three of which take a boolean parameter "invalidateChildren".

          S 1 Reply Last reply
          0
          • S SebbaP

            Thank you for your reply Rob!! Yes, I have added the control to the collection. I have tried to mimic what the designer does, but maybe I have missed some small detail anyway. Does the paint event have to be tied to something before it can be invoked after invalidation of the control? I guess the windows form's message pump is involved somehow...perhaps it is not setup properly. I don't know much about the inner workings of windows forms and their controls, so I'm quite confused.

            R Offline
            R Offline
            Rob Graham
            wrote on last edited by
            #5

            Perhaps a snippet or two of your code would help. The implementation of the OnPaint handler, and the code used to add the control dynamically, for instance... Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke

            1 Reply Last reply
            0
            • S Sebrell

              A thought: does your code call the Invalidate() method of the parent control? This method has multiple overloads, three of which take a boolean parameter "invalidateChildren".

              S Offline
              S Offline
              SebbaP
              wrote on last edited by
              #6

              I managed to get my control to show up finally, but it doesn't happen the way I want to. I had not actually added the control to the form's controls collection, but instead in the DataGridTextBoxColumn.TextBox.Controls. If I add the control to the form's collection, it shows up like it should. However, this is not the way I want to do it, since my form should only be aware of the columnstyles I use, and not of the controls they may use. I've written a new thread about this with a complete sample code that illustrates the problem. I hope you can help me! Thanks!!

              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