Simonetos Simonetos - 6 months ago 13
Vb.net Question

VB.NET - How to define if an owned form has loaded at the same screen of it's owner form?

I'm working on a project with owner and owned forms. There is any way to define if an owned form has loaded at the same screen of it's owner form? Sorry I didn't came up with a code example but I couldn't find something similar to show!!!

Answer

You can test the Screen object returned from Screen.FromControl(Me)

  Private Sub ScreenTestButton_Click(sender As Object, e As EventArgs) Handles ScreenTestButton.Click
        Try
            Dim thisScreen As Screen = Screen.FromControl(Me)
            If thisScreen.Primary Then
                MessageBox.Show("I'm on the primary screen")
            Else
                MessageBox.Show("I'm not on the primary screen")
            End If

        Catch ex As Exception
            MessageBox.Show(String.Concat("Something went wrong: ", ex.Message))
        End Try
    End Sub
Comments