InputBox function

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

    #1

    InputBox function

    I need WinForms function which displays promp and asks single field from
    user, like

    string res = Util.InputBox( "Enter value" );

    How to implement this ?


    Andrus.


  • Peter Duniho

    #2
    Re: InputBox function

    Andrus wrote:
    I need WinForms function which displays promp and asks single field from
    user, like
    >
    string res = Util.InputBox( "Enter value" );
    >
    How to implement this ?
    Make a form with a Label instance for the prompt ("Enter value") and a
    TextBox instance for the user input, a button for "OK" and optionally a
    "Cancel" button. Make sure the buttons are configured for the correct
    DialogResult (set their DialogResult property as desired).

    Instantiate the form, call ShowDialog() on it, if the return value is
    DialogResult.OK , process the Text property of the TextBox instance as
    your entered value.

    Wrap all of the above in a method that does all of the work and simply
    returns the string value obtained from the Text property of the TextBox.
    Don't forget to dispose your form instance before returning.

    Pete

    Comment

    • Andrus

      #3
      Re: InputBox function

      >I need WinForms function which displays promp and asks single field from
      >user, like
      >>
      >string res = Util.InputBox( "Enter value" );
      >>
      >How to implement this ?
      >
      Make a form with a Label instance for the prompt ("Enter value") and a
      TextBox instance for the user input, a button for "OK" and optionally a
      "Cancel" button. Make sure the buttons are configured for the correct
      DialogResult (set their DialogResult property as desired).
      >
      Instantiate the form, call ShowDialog() on it, if the return value is
      DialogResult.OK , process the Text property of the TextBox instance as your
      entered value.
      >
      Wrap all of the above in a method that does all of the work and simply
      returns the string value obtained from the Text property of the TextBox.
      Don't forget to dispose your form instance before returning.
      Pete,

      Can you provide example code please ?
      Or maybe some VB assembly contains such function ?

      Andrus.


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: InputBox function

        Or, one could set a reference to Microsoft.Visua lBasic.dll assembly and
        call the InputBox method on the Interaction class in the
        Microsoft.Visua lBasic namespace.

        Some don't like the idea of loading Microsoft.Visua lBasic.dll, but it's
        there to use if one wants (and I assume the OP wanted this, as he used the
        name of the method in VB which does the same thing).

        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m

        "Peter Duniho" <NpOeStPeAdM@Nn OwSlPiAnMk.comw rote in message
        news:13cm5oriib adme8@corp.supe rnews.com...
        Andrus wrote:
        >I need WinForms function which displays promp and asks single field from
        >user, like
        >>
        >string res = Util.InputBox( "Enter value" );
        >>
        >How to implement this ?
        >
        Make a form with a Label instance for the prompt ("Enter value") and a
        TextBox instance for the user input, a button for "OK" and optionally a
        "Cancel" button. Make sure the buttons are configured for the correct
        DialogResult (set their DialogResult property as desired).
        >
        Instantiate the form, call ShowDialog() on it, if the return value is
        DialogResult.OK , process the Text property of the TextBox instance as your
        entered value.
        >
        Wrap all of the above in a method that does all of the work and simply
        returns the string value obtained from the Text property of the TextBox.
        Don't forget to dispose your form instance before returning.
        >
        Pete

        Comment

        • DK

          #5
          Re: InputBox function

          I wrote an article on how to create an inputbox in C#...it's pretty simple.






          "Andrus" <kobruleht2@hot .eewrote in message
          news:uqxrj7A5HH A.4676@TK2MSFTN GP05.phx.gbl...
          >I need WinForms function which displays promp and asks single field from
          >user, like
          >
          string res = Util.InputBox( "Enter value" );
          >
          How to implement this ?
          >
          >
          Andrus.
          >

          Comment

          • Eric Moreau

            #6
            Re: InputBox function

            see http://www.knowdotnet.com/articles/inputbox.html


            --


            HTH

            Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
            Conseiller Principal / Senior Consultant
            Moer inc. (http://www.emoreau.com)
            Membre du réseau .NET Expertise www.dotnet-expertise.com


            "Andrus" <kobruleht2@hot .eewrote in message
            news:uqxrj7A5HH A.4676@TK2MSFTN GP05.phx.gbl...
            >I need WinForms function which displays promp and asks single field from
            >user, like
            >
            string res = Util.InputBox( "Enter value" );
            >
            How to implement this ?
            >
            >
            Andrus.
            >

            Comment

            • Andrus

              #7
              Re: InputBox function

              Why you re-invented wheel !?

              Isn't it simpler to use

              string res = Interaction.Inp utBox("prompt", "caption", "defaultrespons e",

              0, 0);



              from VisualBasic.dll as Nicolas recommends?

              Andrus.



              "DK" <bushido101@hot mail.comkirjuta s sõnumis
              news:%23XYoaFC5 HHA.1208@TK2MSF TNGP03.phx.gbl. ..
              >I wrote an article on how to create an inputbox in C#...it's pretty simple.
              >

              >
              >
              >
              >
              "Andrus" <kobruleht2@hot .eewrote in message
              news:uqxrj7A5HH A.4676@TK2MSFTN GP05.phx.gbl...
              >>I need WinForms function which displays promp and asks single field from
              >>user, like
              >>
              >string res = Util.InputBox( "Enter value" );
              >>
              >How to implement this ?
              >>
              >>
              >Andrus.
              >>
              >

              Comment

              • Andrus

                #8
                Re: InputBox function

                Thank you.
                I plan to use MS ReportViewer which loads VisualBasics.dl l anyway, so no
                difference.

                I tried

                Interaction.Inp utBox("prompt", "caption", "defaultrespons e", 0, 0);

                but window appears in the left upper corner.

                How to force window to be centered in screen ?

                Andrus.

                "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omkirjutas
                sõnumis news:eorw$SB5HH A.5360@TK2MSFTN GP03.phx.gbl...
                Or, one could set a reference to Microsoft.Visua lBasic.dll assembly and
                call the InputBox method on the Interaction class in the
                Microsoft.Visua lBasic namespace.
                >
                Some don't like the idea of loading Microsoft.Visua lBasic.dll, but it's
                there to use if one wants (and I assume the OP wanted this, as he used the
                name of the method in VB which does the same thing).
                >
                --
                - Nicholas Paldino [.NET/C# MVP]
                - mvp@spam.guard. caspershouse.co m
                >
                "Peter Duniho" <NpOeStPeAdM@Nn OwSlPiAnMk.comw rote in message
                news:13cm5oriib adme8@corp.supe rnews.com...
                >Andrus wrote:
                >>I need WinForms function which displays promp and asks single field from
                >>user, like
                >>>
                >>string res = Util.InputBox( "Enter value" );
                >>>
                >>How to implement this ?
                >>
                >Make a form with a Label instance for the prompt ("Enter value") and a
                >TextBox instance for the user input, a button for "OK" and optionally a
                >"Cancel" button. Make sure the buttons are configured for the correct
                >DialogResult (set their DialogResult property as desired).
                >>
                >Instantiate the form, call ShowDialog() on it, if the return value is
                >DialogResult.O K, process the Text property of the TextBox instance as
                >your entered value.
                >>
                >Wrap all of the above in a method that does all of the work and simply
                >returns the string value obtained from the Text property of the TextBox.
                >Don't forget to dispose your form instance before returning.
                >>
                >Pete
                >
                >

                Comment

                • Nicholas Paldino [.NET/C# MVP]

                  #9
                  Re: InputBox function

                  Andrus,

                  Well, you are specifying the top left of the screen using 0 and 0 for
                  the x and y parameters. Use -1, and it should center the input box.


                  --
                  - Nicholas Paldino [.NET/C# MVP]
                  - mvp@spam.guard. caspershouse.co m

                  "Andrus" <kobruleht2@hot .eewrote in message
                  news:u6HDLAN5HH A.4964@TK2MSFTN GP06.phx.gbl...
                  Thank you.
                  I plan to use MS ReportViewer which loads VisualBasics.dl l anyway, so no
                  difference.
                  >
                  I tried
                  >
                  Interaction.Inp utBox("prompt", "caption", "defaultrespons e", 0, 0);
                  >
                  but window appears in the left upper corner.
                  >
                  How to force window to be centered in screen ?
                  >
                  Andrus.
                  >
                  "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om>
                  kirjutas sõnumis news:eorw$SB5HH A.5360@TK2MSFTN GP03.phx.gbl...
                  > Or, one could set a reference to Microsoft.Visua lBasic.dll assembly
                  >and call the InputBox method on the Interaction class in the
                  >Microsoft.Visu alBasic namespace.
                  >>
                  > Some don't like the idea of loading Microsoft.Visua lBasic.dll, but
                  >it's there to use if one wants (and I assume the OP wanted this, as he
                  >used the name of the method in VB which does the same thing).
                  >>
                  >--
                  > - Nicholas Paldino [.NET/C# MVP]
                  > - mvp@spam.guard. caspershouse.co m
                  >>
                  >"Peter Duniho" <NpOeStPeAdM@Nn OwSlPiAnMk.comw rote in message
                  >news:13cm5orii badme8@corp.sup ernews.com...
                  >>Andrus wrote:
                  >>>I need WinForms function which displays promp and asks single field
                  >>>from user, like
                  >>>>
                  >>>string res = Util.InputBox( "Enter value" );
                  >>>>
                  >>>How to implement this ?
                  >>>
                  >>Make a form with a Label instance for the prompt ("Enter value") and a
                  >>TextBox instance for the user input, a button for "OK" and optionally a
                  >>"Cancel" button. Make sure the buttons are configured for the correct
                  >>DialogResul t (set their DialogResult property as desired).
                  >>>
                  >>Instantiate the form, call ShowDialog() on it, if the return value is
                  >>DialogResult. OK, process the Text property of the TextBox instance as
                  >>your entered value.
                  >>>
                  >>Wrap all of the above in a method that does all of the work and simply
                  >>returns the string value obtained from the Text property of the TextBox.
                  >>Don't forget to dispose your form instance before returning.
                  >>>
                  >>Pete
                  >>
                  >>
                  >
                  >

                  Comment

                  Working...