Resolved Non-Modal form not showing ?

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
Here's something that caused me to lose hours of coding time while head scratching & fist pounding, and although I've found the culprit, I still don't know WHY it is an issue. After making a massive jump from VS2008 to VS2019 Community, I ran into this issue that didn't exist in previous versions of VS.
■ Start with Form1 (800px by 500px), with any number of labels or other clutter, something to define it's existence as a BASE form. Include on this form a Button1 with Text = "Help".
■ Create a 2nd form (Shade1) with no FormBorderStyle and a BackColor of Black.
■ Create a 3rd form (Help1) with no FormBorderStyle and a BackColor of Lime Green. Set the transparency color of this form to Lime Green an include a label (White BackColor) that reads "This is Help Page copy".
■ Create a 4th form (HelpSupport) (much smaller, maybe 200 x 200) with a label that reads "This is a form that supports the Help Page". Include some labels or whatever to define it's purpose.
■ Copy this code to Form1:
VB.NET:
Public Class Form1

    Dim Shade1 As New Shade

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Shade1.Owner = Me
        Shade1.Opacity = 0.55
        Shade1.Size = Me.ClientSize
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Shade1.Location = Me.PointToScreen(New Point(0, 0))
        Shade1.Show()

        Dim Help01 As New Help1
        Help01.Size = Me.ClientSize
        Help01.Location = Me.PointToScreen(New Point(0, 0))
        Help01.Owner = Shade1
        Help01.Show()
        Application.DoEvents()

        Dim Curpos As Point
        Curpos = Me.PointToScreen(New Point(100, 100))
        Pause(Curpos, 1200)

        Dim HS As New HelpSupport
        HS.Location = Me.PointToScreen(New Point(200, 200))
        HS.Owner = Shade1
        HS.Show()

    End Sub

    Private Sub Pause(ByVal p As Point, ByVal tm As Integer)

        Dim t1 As Date
        Dim t2 As Date

        t1 = Now.AddMilliseconds(tm)

        Do
            '  If p <> Nothing Then Windows.Forms.Cursor.Position = p
            t2 = Now
        Loop While t2 < t1

    End Sub

End Class

When the program is running, click the Help Button and you'll see Shade1 shade out the base form and the Help page will come up on top of that. In a second or so, the HelpSupport form that supports the Help page will show also.
Now, Uncomment the line in the "Pause" sub that reads "If p <> Nothing Then Windows.Forms.Cursor.Position = p" and run again.
Pretty much 100% of the time, the HelpSupport form will never show.
Can anyone explain why ?
 
Last edited:
Get rid of that Pause method, it is blocking the UI thread, and use Await Task.Delay(1200) instead and mark the calling method with Async modifier.
Pretty much 100% of the time, the HelpSupport form will never show.
It always showed when I tested this.
 
Yep
 
After building the app and running directly from the .exe it seems to work. Maybe I need to reinstall VS2019 to get the IDE working correctly. Thanks for taking the time, John.
 
Back
Top