Default button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    Default button

    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
  • Greg Burns

    #2
    Re: Default button

    It is now a property of the Form itself. Look for the AcceptButton and
    CancelButton properties.

    Greg

    "cj" <cj@nospam.nosp am> wrote in message
    news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...[color=blue]
    > 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[/color]


    Comment

    • cj

      #3
      Re: Default button

      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.NotifyD efault(True)
      but it doesn't work. What is it supposed to do? I didn't understand
      the help.

      Thanks

      Greg Burns wrote:[color=blue]
      > It is now a property of the Form itself. Look for the AcceptButton and
      > CancelButton properties.
      >
      > Greg
      >
      > "cj" <cj@nospam.nosp am> wrote in message
      > news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...
      >[color=green]
      >>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[/color]
      >
      >
      >[/color]

      Comment

      • Greg Burns

        #4
        Re: Default button

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

        "cj" <cj@nospam.nosp am> wrote in message
        news:%23R3ksymB GHA.3604@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        >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.NotifyD efault(True)
        > but it doesn't work. What is it supposed to do? I didn't understand the
        > help.
        >
        > Thanks
        >
        > Greg Burns wrote:[color=green]
        >> It is now a property of the Form itself. Look for the AcceptButton and
        >> CancelButton properties.
        >>
        >> Greg
        >>
        >> "cj" <cj@nospam.nosp am> wrote in message
        >> news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...
        >>[color=darkred]
        >>>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[/color]
        >>
        >>[/color][/color]

        Comment

        • Greg Burns

          #5
          Re: Default button

          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

          "Greg Burns" <bluebunny@news groups.nospam> wrote in message
          news:%23cFLF3mB GHA.272@TK2MSFT NGP11.phx.gbl.. .[color=blue]
          > Now you're making an easy question hard! :)
          >
          > "cj" <cj@nospam.nosp am> wrote in message
          > news:%23R3ksymB GHA.3604@TK2MSF TNGP09.phx.gbl. ..[color=green]
          >>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.NotifyD efault(True)
          >> but it doesn't work. What is it supposed to do? I didn't understand the
          >> help.
          >>
          >> Thanks
          >>
          >> Greg Burns wrote:[color=darkred]
          >>> It is now a property of the Form itself. Look for the AcceptButton and
          >>> CancelButton properties.
          >>>
          >>> Greg
          >>>
          >>> "cj" <cj@nospam.nosp am> wrote in message
          >>> news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...
          >>>
          >>>>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
          >>>
          >>>[/color][/color]
          >[/color]


          Comment

          • cj

            #6
            Re: Default button


            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!

            Greg Burns wrote:[color=blue]
            > 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
            >
            > "Greg Burns" <bluebunny@news groups.nospam> wrote in message
            > news:%23cFLF3mB GHA.272@TK2MSFT NGP11.phx.gbl.. .
            >[color=green]
            >>Now you're making an easy question hard! :)
            >>
            >>"cj" <cj@nospam.nosp am> wrote in message
            >>news:%23R3ksy mBGHA.3604@TK2M SFTNGP09.phx.gb l...
            >>[color=darkred]
            >>>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.NotifyD efault(True)
            >>>but it doesn't work. What is it supposed to do? I didn't understand the
            >>>help.
            >>>
            >>>Thanks
            >>>
            >>>Greg Burns wrote:
            >>>
            >>>>It is now a property of the Form itself. Look for the AcceptButton and
            >>>>CancelButto n properties.
            >>>>
            >>>>Greg
            >>>>
            >>>>"cj" <cj@nospam.nosp am> wrote in message
            >>>>news:udFimS mBGHA.4004@tk2m sftngp13.phx.gb l...
            >>>>
            >>>>
            >>>>>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
            >>>>
            >>>>[/color][/color]
            >
            >[/color]

            Comment

            • Chris Johnson

              #7
              Re: Default button

              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

              "cj" <cj@nospam.nosp am> wrote in message
              news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...[color=blue]
              > 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[/color]


              Comment

              • Greg Burns

                #8
                Re: Default button

                Using the AcceptButton property is important if you want to write code like
                this:

                Dim f As New Form1
                Dim r As Windows.Forms.D ialogResult = f.ShowDialog

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

                Greg

                "Chris Johnson" <raven65@gmail. com> wrote in message
                news:OrkrZHnBGH A.2300@TK2MSFTN GP15.phx.gbl...[color=blue]
                >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
                >
                > "cj" <cj@nospam.nosp am> wrote in message
                > news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...[color=green]
                >> 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[/color]
                >
                >[/color]


                Comment

                • Peter Huang [MSFT]

                  #9
                  Re: Default button

                  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.

                  Comment

                  • cj

                    #10
                    Re: Default button

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


                    Chris Johnson wrote:[color=blue]
                    > 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
                    >
                    > "cj" <cj@nospam.nosp am> wrote in message
                    > news:udFimSmBGH A.4004@tk2msftn gp13.phx.gbl...
                    >[color=green]
                    >>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[/color]
                    >
                    >
                    >[/color]

                    Comment

                    • Peter Huang [MSFT]

                      #11
                      Re: Default button

                      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.

                      Comment

                      Working...