Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change controls properties in other forms in C#.

I change modifiers to public and when I use parent.Show();, I see results!!! But I don't want to use Show() method.

For example I want to press a button in a form and this action changes the size of a Textbox on another form without calling Show() method.

I want to do this without reloading destination form.

Please help me with an example. :)
Posted
Updated 9-Nov-11 3:47am
v3

Go back to your form, and change all those modifiers back to private.

When you expose controls and fields on your form, you tie the design of the form to what uses it - you cannot change how the form works any more without having to think very carefully about any possible affect it may have on other forms or classes. This is a recipe for bugs and maintenance hassles. Do not do it.

There are two "proper" ways to do this:

1) Create public properties in your form which up-date your form controls. Your form can them change how it works internally, without affecting the outside world.

2) Create events in the outside world which your form can subscribe to. These would indicate "data changed" and cause the updates to be done inside the form.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Nov-11 12:39pm    
OP commented (the false "solution" post removed):

please give me a clear example. im not experienced in C#
Sergey Alexandrovich Kryukov 9-Nov-11 12:42pm    
I voted 5 for this solution and replied, please see.
If such a simple advice is not understood, the only way is to get more experience first. :-)

I agree this solution is good enough but I think -- for small and simple applications. As you probably know, I'm in favor of more advanced solution which is better for more complex applications.
--SA
Use a static global class that contains properties that your forms can set/get, and change the accessors back to either private or protected (whatever they were).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Nov-11 12:39pm    
OP commented (the false "solution" post removed):

please give me a clear example. im not experienced in C#
Sergey Alexandrovich Kryukov 9-Nov-11 12:42pm    
I voted 5 for this solution and replied, please see.
If such a simple advice is not understood, the only way is to get more experience first. :-)

I agree this solution is good enough but I think -- for small and simple applications. As you probably know, I'm in favor of more advanced solution which is better for more complex applications.
--SA
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Sorry, I saw your post about being inexperienced developer. First, please never post non-answers as the "solution". Such posts will be removed, no one will get e-mail notification. Instead, add comment, comment on existing comment, use "Improve Question".

Well, the only thing which helps is getting experienced. :-)
Detailed code sample won't help you much, if you cannot follow such simple instructions as those provided by Griff and John. In this case, I could advise just one thing: stop attempting to create a real-life windowed application. First, learn all the basic techniques on console applications and very simple codes, come back to anything else when you are really confident.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900