Setting focus to Button in a ThemedToolStrip


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I want to set focus to a Button in a ThemedToolstrip, so that when the form loads, it will be enabled and just need to hit the Enter Key

I dont seem to be able to get an option to do this
StrataFrame Team
S
StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)StrataFrame Developer (4.7K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
.NET doesn't do this for you by default.  It takes a little work, but you can get it done.  Basically, you want to set the System.Windows.Forms.Form.AcceptButton property to your toolstrip button.  The AcceptButton property accepts an IButtonControl object, but ToolStripButton does not implement it by default.  If you subclass ToolStripButton and implement that interface (it's simple, just 3 members), you can then set it as the AcceptButton on the form, and the form will call PerformClick() on it when the user hits enter, even if the button doesn't have focus.  

When you subclass the ToolStripButton, you cannot set it through the designer. The ToolStrip designer only knows about the ToolStripButton class, not your subclass.  You will need to create the button and add it to the ToolStrip in code somewhere in the constructor of your form.  I think you'll need to set the AcceptButton in code as well, because the TypeEditor for it won't be able to see your custom button.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search