开发者

Default Button on Form (VB 2008)

I want to find a way to make a specific button, the form's default button, I.e. the button that is h开发者_Python百科ighlighted when the form opens for the first time.

I tried the AcceptButton property but when I run the program, that does not work.

Any idea?

Thank you in advance,

Tassos


You need to change the AcceptButton property of the containing form.

form1.AcceptButton = button1

Here form1 is the Form whose default button you need to set, and button1 is the name of the Button on that form.


The form's AcceptButton and CancelButton properties define the default behaviour for the Enter and Escape keys, rather than the highlighting.

To highlight the button use the Focus method, but when doing this in the form_load event you will need to call the Select method instead.

btnDefault.Select()

As mentioned in the comments, setting the control to the lowest taborder will achieve the same thing


The answer from 'chk' on 5/2/13 is the correct answer, but is shown as a string which of course is not the way to do it.

Also, in the form's property sheet you can find, under Misc, the property 'AcceptButton'. This will give you a list of buttons on the form - just select the one you want.

The button selected as the AcceptButton will behave as the 'default' button. It will be 'highlighted' with a darker border and will be clicked when you push the Enter key on your keyboard.

Setting up an AcceptButton is different than setting the button's focus. The AcceptButton's click event will be triggered by the Enter key no matter which control has the focus on the form.


You can also do this programmatically. I have a maintenance form where initially I want the "search" button as the form accept button. when I'm displaying the field maintenance area, I want the "ok" button to be the accept button. You simply change this in the appropriate areas in your code to Me.AcceptButton = MyButtonName.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜