Newbie: Setting a string value to a textbox

G

Guest

Hi

I'm new at this C# thing but wanted to learn how to program. I've created a
Form with 3 textboxes. How can I set a value to the textboxes? I was
thinking that it would be something like... (as a test)

TextBox1.Text = "Test";

What I really want to do in the end is create maybe a struct that contains
the values for the 3 textboxes and read a file or maybe the registry with the
"default" values when the program loads.

Questions. Where do I create the struct and any registry operations? Would
it be in Program.cs or Forms1.cs? To me it makes sense that the struct would
be created in the same area where the program is started (Main)

Any ideas on how to get started would be appreciated.
 
D

Dan Bass

// assigns the text "Fred" to the textbox
nameTextBox.Text = "Fred";

Three textboxes, three default values doesn't equate to using a struct.

Three values that are part of a unit (eg. a user profile with name, age and
occupation) of which you can have more than one constitutes more of a reason
for using a struct (or class).

Every class, enumeration, structure should have it's own .cs file, which is
called "<objectname>.cs" where <objectname> is the name given to your
enumeration, structure etc...

If you're going to load your objects from a file, data base etc, then you'd
create a object serialiser class which would save, load, update, add objects
to your source. This again would exist in a seperate ".cs" file.

I'd suggest reading up more here:
http://csharpcomputing.com/Tutorials/Lesson1.htm
Then maybe head over to here: http://www.yoda.arachsys.com/csharp/

Hope that helps.

Dan
 
B

Bruce Wood

Strong suggestion: if you do decide to aggregate the three values from
the three text boxes, use a class, not a struct.
 
G

Guest

Thanks Dan!

Dan Bass said:
// assigns the text "Fred" to the textbox
nameTextBox.Text = "Fred";

Three textboxes, three default values doesn't equate to using a struct.

Three values that are part of a unit (eg. a user profile with name, age and
occupation) of which you can have more than one constitutes more of a reason
for using a struct (or class).

Every class, enumeration, structure should have it's own .cs file, which is
called "<objectname>.cs" where <objectname> is the name given to your
enumeration, structure etc...

If you're going to load your objects from a file, data base etc, then you'd
create a object serialiser class which would save, load, update, add objects
to your source. This again would exist in a seperate ".cs" file.

I'd suggest reading up more here:
http://csharpcomputing.com/Tutorials/Lesson1.htm
Then maybe head over to here: http://www.yoda.arachsys.com/csharp/

Hope that helps.

Dan
 
G

Guest

Thanks for the suggestion. As you can tell I am really Green at this! I've
been able to program in VBScript but it does not even compare to the
complexity of C#!

I guess I just have to get the basics and go from there!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top