Default button

  • Thread starter Thread starter cj
  • Start date Start date
C

cj

Here's an easy one, I hope. How do I make button1, which I put on this
form from the toolbox, the default button on the form?

I thought it used to be a property in the properties window called
default. It's not there now. I found in the help index an isdefault
property and tried to set it in code but it doesn't show up in the list
when I type button1.isdef
 
It is now a property of the Form itself. Look for the AcceptButton and
CancelButton properties.

Greg
 
I looked and if, in the form1_load event, I type form1. acceptbutton
doesn't come up. If I type me. acceptbutton appears. Don't both refer
to the same form? I also tried activeform. and acceptbutton is there
too. What's different in that?

BTW, while I was waiting for a reply I found Button1.NotifyDefault(True)
but it doesn't work. What is it supposed to do? I didn't understand
the help.

Thanks
 
Now you're making an easy question hard! :)

cj said:
I looked and if, in the form1_load event, I type form1. acceptbutton
doesn't come up. If I type me. acceptbutton appears. Don't both refer to
the same form? I also tried activeform. and acceptbutton is there too.
What's different in that?

BTW, while I was waiting for a reply I found Button1.NotifyDefault(True)
but it doesn't work. What is it supposed to do? I didn't understand the
help.

Thanks
 
Your form1 is the class type, whereas Me is an instance of the form1 class.

I assume the properties and methods you see when you form1 are the shared
properites/methods of the class only.

I'm not sure why you would want to use NotifyDefault, but I gives a button
the "look" of being the default without really making it so.

Greg
 
Your right, I was making an easy question hard wasn't I. Sorry, but
thanks for the input. Ok, I guess classes and instances are still a bit
fuzzy to me as I thought form1 was an instance of the form class. Don't
worry about it, I'll pick it up as I go. As for NotifyDefault, Humm, I
guess it would be useful if you want to confuse your users. Or maybe
Microsoft wanted to confuse me. Er, I mean me as in me or is me an
instance of I? Darn it, where is my medication!
 
I created a small sample project just now, and it seems
that setting the TabIndex property of the buttom to 0
is sufficient to make the button the default item on the form.

That is ofcourse, until your user presses tab, but that's
true anyway...

Let us know if that works for your situation,
chrisj
 
Using the AcceptButton property is important if you want to write code like
this:

Dim f As New Form1
Dim r As Windows.Forms.DialogResult = f.ShowDialog

If r = DialogResult.OK Then
' do something
End If

Greg
 
Hi

Form1 is a derived class from Form.
And then we use
Dim fm as Form1
fm is a instance

As for NotifyDefault, based on the MSDN, it should be called by the parent
form and we should use AcceptButton to assign a default button.

This method is called by the parent form to notify the Button that it
should be set as the default button and to allow it to adjust its
appearance accordingly. Typically, a button that is the default button for
a form has a thicker border than other buttons on the form.

Calling the NotifyDefault method only draws the button as a default button;
it does not change its behavior. To make the button behave like a default
button, it must be assigned to the AcceptButton property of the Form.




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
That's a fairly simple solution and I'm not checking results like Greg
is talking about. Neverless I'm setting acceptbutton because I set
focus to a text box when the form loads and I'd like the button's click
event to run regardless of what control the user is on if the user hits
enter (er. I should note this is the only button on the form).
 
Hi

Thanks for your input!
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top