|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Not understanding simple conceptLets say I have a form From1, and I add a text box to it, TextBox1, in
the VS2005 form designer. I set the 'Text' property of TextBox1 to "Original" using the properties dialog box in the form designer. Consider the following code that runs on the loading of the form dim txt as new TextBox txt.Text = "changed" Me.TextBox1 = txt I was thinking that when I open the form the text in the textbox would read "changed", but it still reads "original". Why does this not work? I wan't to be able to create an object at runtime, then set a control that I created at designtime equal to the runtime version. What you have done is created a new instance of textbox but not added it to
the controls collection of the parent form. So there are now two instances, the original and your new instance. To get your "changed" instance onto the form, you should set it's position and then add it to the controls collection of the parent form. You also need to "AddHandler" for any events you want to handle on the text box. Thanks for the response. Wouldn't that leave me with two textboxes on
my form though? I only want one. I basically want to replace all the old one's properties with the new one's properties i guess. I thought this would be done with the equals operator '='. "Bryan" <bryanv***@gmail.com> wrote in message Well you are basically wanting to use the Prototype pattern. If you want to news:1164617420.723248.92620@14g2000cws.googlegroups.com... > Thanks for the response. Wouldn't that leave me with two textboxes on > my form though? I only want one. I basically want to replace all the > old one's properties with the new one's properties i guess. I thought > this would be done with the equals operator '='. implement it like this, then you can always make the prototype invisible (visible = false). You might also consider deriving a new class from TextBox and implementing the IClonable interface, to make cloning (creating a new instance from the prototype) easier. However not knowing what application you have in mind it's quite difficult to suggest a better way ;). Bryan wrote:
> Thanks for the response. Wouldn't that leave me with two textboxes on Is there a particular reason you need to create a *new* textbox? Why> my form though? I only want one. I basically want to replace all the > old one's properties with the new one's properties i guess. I thought > this would be done with the equals operator '='. not just alter the parameters of the old one: TextBox1.Text = "Changed" Chris Chris Dunaway wrote:
> Is there a particular reason you need to create a *new* textbox? Why Because in reality I actually built a class that builds a Developer> not just alter the parameters of the old one: > > TextBox1.Text = "Changed" > > Chris Express XtraGrid (fancy datagrid) based on its properties that are set at runtime (TextBox was just an example). This class holds the finished XtraGrid control in a member. Sometimes I want to create a form and add this control to the form at runtime, like some of the above suggestions. But other times, I already have an XtraGrid on a form that was placed in design mode and has some code behind its events already. In this case I simply want the design time XtraGrid to inherit all the properties of the runtime control, but keep the same events. Did you add the control to the control collection?
Myform.controls.add(MyTextBox) This is done in the designer class of your form in vb2005. But it is hidden. You will also have to set the Location, Size, and Color. -- Thiele Enterprises - The Power Is In Your Hands Now! -- "Bryan" <bryanv***@gmail.com> wrote in message Lets say I have a form From1, and I add a text box to it, TextBox1, innews:1164607842.849045.241380@j44g2000cwa.googlegroups.com... the VS2005 form designer. I set the 'Text' property of TextBox1 to "Original" using the properties dialog box in the form designer. Consider the following code that runs on the loading of the form dim txt as new TextBox txt.Text = "changed" Me.TextBox1 = txt I was thinking that when I open the form the text in the textbox would read "changed", but it still reads "original". Why does this not work? I wan't to be able to create an object at runtime, then set a control that I created at designtime equal to the runtime version. |
|||||||||||||||||||||||