Click here to Skip to main content
15,896,278 members
Home / Discussions / C#
   

C#

 
GeneralRe: Implementation in C# Pin
S. Senthil Kumar26-May-05 2:55
S. Senthil Kumar26-May-05 2:55 
GeneralRe: Implementation in C# Pin
Colin Angus Mackay26-May-05 3:16
Colin Angus Mackay26-May-05 3:16 
GeneralRe: Implementation in C# Pin
S. Senthil Kumar26-May-05 4:24
S. Senthil Kumar26-May-05 4:24 
GeneralWhy toolbar buttons doesn't care of CausesValidation Pin
Itanium26-May-05 0:38
Itanium26-May-05 0:38 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Luis Alonso Ramos26-May-05 5:12
Luis Alonso Ramos26-May-05 5:12 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Luis Alonso Ramos26-May-05 5:13
Luis Alonso Ramos26-May-05 5:13 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Itanium31-May-05 22:42
Itanium31-May-05 22:42 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Luis Alonso Ramos1-Jun-05 6:01
Luis Alonso Ramos1-Jun-05 6:01 
When you click on a toolbar button, the control that has the focus doesn't lose it, and thus Validating/Validated events are not generated.

My solution goes to great length to ensure that the focus is given back to the control that has it, so that it acts the same as you.

Your solution simply takes focus away from the currently focused control, and doesn't give it back. I did try something similar before getting to my recursive solution, but I don't remember the details.

I took your code and gave it a try, and this is what I came up with:
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
    if(!ValidateFocusedControl())
        return;

    if(e.Button == toolBarButton1)
        MessageBox.Show(this, "Button 1 clicked!");
    else if(e.Button == toolBarButton2)
        MessageBox.Show(this, "Button 2 clicked!");
}
The heart of if is that call to ValidateFocusedControl:
protected bool ValidateFocusedControl()
{
    bool result = true;

    Control ctl = ActiveControl;
    toolBar1.Focus();
    if(!toolBar1.Focused)
        result = false;
    ctl.Focus();
    return result;
}
I gave it a try and it works as expected, even with controls inside tabpages for example.

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

Generaldatagrid complex object binding Pin
nonick226-May-05 0:09
nonick226-May-05 0:09 
GeneralDisplay line and column on satusbar Pin
hoangsamac25-May-05 23:45
hoangsamac25-May-05 23:45 
Generalgetting the ListBox list as an array Pin
Green Fuze25-May-05 23:41
Green Fuze25-May-05 23:41 
GeneralRe: getting the ListBox list as an array Pin
pubududilena26-May-05 0:07
pubududilena26-May-05 0:07 
GeneralRe: getting the ListBox list as an array Pin
Green Fuze26-May-05 1:26
Green Fuze26-May-05 1:26 
GeneralNew starter - Common Module Q. Pin
Member 199247025-May-05 23:11
Member 199247025-May-05 23:11 
GeneralRe: New starter - Common Module Q. Pin
Itanium26-May-05 0:10
Itanium26-May-05 0:10 
GeneralRe: New starter - Common Module Q. Pin
Member 199247026-May-05 1:03
Member 199247026-May-05 1:03 
Generalget Time on Server Pin
SEAGames2225-May-05 23:00
SEAGames2225-May-05 23:00 
GeneralRe: get Time on Server Pin
pubududilena25-May-05 23:52
pubududilena25-May-05 23:52 
GeneralRe: get Time on Server Pin
Dave Kreskowiak26-May-05 4:02
mveDave Kreskowiak26-May-05 4:02 
QuestionModule like vb.net ? Pin
LIUCKAS25-May-05 22:42
LIUCKAS25-May-05 22:42 
AnswerRe: Module like vb.net ? Pin
Colin Angus Mackay25-May-05 22:52
Colin Angus Mackay25-May-05 22:52 
GeneralRe: Module like vb.net ? Pin
LIUCKAS25-May-05 23:14
LIUCKAS25-May-05 23:14 
QuestionHow we can stop to creating new Instance on same click of form Pin
Trivikram Dwivedi25-May-05 22:30
Trivikram Dwivedi25-May-05 22:30 
AnswerRe: How we can stop to creating new Instance on same click of form Pin
Itanium25-May-05 23:03
Itanium25-May-05 23:03 
GeneralRe: How we can stop to creating new Instance on same click of form Pin
Trivikram Dwivedi25-May-05 23:54
Trivikram Dwivedi25-May-05 23:54 

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.