StrataFrame Forum

Setting focus to Button in a ThemedToolStrip

http://forum.strataframe.net/Topic31876.aspx

By Ger Cannoll - 2/26/2013

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
By StrataFrame Team - 2/26/2013

.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.