Solved

showDialog not working for me

Posted on 2006-11-26
5
464 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

13 Experts available now in Live!

Get 1:1 Help Now