473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Not understanding simple concept

Lets 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.

Nov 27 '06 #1
6 1040

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.
Nov 27 '06 #2
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 '='.

Nov 27 '06 #3

"Bryan" <br*******@gmail.comwrote in message
news:11*********************@14g2000cws.googlegrou ps.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 '='.
Well you are basically wanting to use the Prototype pattern. If you want to
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
;).
Nov 27 '06 #4
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" <br*******@gmail.comwrote in message
news:11**********************@j44g2000cwa.googlegr oups.com...
Lets 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.
Nov 27 '06 #5
Bryan wrote:
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 '='.
Is there a particular reason you need to create a *new* textbox? Why
not just alter the parameters of the old one:

TextBox1.Text = "Changed"

Chris

Nov 27 '06 #6

Chris Dunaway wrote:
Is there a particular reason you need to create a *new* textbox? Why
not just alter the parameters of the old one:

TextBox1.Text = "Changed"

Chris
Because in reality I actually built a class that builds a Developer
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.

Nov 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I have been trying to understand this concept for quite sometime now somehow I am missing some vital point. I am new to Object Oriented Programming so maybe thats the reason. I want to...
24
by: Norm | last post by:
Could someone explain for me what is happening here? char *string; string = new char; string = "This is the string"; cout << string << std::endl; The output contains (This the string) even...
13
by: tfsquare | last post by:
All, I am new to XSLT and having some problems understanding the syntax of XPath which selects nodes in the XML document. Consider this bit of XML, which contains three outer XML elements. ...
17
by: RSH | last post by:
I am really trying to grasp the concept of OOP as it applies to C#. I am looking at trying to set up a simple Employee Class but I am having trouble conceptualizing what this class should look...
10
by: sasquatch | last post by:
X-No-Archive: Are there any good books that provide tips about how to understand and "play with" large C++ programs? It seems like a very important skill, and yet its hardly taught in the...
4
by: Andrew Taylor | last post by:
Hi, I've been using PHP for a long time, I have designed and developed a number of mid-range systems. I've always used a procedural approach. I fully understand the concept of OO, I know all the...
16
by: RSH | last post by:
Hi, I am a fairly seasoned developer and have recently started looking at software design patterns. I am starting with the Abstract Factory Pattern and was wondering if someone could help me...
0
by: steve | last post by:
There is little evidence that the sql community understands the concept of a table as a variable let alone its significant implications. Yet there is ample evidence that the sql community thinks...
2
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means...
9
by: Daniel Smedegaard Buus | last post by:
Hey all :) I was wondering about the $error_types (I particularly notice the 's' suffix when reading the manual) parameter for 'set_error_handler()': Can be used to mask the triggering of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.