CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Location
    Belgium (Country in Europe)
    Posts
    44

    Inputbox and Form together?

    Hi all,

    I'm having some trouble (again).
    At the moment I'm trying to create and use a simple inputbox. (Like the one in Visual Basic)

    I just created a simple Inputbox (=Windows Form) with a label, a button and a textbox.

    In the eventhandler of the button I copy the content of the textbox to a global variable. And then I close the form using:

    Code:
    close();
    Now I want to use the inputbox in another form.
    So in "Form1" I'd like to call my inputbox. So I did this inside a public function of Form1:

    Code:
    inputbox window; // Create an Inputbox window
    
    window.Show(); // Show it. => The window shows
    window.focus(); // Change focus

    But the problem is that the window (Inputbox) never gets focus and my "Form1" just keeps executing the lines after window.focus().

    --> Is it possible to shift focus from my main program to the inputbox and when the inputbox closes (When I press the OKbutton on the inputbox), my main program will continue running.

    So what I want is this in pseudo code:
    - Open an inputbox where the user can enter text.
    - Pause main program.
    - User enters text in inputbox
    - User presses OK button in inputbox
    - Inputbox will validate input
    - if the input is numerical => Save the input in a global variable and Close the inputbox
    - When the inputbox closes, my mainprogram should continue running.

    Is this possible? If so, how?

    Any help will be appreciated.

    Greetz,
    Dave

    PS: The inputbox does not need to return a value. It just needs to get focus.

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Inputbox and Form together?

    There are two types of windows: modal and modeless. A modal dialog takes the focus, and you cannot access the parent, until you close it. This you open with ShowDialog(). A modeless dialog does not retain the top of the Z order, and you can access its parent, without closing it first. This you open with Show().

    As far as I understand you should use ShowDialog() instead of Show().

    BTW, C++ and C++/CLI and C# are case sensitive.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Inputbox and Form together?

    [ redirected ]
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jun 2009
    Location
    Belgium (Country in Europe)
    Posts
    44

    Thumbs up Re: Inputbox and Form together?

    Quote Originally Posted by cilu View Post
    [ redirected ]
    Sorry for that .

    There are two types of windows: modal and modeless. A modal dialog takes the focus, and you cannot access the parent, until you close it. This you open with ShowDialog(). A modeless dialog does not retain the top of the Z order, and you can access its parent, without closing it first. This you open with Show().

    As far as I understand you should use ShowDialog() instead of Show().

    BTW, C++ and C++/CLI and C# are case sensitive.
    Many thanks . ShowDialog() solved this issue.

    Greetz,
    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured