472,353 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Locate MessageBox over Window


One option of the messagebox object indicates it can be placed over a
selected window rather than just appearing centered on the desktop. The
function is "Overloads Public Shared Function Show(IWin32Window, String) As
DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToString()
rtn = MessageBox.Show(winhandle, "My message")
\\\

Unfortunately the winhandle becomes the content with the My message as the
title and the box in the center of the desktop, not over form1.
Appreciate some help.

Ed
Nov 21 '05 #1
10 8188
"Ed Bitzer" <ed******@yahoo.com> schrieb:
One option of the messagebox object indicates it can be placed over a
selected window rather than just appearing centered on the desktop.


You can position a messagebox window by using a hook. A VB6 sample which
can be converted to VB.NET can be found here:

<URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eB**************@TK2MSFTNGP15.phx.gbl...
You can position a messagebox window by using a hook. A VB6 sample which
can be converted to VB.NET can be found here:

<URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>


Herfried,
I do thank you but converting that code is over my head. The vb.net
messagebox object appears to have the capability and simply executed but I
do not understand the window identification syntax.

Ed
Nov 21 '05 #3
The 'owner' parameter to the MessageBox.Show() method is of type
IWin32Window. It does not represent a window handle, rather it represents a
window. so in your case it should be: rtn = MessageBox.Show(Me, "My
message").

The bigger point to understand when you read the documentation is that "You
can use the owner parameter to specify a particular object, which implements
the IWin32Window interface, to place the message box in front of.". Note the
use of the phrase 'in front of'. This means the position of the dialog in
the z-order, not the location of the dialog on the screen.

I have never understood how this parameter is useful. Because the dialog is
modal to the application, I can't see any point in displaying the dialog in
front of a window that might be behind the current window. One would have to
move the current window to see it but the dialog is modal so you can't.
"Ed Bitzer" <ed******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

One option of the messagebox object indicates it can be placed over a
selected window rather than just appearing centered on the desktop. The
function is "Overloads Public Shared Function Show(IWin32Window, String)
As DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToString()
rtn = MessageBox.Show(winhandle, "My message")
\\\

Unfortunately the winhandle becomes the content with the My message as the
title and the box in the center of the desktop, not over form1.
Appreciate some help.

Ed

Nov 21 '05 #4
Ed,

"Ed Bitzer" <ed******@yahoo.com> schrieb:
You can position a messagebox window by using a hook. A VB6 sample which
can be converted to VB.NET can be found here:

<URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>


I do thank you but converting that code is over my head. The vb.net
messagebox object appears to have the capability and simply executed but I
do not understand the window identification syntax.


The .NET messagebox doesn't have this capability out of the box (although
you can specify an owner window). I doubt that it's worth the effort to
center a messagebox.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
Stephany,

I certainly misunderstood - as you suspected I was not thinking about the
z-order but the placement of the messagebox relative to my form. My program
has a relatively small window and I found the message box voicing a
confirmation could be "far away." When I saw this option I jumped, but then
stumbled with my lack of knowledge of IWin32Window interface. So the
alternate solution (besides leaning a bit more, and at 72 I am getting a bit
old for that) is to create my own form and control its position relative to
the form opening it.

Ed
"Stephany Young" <noone@localhost> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
The 'owner' parameter to the MessageBox.Show() method is of type
IWin32Window. It does not represent a window handle, rather it represents
a window. so in your case it should be: rtn = MessageBox.Show(Me, "My
message").

The bigger point to understand when you read the documentation is that
"You can use the owner parameter to specify a particular object, which
implements the IWin32Window interface, to place the message box in front
of.". Note the use of the phrase 'in front of'. This means the position of
the dialog in the z-order, not the location of the dialog on the screen.

I have never understood how this parameter is useful. Because the dialog
is modal to the application, I can't see any point in displaying the
dialog in front of a window that might be behind the current window. One
would have to move the current window to see it but the dialog is modal so
you can't.
"Ed Bitzer" <ed******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

One option of the messagebox object indicates it can be placed over a
selected window rather than just appearing centered on the desktop. The
function is "Overloads Public Shared Function Show(IWin32Window, String)
As DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToString()
rtn = MessageBox.Show(winhandle, "My message")
\\\

Unfortunately the winhandle becomes the content with the My message as
the title and the box in the center of the desktop, not over form1.
Appreciate some help.

Ed


Nov 21 '05 #6
Herfried ,
Stephany caught my misunderstanding and I do thank you for trying to
help. Have got to lean how to convert old API's so will study the code you
offered.

Ed
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ed,

"Ed Bitzer" <ed******@yahoo.com> schrieb:
You can position a messagebox window by using a hook. A VB6 sample
which can be converted to VB.NET can be found here:

<URL:http://dotnet.mvps.org/vb/samples/misc/DialogPosition.zip>


I do thank you but converting that code is over my head. The vb.net
messagebox object appears to have the capability and simply executed but
I do not understand the window identification syntax.


The .NET messagebox doesn't have this capability out of the box (although
you can specify an owner window). I doubt that it's worth the effort to
center a messagebox.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
Cor,

Of course there might actually be some reason to stop checking newer
solutions at my age - times running out<g>. However I admit I have not even
looked how VB.Net handles and will do so. The INI file has always made it
so easy to examine and modify content with any ASCII editor. Not having to
search through the Registry to detect my errors did seem simpler.

Ed

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Ed,
I still like ini files better.

Be cautious, this kind of behaviour can show that your age stops you to
check newer solutions. Did you try the registry with VBNet. It is so easy
to use.

Cor

Nov 21 '05 #8
Ed,

A piece of code to save your Form settings

\\\
Imports Microsoft.Win32
Public Class RegistryEd
Private Shared pFormWidth As Integer
Private Shared pFormHeight As Integer
Private Shared pFormX As Integer
Private Shared pFormY As Integer
Private Shared pWindowState As Integer
Private Shared Reg As RegistryKey = Registry.CurrentUser
Public Shared Property FormWidth() As Integer
Get
Return pFormWidth
End Get
Set(ByVal Value As Integer)
pFormWidth = Value
End Set
End Property
Public Shared Property FormHeight() As Integer
Get
Return pFormHeight
End Get
Set(ByVal Value As Integer)
pFormHeight = Value
End Set
End Property
Public Shared Property FormX() As Integer
Get
Return pFormX
End Get
Set(ByVal Value As Integer)
pFormX = Value
End Set
End Property
Public Shared Property FormY() As Integer
Get
Return pFormY
End Get
Set(ByVal Value As Integer)
pFormY = Value
End Set
End Property
Public Shared Property WindowState() As Integer
Get
Return pWindowState
End Get
Set(ByVal Value As Integer)
pWindowState = Value
End Set
End Property
Public Shared Sub Load()
Reg = Registry.CurrentUser.CreateSubKey("Software\Cor\Ed Sample")
pFormWidth = CInt(Reg.GetValue("Width", 700))
pFormHeight = CInt(Reg.GetValue("Height", 400))
pFormX = CInt(Reg.GetValue("X", 100))
pFormY = CInt(Reg.GetValue("Y", 100))
pWindowState = CInt(Reg.GetValue("WindowState", 0))
End Sub
Public Shared Sub Save()
Dim Reg As RegistryKey
Reg = Registry.CurrentUser.CreateSubKey("Software\Cors\E dSample")
Reg.SetValue("Width", pFormWidth)
Reg.SetValue("Height", pFormHeight)
Reg.SetValue("X", pFormX)
Reg.SetValue("Y", pFormY)
End Sub
End Class
///

I hope this gives a QuickStart

Cor
Nov 21 '05 #9
Ed,

I changed some words and deleted as well some parts, where is Cors it should
be Cor or visa versa. Maybe there are more errors because of that change.

:-)

Cor
Nov 21 '05 #10
Cor,

I do thank you -- you took all the work out of this project. Have an
example working already.

Ed
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ed,

I changed some words and deleted as well some parts, where is Cors it
should be Cor or visa versa. Maybe there are more errors because of that
change.

:-)

Cor

Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steven Malcolm | last post by:
Hello there Is it possible to close a window without the messagebox coming up asking if you really want to close the window? Steven
0
by: Dan | last post by:
How can I make the MessageBox window appear centered with respect to its parent? Even when I specify this as the MessageBox owner...
8
by: Dennis C. Drumm | last post by:
I have ordered the book .NET Framework Solutions, In Search of the Lost Win32 API by John Paul Meuller which I think will help answer some of my...
2
by: selen | last post by:
hello how I can use messagebox as windows application in web application . Thanks
3
by: Carl Fenley | last post by:
I am trying to capture the Windows QueryCancelAutoPlay message that is sent to the "foreground window" when an AutoRun enabled CD is inserted into a...
3
by: Jason | last post by:
Hi, I built a vb.Net application that creates ICS calendar files dynamically and then sends them to the client browser as a downloadable file....
3
by: Tim Hunter | last post by:
Hi, I am running WinXP Pro with Access 2003. I would like to have a window or an Alert Message that displays and stops processing without...
2
by: Prats | last post by:
MessageBox::Show(Window, String) How do I pass the value for the Window parameter, rather how do I get the value for the active window ...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.