way to read object info in another form/passing parameter like

F

Franck

I know in vb6 it was super easy to pass parameter or either read
example the textbox1.text on the already open form form2

like all object were as public. but is there a way to do something
that easy in c# because i wonder is there is a faster way than the
following example i use right now

to assign a control in another form a value at opening (ex:
textbox1.text)

frmForm2 frm = new frmForm2();
frm.textbox1.text = "bla bla bla";
frm.show();

and here the way i use for example if i would like from frmForm1 read
what's inside the currently opened frmForm2

first in frmForm2 i create a get class like

public string FormTexbox1TextValue
{
get{return this.textbox1.text};
}

and now in form1 i can call it by frmForm2.FormTextbox1TextValue() and
it'll return me the value of his textbox.

so is there any faster way
 
N

Nicholas Paldino [.NET/C# MVP]

Franck,

You could always change the controls which are members of the form to
public, instead of private. However, you have to be aware of the issues
involved with exposing your control (in other words, you are making it
public, and depending on who is using the form, it might trigger effects you
are not prepared for).

A generally better way of doing this is to expose methods and properties
which will perform the actions on the private members and then call those.
 
F

Franck

as exposing the object property is there a fast way like for example:
public textbox1.text();

something look like this, any example of putting public the text
property of a textbox would be nice
 
N

Nicholas Paldino [.NET/C# MVP]

Franck,

In the designer, there should be a row in the property box which allows
you to change the access modifier from private to public.

Or, just change the declaration in the designer-generated code (or
hand-generated, if you are not using a designer) to not be
private/protected.
 
F

Franck

Franck,

In the designer, there should be a row in the property box which allows
you to change the access modifier from private to public.

Or, just change the declaration in the designer-generated code (or
hand-generated, if you are not using a designer) to not be
private/protected.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


as exposing the object property is there a fast way like for example:
public textbox1.text();
something look like this, any example of putting public the text
property of a textbox would be nice

but in that case it allow the full control of the object
 
N

Nicholas Paldino [.NET/C# MVP]

Franck,

Yes, which is the behavior that you get in VB. If you don't want to
expose full control of the object, then you have to expose a method or
property on the hosting control/form which takes the parameters that you
need, and performs the action you want.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Franck said:
Franck,

In the designer, there should be a row in the property box which
allows
you to change the access modifier from private to public.

Or, just change the declaration in the designer-generated code (or
hand-generated, if you are not using a designer) to not be
private/protected.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


as exposing the object property is there a fast way like for example:
public textbox1.text();
something look like this, any example of putting public the text
property of a textbox would be nice

but in that case it allow the full control of the object
 
F

Franck

Franck,

Yes, which is the behavior that you get in VB. If you don't want to
expose full control of the object, then you have to expose a method or
property on the hosting control/form which takes the parameters that you
need, and performs the action you want.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Franck,
In the designer, there should be a row in the property box which
allows
you to change the access modifier from private to public.
Or, just change the declaration in the designer-generated code (or
hand-generated, if you are not using a designer) to not be
private/protected.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

as exposing the object property is there a fast way like for example:
public textbox1.text();
something look like this, any example of putting public the text
property of a textbox would be nice
but in that case it allow the full control of the object

got it thank you
 

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