Click here to Skip to main content
15,883,901 members
Home / Discussions / C#
   

C#

 
AnswerRe: Storing Info Between Events Pin
Luc Pattyn23-Jun-12 4:08
sitebuilderLuc Pattyn23-Jun-12 4:08 
GeneralRe: Storing Info Between Events Pin
Richard MacCutchan23-Jun-12 4:45
mveRichard MacCutchan23-Jun-12 4:45 
AnswerRe: Storing Info Between Events Pin
Luc Pattyn23-Jun-12 4:55
sitebuilderLuc Pattyn23-Jun-12 4:55 
GeneralRe: Storing Info Between Events Pin
Richard MacCutchan23-Jun-12 5:08
mveRichard MacCutchan23-Jun-12 5:08 
AnswerRe: Storing Info Between Events Pin
Luc Pattyn23-Jun-12 5:11
sitebuilderLuc Pattyn23-Jun-12 5:11 
GeneralRe: Storing Info Between Events Pin
Richard MacCutchan23-Jun-12 5:14
mveRichard MacCutchan23-Jun-12 5:14 
GeneralRe: Storing Info Between Events Pin
Dave Kreskowiak23-Jun-12 5:37
mveDave Kreskowiak23-Jun-12 5:37 
AnswerRe: Storing Info Between Events Pin
Luc Pattyn23-Jun-12 4:04
sitebuilderLuc Pattyn23-Jun-12 4:04 
Your code seems to suggest that you are maintaining the state of your app in a variable (clickCount) which is declared inside the button Click handler, which means it won't survive the handling of a click, hence it will always restart having the value of 1.

You should move the declaration outside the method, i.e. make it a class member. That way, for each instance of the Form (assuming you might create more than one of them), the button would remember its state.
You do not need the static keyword, unless you want to have all instances of that Form to share their state (which seems unlikely to me).

IMO it is easier and robuster to put the state inside the button itself; there are several ways to achieve this;
- one is to create your own MyButton class, inheriting from Button, and taking care of its peculiarities (IMO it would be overkill here);
- another is to hide the state in the Tag property, which is a field provided but unused by Windows for all WinForms Controls, so it is available for whatever purpose you decide to use it for. Mind you, it is of type object, so you would need some casting. (I prefer this approach).
- and then you could derive the state from existing variables and/or properties; in your example, you could perhaps just check the txtDisplay.Text and when it ends on "Side1" just replace "Side1" by "Side2". (I typically don't do it this way, as it is less robust; e.g. when you change languages, there is more code that needs changing).

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum


modified 23-Jun-12 10:12am.

GeneralRe: Storing Info Between Events Pin
ASPnoob23-Jun-12 7:24
ASPnoob23-Jun-12 7:24 
GeneralRe: Storing Info Between Events Pin
Dave Kreskowiak23-Jun-12 9:56
mveDave Kreskowiak23-Jun-12 9:56 
AnswerRe: Storing Info Between Events Pin
Luc Pattyn23-Jun-12 10:48
sitebuilderLuc Pattyn23-Jun-12 10:48 
GeneralRe: Storing Info Between Events Pin
ignrod27-Jun-12 1:11
ignrod27-Jun-12 1:11 
QuestionConverting BindingSource and Guid [solved] Pin
Midnight Ahri22-Jun-12 17:11
Midnight Ahri22-Jun-12 17:11 
AnswerRe: Converting BindingSource and Guid Pin
OriginalGriff22-Jun-12 19:50
mveOriginalGriff22-Jun-12 19:50 
AnswerRe: Converting BindingSource and Guid Pin
Midnight Ahri22-Jun-12 20:08
Midnight Ahri22-Jun-12 20:08 
GeneralRe: Converting BindingSource and Guid Pin
OriginalGriff22-Jun-12 20:24
mveOriginalGriff22-Jun-12 20:24 
QuestionListbox Pin
Dirk Higbee22-Jun-12 12:57
Dirk Higbee22-Jun-12 12:57 
AnswerRe: Listbox Pin
OriginalGriff22-Jun-12 19:52
mveOriginalGriff22-Jun-12 19:52 
GeneralRe: Listbox Pin
Dirk Higbee23-Jun-12 7:30
Dirk Higbee23-Jun-12 7:30 
QuestionHow to split byte[] to string & bytes Pin
caspidoron22-Jun-12 8:53
caspidoron22-Jun-12 8:53 
AnswerRe: How to split byte[] to string & bytes Pin
Ian Shlasko22-Jun-12 9:00
Ian Shlasko22-Jun-12 9:00 
AnswerRe: How to split byte[] to string & bytes Pin
Richard Andrew x6422-Jun-12 9:02
professionalRichard Andrew x6422-Jun-12 9:02 
QuestionC# work with database Pin
sc steinhayse22-Jun-12 7:33
sc steinhayse22-Jun-12 7:33 
AnswerRe: C# work with database Pin
Ravi Bhavnani23-Jun-12 4:00
professionalRavi Bhavnani23-Jun-12 4:00 
QuestionC# to update table Pin
sc steinhayse22-Jun-12 3:43
sc steinhayse22-Jun-12 3:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.