How to disable the parent form when a child form is active?

前端 未结 13 2218
闹比i
闹比i 2020-12-12 23:26

How to disable a parent form when child form is active using c#?

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 23:53

    @Melodia

    Sorry for this is not C# code but this is what you would want, besides translating this should be easy.

    FORM1

    Private Sub Form1_MouseEnter(sender As Object, e As EventArgs) Handles MyBase.MouseEnter
        Me.Focus()
        Me.Enabled = True
        Form2.Enabled = False
    End Sub
    
    Private Sub Form1_MouseLeave(sender As Object, e As EventArgs) Handles MyBase.MouseLeave
        Form2.Enabled = True
        Form2.Focus()
    End Sub
    

    FORM2

    Private Sub Form2_MouseEnter(sender As Object, e As EventArgs) Handles MyBase.MouseEnter
        Me.Focus()
        Me.Enabled = True
        Form1.Enabled = False
    End Sub
    
    Private Sub Form2_MouseLeave(sender As Object, e As EventArgs) Handles MyBase.MouseLeave
        Form1.Enabled = True
        Form1.Focus()
    End Sub
    

    Hope this helps

提交回复
热议问题