Displaying a Control at Runtime
-
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? -
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? -
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?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 withinthis.Controls
array. 2.) The InitControl is the topmost control within thethis.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...
-
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 withinthis.Controls
array. 2.) The InitControl is the topmost control within thethis.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...
-
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.
gareth111, By points 1 and 2 I meant the following: Suppose you add
InitControl
at Location (10,10) within thethis.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 afterinitControl.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...
-
gareth111, By points 1 and 2 I meant the following: Suppose you add
InitControl
at Location (10,10) within thethis.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 afterinitControl.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...