Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

showDialog not working for me

Posted on 2006-11-26
5
Medium Priority
?
481 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 400 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 400 total points
ID: 18016447

or simply set

Me.TopMost = True

in formload event
0
 
LVL 5

Accepted Solution

by:
sivachirravuri earned 1200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 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