473,806 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(IWin32Wind ow, String) As
DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToStr ing()
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 8301
"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******** ******@TK2MSFTN GP15.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******** ********@TK2MSF TNGP15.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(IWin32Wind ow, String)
As DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToStr ing()
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@localhos t> wrote in message
news:%2******** *******@TK2MSFT NGP09.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******** ********@TK2MSF TNGP15.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(IWin32Wind ow, String)
As DialogResult"

I have unsuccessfully tried:
///
Dim winhandle as string
Dim rtn as DialogResult
winHandle = Me.Handle.ToStr ing()
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 misunderstandin g 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******** ********@TK2MSF TNGP10.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******** **********@TK2M SFTNGP10.phx.gb l...
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.Curren tUser
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.Curren tUser.CreateSub Key("Software\C or\EdSample")
pFormWidth = CInt(Reg.GetVal ue("Width", 700))
pFormHeight = CInt(Reg.GetVal ue("Height", 400))
pFormX = CInt(Reg.GetVal ue("X", 100))
pFormY = CInt(Reg.GetVal ue("Y", 100))
pWindowState = CInt(Reg.GetVal ue("WindowState ", 0))
End Sub
Public Shared Sub Save()
Dim Reg As RegistryKey
Reg = Registry.Curren tUser.CreateSub Key("Software\C ors\EdSample")
Reg.SetValue("W idth", pFormWidth)
Reg.SetValue("H eight", 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

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

Similar topics

9
2597
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
6140
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 (MessageBox.Show(this, "dummy", etc), this does not affect the starting position of the message box window, which always pops up centered in the desktop. Is there a way to center it onto the owner window? Thanks guys!
8
13113
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 questions I have regarding making custom MessageBoxes, but that isn't going to be here for a few days. So, I thought I would ask you guys how to put one of hte standard MessageBox icons, such as MessageBoxIcon.Exclamation, into my custom MessageBox. Thanks,
2
1632
by: selen | last post by:
hello how I can use messagebox as windows application in web application . Thanks
3
3457
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 drive. Enabling and Disabling AutoRun http://tinyurl.com/2m26 If my MainForm uses MessageBox.Show to prompt the end-user to insert a CD, I'd like to know whether MainForm or my MessageBox is the "foreground window". Any ideas?
3
3080
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. Works perfectly except in the following situation. If the URL link to the web page is mailed to someone and they click on the link in Outlook and there are no web browsers already opened on their system, IE Starts, the open/save Dialog displays and then 1-2 seconds later the IE window closes...
3
2644
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 continuing out of the routine that called it. Like a MessageBox. The MessageBox is not big enough and the font is too small for what I would like. I looked for a way to modify this but i could not find it. I thought making a window "Modal" would accomplich this but it does not. When I am within a...
2
7379
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 Also,there are two forms open at the same time, one overlapping the other. Now if I click the form at behind how do I bring to to front. I tried giving BringToFront() didn't work.
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.