Click here to Skip to main content
15,892,737 members
Home / Discussions / C#
   

C#

 
Question20 Questions Algorithm Pin
Andre Trollip10-Sep-07 21:43
Andre Trollip10-Sep-07 21:43 
AnswerRe: 20 Questions Algorithm Pin
suveenmohan10-Sep-07 23:47
suveenmohan10-Sep-07 23:47 
GeneralRe: 20 Questions Algorithm Pin
Andre Trollip11-Sep-07 3:17
Andre Trollip11-Sep-07 3:17 
QuestionMicrosoft image printing problems Pin
pmartike10-Sep-07 20:43
pmartike10-Sep-07 20:43 
Questiondisable a button Pin
Sunshine Always10-Sep-07 20:07
Sunshine Always10-Sep-07 20:07 
AnswerRe: disable a button Pin
Chetan Patel10-Sep-07 20:23
Chetan Patel10-Sep-07 20:23 
GeneralRe: disable a button Pin
Sunshine Always10-Sep-07 20:31
Sunshine Always10-Sep-07 20:31 
GeneralRe: disable a button Pin
Martin#10-Sep-07 22:06
Martin#10-Sep-07 22:06 
Hello,

You have to set the "Enabled" property before the user clicks the button.


If you want to make a validation on the/an event itselfe,
I would suggest inherit your own Button from System.Windows.Forms.Button.

Use a validation method which uses Flags or some other stuff.

Override OnMouseDown, which checks the validation method and calls the base method or not!
Not calling the base method of OnMouseDown, will prevent the click event from fireing!

See this code example:
public class SpecialButton : System.Windows.Forms.Button
{
    public SpecialButton()
    {
    }

    private bool flag1 = true;
    public bool Flag1
    {
        get
        {
            return flag1;
        }
        set
        {
            if(value!=flag1)
                flag1 = value;
        }
    }

    private bool flag2 = true;
    public bool Flag2
    {
        get
        {
            return flag2;
        }
        set
        {
            if(value!=flag2)
                flag2 = value;
        }
    }

    private bool ValidateClick()
    {
        //If Flag1 and Flag2 are true, the Click event will be fired
        return Flag1&&Flag2;
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        if(ValidateClick())
        {
            //Validation ok (Click will fire)
            base.OnMouseDown (e);
        }
        else
        {
            //give some feedback to the user (MessageBox)
        }
    }
}


Hope it helps!



All the best,

Martin

AnswerRe: disable a button Pin
Luc Pattyn11-Sep-07 0:50
sitebuilderLuc Pattyn11-Sep-07 0:50 
Questionhow can show a pdf file in C#? Pin
B.A10-Sep-07 19:54
B.A10-Sep-07 19:54 
AnswerRe: how can show a pdf file in C#? Pin
satsumatable10-Sep-07 20:49
satsumatable10-Sep-07 20:49 
GeneralRe: how can show a pdf file in C#? Pin
blackjack215010-Sep-07 22:07
blackjack215010-Sep-07 22:07 
AnswerRe: how can show a pdf file in C#? Pin
Luc Pattyn11-Sep-07 0:52
sitebuilderLuc Pattyn11-Sep-07 0:52 
GeneralRe: how can show a pdf file in C#? Pin
B.A11-Sep-07 3:17
B.A11-Sep-07 3:17 
Questionavoid .net reflector Pin
Eli Nurman10-Sep-07 18:32
Eli Nurman10-Sep-07 18:32 
AnswerRe: avoid .net reflector Pin
VirtualVoid.NET10-Sep-07 21:43
VirtualVoid.NET10-Sep-07 21:43 
AnswerRe: avoid .net reflector Pin
Arjan Einbu10-Sep-07 21:49
Arjan Einbu10-Sep-07 21:49 
AnswerRe: avoid .net reflector Pin
blackjack215010-Sep-07 21:59
blackjack215010-Sep-07 21:59 
AnswerJust a thought Pin
Urs Enzler11-Sep-07 2:56
Urs Enzler11-Sep-07 2:56 
QuestionHow to combine two DLL into one ? Pin
bug_aonz10-Sep-07 17:22
bug_aonz10-Sep-07 17:22 
AnswerRe: How to combine two DLL into one ? Pin
Mark Churchill10-Sep-07 18:05
Mark Churchill10-Sep-07 18:05 
GeneralRe: How to combine two DLL into one ? Pin
bug_aonz10-Sep-07 18:32
bug_aonz10-Sep-07 18:32 
AnswerRe: How to combine two DLL into one ? Pin
Virendrak10-Sep-07 19:43
Virendrak10-Sep-07 19:43 
AnswerRe: How to combine two DLL into one ? Pin
Virendrak10-Sep-07 19:51
Virendrak10-Sep-07 19:51 
QuestionHow to download multiple files in the same url? Pin
bug_aonz10-Sep-07 17:15
bug_aonz10-Sep-07 17:15 

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.