开发者

Toggling TopMost in VB.NET

I have a form that has to be on top for a period of time, and then can be set behind other windows normally. Is there anything in addition to setting Me.TopMost to True or False that needs to be done? I ask because it doesn't开发者_StackOverflow社区 seem to be working.


It should present no problem. The following code (C#, sorry for that, no VB.NET environment available where I am right now) sets TopMost to true, waits for 5 seconds and then toggles TopMost back to false.

private void MakeMeTopmostForAWhile()
{
    this.TopMost = true;
    ThreadPool.QueueUserWorkItem(state =>
    {
        Thread.Sleep(5000);
        this.Invoke((Action)delegate { this.TopMost = false; });
    });
}

Note that this does not affect the Z-order of the window immediately; when TopMost is set to false, the window will still be on top of other windows. If the window is on top of another window that is also topmost, it will move so that the other topmost window is not covered, but it will remain on top of other non-topmost windows.

Update
Here is the above code in VB.NET (auto-converted, not tested):

Private Sub MakeMeTopmostForAWhile()
    Me.TopMost = True
    ThreadPool.QueueUserWorkItem(Function(state) Do
        Thread.Sleep(5000)
        Me.Invoke(DirectCast(Function() Do
            Me.TopMost = False
        End Function, Action))
    End Function)
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜