Reputation: 105
I have a winform application running , i added one more winform one top of this application which will pass some datas to the the application. After passing the datas to the application, Save button will be enabled to save data in to application. The save button is toolstripmenuitem. One issue i am facing is when the newly added form is still there, i need to click two times to save ie first click will not click properly . Or if i close the newly added winform then save click will happen first time itself or if i click any part of the exisitng application ie focus will be there ,then also first click will do.
Upvotes: 4
Views: 1546
Reputation: 1541
Adding this method override to the form containing your tool strip should take care of it.
protected override void WndProc(ref Message m)
{
const int WM_PARENTNOTIFY = 0x0210;
if (m.Msg == WM_PARENTNOTIFY)
{
if (!Focused)
Activate();
}
base.WndProc(ref m);
}
The tool strip is performing the Activate call only, so by handling it ourselves it will perform the Click event
Upvotes: 13
Reputation: 1101
When you enable the save button wich you at some point have to do in your main form, call Focus() on it. That way focus is given back to the main form and the user can perform one click to save
Upvotes: 0
Reputation: 1225
You pretty answered your own question: new form takes focus when got added. So it is up to you how to handle this "by design" issue:
;)
Upvotes: 0