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. Displaying a Control at Runtime

Displaying a Control at Runtime

Scheduled Pinned Locked Moved C#
questiondebugginghelpannouncement
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.
  • G Offline
    G Offline
    Gareth H
    wrote on last edited by
    #1

    I've created a control that has a simple label on it and a progress bar. When a certain event happens i create a new instance of the control and add it to my parent control. Once the event is finnished i dispose of the control. My problem is that the control is never displayed. I know its being created since i've added trace's and can see that its checking to see if it needs to update the progress bar. When i call the progress bar, i check to see if it needs to be invoked and then do the below code: initControl = new InitControl(); this.Controls.Add(initControl); int posX = ((this.Width / 2) - (initControl.Width / 2)); int posY = ((this.Height / 2) - (initControl.Height / 2)); initControl.SetBounds(posX, posY, 100, 100); The question is, What am i missing so the control isnt showed?

    L V 2 Replies Last reply
    0
    • G Gareth H

      I've created a control that has a simple label on it and a progress bar. When a certain event happens i create a new instance of the control and add it to my parent control. Once the event is finnished i dispose of the control. My problem is that the control is never displayed. I know its being created since i've added trace's and can see that its checking to see if it needs to update the progress bar. When i call the progress bar, i check to see if it needs to be invoked and then do the below code: initControl = new InitControl(); this.Controls.Add(initControl); int posX = ((this.Width / 2) - (initControl.Width / 2)); int posY = ((this.Height / 2) - (initControl.Height / 2)); initControl.SetBounds(posX, posY, 100, 100); The question is, What am i missing so the control isnt showed?

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      gareth111 wrote:

      Once the event is finnished i dispose of the control.

      A control that has been disposed is not going to display.

      led mike

      1 Reply Last reply
      0
      • G Gareth H

        I've created a control that has a simple label on it and a progress bar. When a certain event happens i create a new instance of the control and add it to my parent control. Once the event is finnished i dispose of the control. My problem is that the control is never displayed. I know its being created since i've added trace's and can see that its checking to see if it needs to update the progress bar. When i call the progress bar, i check to see if it needs to be invoked and then do the below code: initControl = new InitControl(); this.Controls.Add(initControl); int posX = ((this.Width / 2) - (initControl.Width / 2)); int posY = ((this.Height / 2) - (initControl.Height / 2)); initControl.SetBounds(posX, posY, 100, 100); The question is, What am i missing so the control isnt showed?

        V Offline
        V Offline
        vinSharp
        wrote on last edited by
        #3

        There are mainly 2 to 3 points you need to take care of: 1.) You are adding to this.Controls, so hopefully there should be no other control present at the same Location within this.Controls array. 2.) The InitControl is the topmost control within the this.Controls list. 3.) The InitControl's 'Visible' property is set to TRUE. Regards, Vin...

        There are two types of fools in this world: One who give advice and the others who do not take it...

        G 1 Reply Last reply
        0
        • V vinSharp

          There are mainly 2 to 3 points you need to take care of: 1.) You are adding to this.Controls, so hopefully there should be no other control present at the same Location within this.Controls array. 2.) The InitControl is the topmost control within the this.Controls list. 3.) The InitControl's 'Visible' property is set to TRUE. Regards, Vin...

          There are two types of fools in this world: One who give advice and the others who do not take it...

          G Offline
          G Offline
          Gareth H
          wrote on last edited by
          #4

          led mike: I dont dispose of it until im finnished with it, i dont just create it and then dispose of it instantly. vinSharp: Its visiability is set to true, but im unsure what you mean by 1 and 2.

          V 1 Reply Last reply
          0
          • G Gareth H

            led mike: I dont dispose of it until im finnished with it, i dont just create it and then dispose of it instantly. vinSharp: Its visiability is set to true, but im unsure what you mean by 1 and 2.

            V Offline
            V Offline
            vinSharp
            wrote on last edited by
            #5

            gareth111, By points 1 and 2 I meant the following: Suppose you add InitControl at Location (10,10) within the this.Controls and elsewhere you add another opaque control whose span overlaps the InitControl, then also it would make your control invisible. To do a double check on that, add the following line after initControl.SetBounds(...) Add the line: initControl.BringToFront() Check whether this works for you...

            There are two types of fools in this world: One who give advice and the others who do not take it...

            G 1 Reply Last reply
            0
            • V vinSharp

              gareth111, By points 1 and 2 I meant the following: Suppose you add InitControl at Location (10,10) within the this.Controls and elsewhere you add another opaque control whose span overlaps the InitControl, then also it would make your control invisible. To do a double check on that, add the following line after initControl.SetBounds(...) Add the line: initControl.BringToFront() Check whether this works for you...

              There are two types of fools in this world: One who give advice and the others who do not take it...

              G Offline
              G Offline
              Gareth H
              wrote on last edited by
              #6

              Ye, that worked, cheers.

              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