Solved

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

Posted on 2013-12-19
2
368 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now