Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

msgbox VB.NET - set position screen centre

Posted on 2010-08-25
6
Medium Priority
?
3,021 Views
Last Modified: 2012-05-10
Hi, how to set msgbox position at screen centre or form ... in VB.NET? I have to use msgbox and not messagebox (due to VB6 conversion project). Does it work with messagebox?

In dual screen or large resolution ... the msgbox goes crazy. Any code sample and help is much appreciated. Cheers.

0
Comment
Question by:tjoseph833
[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
6 Comments
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 532 total points
ID: 33519815
Here is a complete code how to center "messaageBox"...
I am trying to find out about MsgBox
http://www.freevbcode.com/ShowCode.asp?ID=952
0
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 532 total points
ID: 33519820
Another Option is make you "Own" MessageBox Creating a new Form and Open it as ShowDialog whenever you want
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 268 total points
ID: 33519888
if you want to build your own messagebox, chech http://www.emoreau.com/Entries/Articles/2006/01/A-custom-MessageBox.aspx
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 400 total points
ID: 33520625
this is what you do.

1. add the following declarations:

Private Const MSG_BOX_TITLE As String = "MsgBoxTitle"

    Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

    Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" _
    (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer

    <DllImport("user32.dll")> _
    Public Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Public Function FindWindow( _
     ByVal lpClassName As String, _
     ByVal lpWindowName As String) As IntPtr
    End Function


2. add the following handler:

 Sub BackgroundProcess()
        Dim h As IntPtr = Nothing
        Dim rct As RECT
        Dim res As Int32 = 0
        While (res <> 1)
            h = FindWindow(Nothing, MSG_BOX_TITLE )
            res = GetWindowRect(h, rct)
        End While

        Dim x As Int32 = (Screen.PrimaryScreen.Bounds.Width - (rct.Right - rct.Left)) / 2
        Dim y As Int32 = (Screen.PrimaryScreen.Bounds.Height - (rct.Bottom - rct.Top)) / 2

        MoveWindow(h, x, y, rct.Right - rct.Left, rct.Bottom - rct.Top, True)
    End Sub

3. just before calling you MsgBox line, add the following:

  Dim t As Thread = New Thread(AddressOf BackgroundProcess)
        t.Start()

        Microsoft.VisualBasic.MsgBox("MsgBox Body...", MsgBoxStyle.ApplicationModal, MSG_BOX_TITLE )

and that's it.

the thread will wait till your msg box is display and then it will move it with a blink of an eye to the center of the screen.
0
 

Author Comment

by:tjoseph833
ID: 33702627
thanks everyone ...
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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
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…

609 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