locked
Hold focus on windows form RRS feed

  • Question

  • I'm programming a database programma. 

    Program have a main window with a menu. If they choose one window item then a new form will be open. Now I want that if that form is open they can not go back to the main form until they close the form where they work on. Can someone give me some ide how I can do that.

    Private Sub SIPToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SIPToolStripMenuItem.Click
            SSP_FM.ShowDialog()
        End Sub

    For the moment I use this to open that new form. I want also that I get the focus on this and can't go back until SSP_FM is closed

    thanks for the help

    Tuesday, September 15, 2020 9:19 AM

Answers

  • Hi sgroenen,

    Thank you for posting here.

    In order to prevent the user from making inputs you can set

        mainForm.Enabled = False

    For example:

    Form1(main form):

        Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
            Dim frm2 = New Form2
            frm2.Show()
            Me.Enabled = False
        End Sub

    Form2:

        Private Sub Form2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
            Form1.Enabled = True
        End Sub

    Result of my test:

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Mattia Fanti Wednesday, September 16, 2020 10:06 AM
    • Marked as answer by sgroenen Friday, September 18, 2020 8:45 AM
    Wednesday, September 16, 2020 7:08 AM

All replies

  • Hello,

    Your only option to allow them to get back to the calling form is to call the child form using .Show rather than .ShowDialog. 

    Also when bringing up a new form you should use

    Dim f As New SSP_FM 

    F.Show or F.ShowDialog


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, September 15, 2020 10:16 AM
  • Hi sgroenen,

    Thank you for posting here.

    In order to prevent the user from making inputs you can set

        mainForm.Enabled = False

    For example:

    Form1(main form):

        Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
            Dim frm2 = New Form2
            frm2.Show()
            Me.Enabled = False
        End Sub

    Form2:

        Private Sub Form2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
            Form1.Enabled = True
        End Sub

    Result of my test:

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Mattia Fanti Wednesday, September 16, 2020 10:06 AM
    • Marked as answer by sgroenen Friday, September 18, 2020 8:45 AM
    Wednesday, September 16, 2020 7:08 AM