have a form return a value when it closes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aXdkdTE1?=

    #1

    have a form return a value when it closes

    hi, im attempting to create an intellisense type form and have hit a
    roadblock. I need the form to return (like the ShowDialog method returns the
    dialog result) the value that was selected when the form closes. however, i
    cannot just create a method that shadows ShowDialog and return it that way
    because the form needs to close when the user clicks elsewhere on the screen,
    or Alt-Tabs away from the window. i already have the code to close the window
    when the user clicks or aalt-tabs away, but how can i have the form return a
    result when this occurs? thanks
    --
    -iwdu15
  • Lloyd Sheen

    #2
    Re: have a form return a value when it closes

    You can create a public property on the form and then after the return from
    ShowDialog get the value. When the form returns the class object (which is
    the form) is still available and you can read the value from the property.
    I do this lots.

    LS

    "iwdu15" <jmmgoalsteraty ahoodotcomwrote in message
    news:154E5533-2084-487A-A321-C1E80CEDBC9E@mi crosoft.com...
    hi, im attempting to create an intellisense type form and have hit a
    roadblock. I need the form to return (like the ShowDialog method returns
    the
    dialog result) the value that was selected when the form closes. however,
    i
    cannot just create a method that shadows ShowDialog and return it that way
    because the form needs to close when the user clicks elsewhere on the
    screen,
    or Alt-Tabs away from the window. i already have the code to close the
    window
    when the user clicks or aalt-tabs away, but how can i have the form return
    a
    result when this occurs? thanks
    --
    -iwdu15

    Comment

    • RobinS

      #3
      Re: have a form return a value when it closes

      You can invoke a function on the form that returns a value, and in the
      function do a me.showdialog() . Like this:

      'to invoke this class, do this: X = SelectDatabase. PromptUser
      ' X will be the returned ConnectionStrin g.
      'Return empty string if user clicks Cancel.
      Public Function PromptUser() As String
      Me.ShowDialog()
      If (Me.DialogResul t = Windows.Forms.D ialogResult.OK) Then
      My.Settings.DBC onnString = CreateConnectio nString("Y")
      My.Settings.Dat abaseName = DatabaseComboBo x.Text
      My.Settings.Ser verName = ServerTextBox.T ext
      My.Settings.Sav e()
      Return DatabaseComboBo x.Text
      Else
      Return String.Empty
      End If
      End Function

      Robin S.
      --------------------------
      "iwdu15" <jmmgoalsteraty ahoodotcomwrote in message
      news:154E5533-2084-487A-A321-C1E80CEDBC9E@mi crosoft.com...
      hi, im attempting to create an intellisense type form and have hit a
      roadblock. I need the form to return (like the ShowDialog method returns
      the
      dialog result) the value that was selected when the form closes. however,
      i
      cannot just create a method that shadows ShowDialog and return it that
      way
      because the form needs to close when the user clicks elsewhere on the
      screen,
      or Alt-Tabs away from the window. i already have the code to close the
      window
      when the user clicks or aalt-tabs away, but how can i have the form
      return a
      result when this occurs? thanks
      --
      -iwdu15

      Comment

      • =?Utf-8?B?aXdkdTE1?=

        #4
        Re: have a form return a value when it closes

        i realize i can do those things, the issue is that if the user clicks away or
        alt-tabs away from the window, ShowDialog does not let the window close. i
        want the window to close if the user clicks away or alt-tabs away, so i
        cannot use ShowDialog..... i pretty much need to make an exact replica of
        Intellisense
        --
        -iwdu15

        Comment

        • ImageAnalyst

          #5
          Re: have a form return a value when it closes

          I thought you said (in your first post) that you solved the problem of
          closing the form when the user clicks away. Are you now saying you
          didn't solve that? I'd probably try putting a me.close() in the
          form's LostFocus event. And I may need to show the form modeless with
          a Show() method rather than modally with a ShowDialog() method (if it
          beeps at you when you try to click somewhere else).

          I still think Lloyd's solution should work for you. Not sure why you
          don't.
          Regards,
          ImageAnalyst

          On Feb 24, 3:22 pm, iwdu15 <jmmgoalsteraty ahoodotcomwrote :
          i realize i can do those things, the issue is that if the user clicks away or
          alt-tabs away from the window, ShowDialog does not let the window close. i
          want the window to close if the user clicks away or alt-tabs away, so i
          cannot use ShowDialog..... i pretty much need to make an exact replica of
          Intellisense
          --
          -iwdu15

          Comment

          • Lloyd Sheen

            #6
            Re: have a form return a value when it closes

            If you want click away functionallity then perhaps you can use the context
            menu. It can be shown thru code as well as auto and as a control's context
            menu.

            Then when you click away the dialog (context menu) will disappear.

            LS
            "iwdu15" <jmmgoalsteraty ahoodotcomwrote in message
            news:2802BEEA-AA63-4F2E-8259-E270FE6C90EE@mi crosoft.com...
            >i realize i can do those things, the issue is that if the user clicks away
            >or
            alt-tabs away from the window, ShowDialog does not let the window close. i
            want the window to close if the user clicks away or alt-tabs away, so i
            cannot use ShowDialog..... i pretty much need to make an exact replica of
            Intellisense
            --
            -iwdu15

            Comment

            • Chris Dunaway

              #7
              Re: have a form return a value when it closes

              On Feb 24, 9:34 pm, "ImageAnaly st" <imageanal...@m ailinator.com>
              wrote:
              I thought you said (in your first post) that you solved the problem of
              closing the form when the user clicks away. Are you now saying you
              didn't solve that? I'd probably try putting a me.close() in the
              form's LostFocus event. And I may need to show the form modeless with
              a Show() method rather than modally with a ShowDialog() method (if it
              beeps at you when you try to click somewhere else).
              >
              If he uses the Show method, as soon as the form closes, it will be
              disposed and if he then tries to access a custom property he will
              likely get an exception.


              Comment

              • RobinS

                #8
                Re: have a form return a value when it closes


                "Chris Dunaway" <dunawayc@gmail .comwrote in message
                news:1172502898 .594707.7340@q2 g2000cwa.google groups.com...
                On Feb 24, 9:34 pm, "ImageAnaly st" <imageanal...@m ailinator.com>
                wrote:
                >I thought you said (in your first post) that you solved the problem of
                >closing the form when the user clicks away. Are you now saying you
                >didn't solve that? I'd probably try putting a me.close() in the
                >form's LostFocus event. And I may need to show the form modeless with
                >a Show() method rather than modally with a ShowDialog() method (if it
                >beeps at you when you try to click somewhere else).
                >>
                >
                If he uses the Show method, as soon as the form closes, it will be
                disposed and if he then tries to access a custom property he will
                likely get an exception.
                >
                >
                He could put a property in his first form, and set it from the second form
                in the form_closing event.

                Robin S.


                Comment

                Working...