Solved

C# Windows App

Posted on 2004-04-14
5
304 Views
Last Modified: 2010-04-15
Hello,

I have a Main form 'Parent' and in that form i have a button 'A'. if i click on the button 'A' in the parent form it takes me to a differnt form 'Child'. (like this)

frmA dr = new frmA();
dr.Show();

In 'Child' i have 2 buttons. One: Submit Second: Clear/Close. I have implemented all the funtionality for the 'Child' form.
After validating the 'Child' form the Submit button gets disabled and Clear button becomes Close button.

Now My question is::

When i click the Close button i want the Button 'A' in the 'Parent' form also to get disabled. I mean, After validating, submitting and closing the  child form the Button on the Parent form should also get disabled. How can i do it?
0
Comment
Question by:karra
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
int_20h earned 20 total points
ID: 10826171
you can pass the parent instance to the child form and create a public method in the parent that sets a boolean to disable the button.  In the child form, after validating the input, call the public method in the parent to disable the button.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10826585
you can also have the child form raise an event that the parent catches and then have the parent change the button state
0
 

Author Comment

by:karra
ID: 10826878
Can some one show me an example please?
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 30 total points
ID: 10827090
of my method ?

            public delegate void DisableButtonEventHandler(object sender, EventArgs e);
            public event DisableButtonEventHandler DisableButton;

            protected virtual void OnDisableButton(EventArgs e) {
                  if (DisableButton != null)
                        DisableButton(this, e);
            }
Child foo = new Child() ;
foo.DisableButton += new DisableuttonEventHandler(this.methodtohandle);

when you want the button disabled call OnDisableButton then trap the event in the parent the way you would any other event ... this also allows other things to trap it in the future


of his Method ...

You add a property to the child of parent (type is type of the parent)

Add a public  method to the parent DisableButton()

then in the child you say Parent.DisableButton() when you want it to be disabled

once done this allows easier future exchanges between the parent and child ...
0
 

Author Comment

by:karra
ID: 10843216
I got along with this problem with a easy answer.

child.ShowDialog(this);
if(!child.IsAccessible)
    btnChild.Enabled = false;
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now