C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,380 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,539 people online right now. Registration is fast and FREE... Join Now!




Check Whether Button Clicked or not - Please Help

 

Check Whether Button Clicked or not - Please Help

s2009

2 Jul, 2009 - 09:30 AM
Post #1

New D.I.C Head
*

Joined: 28 Jun, 2009
Posts: 31

Hi all,

I am creating an Windows application.

I have 2 forms.

In First form I have two buttons. The Second Buttons Enabled property is set to False.

If the First button is clicked then Form 2 should be shown which I have done with the Coding.

In the second Form I have one button If this button is clicked then it should show first form and the second button of that form should be enabled (Enabled property to be set to TRUE).

Can anyone help me out in doing this task?

Please help me out.

Thanks in advance!!

User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Check Whether Button Clicked Or Not - Please Help

2 Jul, 2009 - 09:32 AM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
You can use a static boolean somewhere that will store the button's state, which you can use within both forms.
User is offlineProfile CardPM
+Quote Post

s2009

RE: Check Whether Button Clicked Or Not - Please Help

2 Jul, 2009 - 09:12 PM
Post #3

New D.I.C Head
*

Joined: 28 Jun, 2009
Posts: 31

QUOTE(MageUK @ 2 Jul, 2009 - 09:32 AM) *

You can use a static boolean somewhere that will store the button's state, which you can use within both forms.



Thanks for your reply.



I tried using it but it is not working out.

Any other Idea please?


User is offlineProfile CardPM
+Quote Post

indrora

RE: Check Whether Button Clicked Or Not - Please Help

2 Jul, 2009 - 09:37 PM
Post #4

D.I.C Head
Group Icon

Joined: 25 Jul, 2008
Posts: 76



Thanked: 1 times
Dream Kudos: 75
My Contributions
... From the lessons I've learned from Beautiful Code...
csharp

// this is internal -- its used so that we dont interfere with other people reading it.
private bool _hasClicked = false;
// this is so that other objects dont mess with our internal state.
public bool hasClicked { get { return _hasClicked; } }

// this gets called when our button is clicked. It sets _hasClicked to true.
void buttonClicked(object s, EventArgs ea)
{
_hasClicked = true;
}


the "proper" way to do it.

Static bool's are not as useful as a ReadOnly property.

You may be wondering why I created a private boolean _hasClicked and a public boolean hasClicked with a "get" code block -- this is because we only want other objects to read or "get" the value (not "set" them). I'm from an era that uses '_' to state that the variable is private.



User is offlineProfile CardPM
+Quote Post

baavgai

RE: Check Whether Button Clicked Or Not - Please Help

3 Jul, 2009 - 03:29 AM
Post #5

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,261



Thanked: 389 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
So Form1 spawns Form2? And Form1 wants to know when Form2 clicks a button?

Make the button on Form2 public. When Form1 creates Form2, Form1 hooks into the Clicked event of the button on Form2. When Form2 button is clicked, Form1 gets notified and reacts appropriately.

User is offlineProfile CardPM
+Quote Post

s2009

RE: Check Whether Button Clicked Or Not - Please Help

3 Jul, 2009 - 03:38 AM
Post #6

New D.I.C Head
*

Joined: 28 Jun, 2009
Posts: 31

QUOTE(baavgai @ 3 Jul, 2009 - 03:29 AM) *

So Form1 spawns Form2? And Form1 wants to know when Form2 clicks a button?

Make the button on Form2 public. When Form1 creates Form2, Form1 hooks into the Clicked event of the button on Form2. When Form2 button is clicked, Form1 gets notified and reacts appropriately.




Ok

thanks for your prompt reply.

I have achieved the desired result.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 09:30PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month