How to hide form when it lost focus

Mansour_Dalir 1,716 Reputation points
2023-05-29T18:17:00.65+00:00

Hello

Form2 appears when I click the button.

Now I want to hide form2 by clicking anywhere on screen windows.

At the same time, I clicked on form2, it should not be hidden. Thank

tags: vb.net vs2019

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,655 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 28,781 Reputation points Microsoft Vendor
    2023-05-30T01:27:08.7833333+00:00

    Hi @Mansour_Dalir ,

    You can hide Form2 by adding code to Form2's Deactivate event.

    So when you click outside of Form2 and Form2 loses focus, the Deactivate event of Form2 is triggered, hiding Form2.

        Private Sub Form2_Deactivate(sender As Object, e As EventArgs) Handles MyBase.Deactivate
            Me.Hide()
        End Sub
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful