Solved

Center another applications window using it's handle VB.NET

Posted on 2013-12-19
2
364 Views
Last Modified: 2013-12-27
Hi experts...
Is there a way that I can center another applications child window using that windows handle?

Here's what I have written so far but not sure where to go from here:

 
Private Sub CenterWindow(ByVal intHandle As Long)
        Dim iScreenHeight As Long
        Dim iScreenWidth As Long
        '##  PROVIDES SCREEN SIZE IN PIXELS
        iScreenWidth = Screen.PrimaryScreen.WorkingArea.Width
        iScreenHeight = Screen.PrimaryScreen.WorkingArea.Height


        Dim iFormHeight As Long
        Dim iFormWidth As Long

        Dim myRect As RECT
        If GetWindowRect(intHandle, myRect) > 0 Then
            If (myRect.Right - myRect.Left < My.Computer.Screen.WorkingArea.Width) Or (myRect.Bottom - myRect.Top < My.Computer.Screen.WorkingArea.Height) Then
                iFormHeight = myRect.Left
                iFormWidth = myRect.Top

            End If

        End If
        

        '## Next, we need to find the x/y location of the upper right hand corner

        Dim iTopLoc As Long
        Dim iLeftLoc As Long

        iLeftLoc = iFormWidth / 2
        iTopLoc = iFormHeight / 2


    End Sub

Open in new window

0
Comment
Question by:romiebehunin
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39731543
0
 

Author Closing Comment

by:romiebehunin
ID: 39742031
Works like a charm thanks guys
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to picture file 3 40
Round a string to two digits 12 24
Round up to 100% in .NET 10 43
Calling stored proc in EDMX 11 18
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

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

17 Experts available now in Live!

Get 1:1 Help Now