473,765 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1061

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*******@gmai l.comwrote in message
news:11******** *************@1 4g2000cws.googl egroups.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*******@gmai l.comwrote in message
news:11******** **************@ j44g2000cwa.goo glegroups.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
8185
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 understand what is typecasting in C++. Say I have a Base class and a Derived class, I have a pointer to an object to each. Base *ba = new Base; Derived *de = new Derived;
24
3163
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 though I only allocated 5 characters in memory with new.
13
2511
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. <FOO>foo.top.level</FOO> <BOO><FOO>foo.second.level</FOO></BOO> <CHOO><BOO><FOO>foo.third.level</FOO></BOO></CHOO>
17
19307
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 like. I was hoping someone might be able to simply outline what I envision my class to look like: Basically I am envisioning a Class called Employee: I imagine it would have many properties(?) such as:
10
2697
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 universities. Basic programming skills and knowledge of language constructs don't seem enough for understanding larger programs.
4
1633
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 basics and I know how to code OO. What I'm having problems with is understanding how to design/architect projects using OO. Can anyone reccomend any good online tutorials / online learning / video tutorials which deal with these subjects...
16
2646
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 understand where I might use this Pattern. I get the general concept but I am having a hard time converting that concept into where I might use that in a real world scenerio for a business application or web development project. I appreciate the...
0
1120
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 that it is practicing relational principals within an sq database. This would seem an awkward state of affairs given that the concept of table types and variables lies at the heart of a relational database. Every table created is at inception a...
2
7640
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 mentioning the class members(functions, typedefs, data) under the access control labels : public, protected, private. Encapsulation means providing the implementation of class member
9
2272
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 error_handler function just like the error_reporting ini setting controls which errors are shown. Without this mask set the error_handler will be called for every error regardless to the setting of the error_reporting setting.
0
10156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.