Solved

showDialog not working for me

Posted on 2006-11-26
5
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

687 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