Solved

showDialog not working for me

Posted on 2006-11-26
5
465 Views
Last Modified: 2008-01-09
Using .NET 1.1, Windows Forms

i I have a .NET dll that I call from a PowerBuilder application. The .NET dll opens a windows form. Unless the user explicitly closes the windows form, I don't want them to be able to click out of it. In other words, the form should remain the top most form until it is explicitly closed. I tried form.ShowDialog() but it doesn't work because I can still click on the Powerbuilder window behind the windows form. Any ideas on how I can prevent the form from losing focus unless it is explicity closed?

Thanks

San
0
Comment
Question by:Sanmarie
5 Comments
 
LVL 39

Expert Comment

by:appari
ID: 18016356
add the following in to a module

 Private Const SWP_NOMOVE = 2
    Private Const SWP_NOSIZE = 1
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

    Private Declare Auto Function SetWindowPos Lib "user32" _
          (ByVal hWnd As IntPtr, _
          ByVal hWndInsertAfter As Long, _
          ByVal x As Long, _
          ByVal y As Long, _
          ByVal cx As Long, _
          ByVal cy As Long, _
          ByVal wFlags As Long) As Long


    Public Function SetTopMostWindow(ByVal hWnd As IntPtr, ByVal Topmost As Boolean) As Long
        ' Function sets a window as always on top, or turns this off

        Try

            If Topmost = True Then 'Make the window topmost
                SetTopMostWindow = SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
            Else
                SetTopMostWindow = SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
                SetTopMostWindow = False
            End If
        Catch ex As Exception
            Throw
        End Try

    End Function


and call it from form load event to set the form as always on top window

SetTopMostWindow me.handle, true
0
 
LVL 18

Assisted Solution

by:Ravi Singh
Ravi Singh earned 100 total points
ID: 18016443
Windows forms in .NET have a TopMost property:

form.TopMost = True
form.Show()
0
 
LVL 39

Assisted Solution

by:appari
appari earned 100 total points
ID: 18016447

or simply set

Me.TopMost = True

in formload event
0
 
LVL 5

Accepted Solution

by:
sivachirravuri earned 300 total points
ID: 18017234
Private Sub frm_LocationChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.LocationChanged
Me.CenterToScreen()
Me.TopMost = True
End Sub
0
 

Author Comment

by:Sanmarie
ID: 18020181
Sorry for taking so long to get back to you. The topMost property worked.
However, it did not work 100% in the LocationChanged event. I had to move the form around for it to work. The LostFocus event of the window did the trick

Private Sub form1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LostFocus
        Me.CenterToScreen()
        Me.TopMost = True
    End Sub

Thanks

San

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now