Well, I recently helped someone solve the problem of centering a form on a secondary monitor. At that time, I had the necessary routines, but they weren't cleaned up as much as I'd like. And a couple of you encouraged me to do so. So here they are, all cleaned up.
Also, it's important to make note that, in some ways, these are better than the built-in VB6 properties for doing the same thing. Specifically, if you intend to program for multi-monitor systems, or even for a single monitor system that has its monitor in portrait orientation. VB6 struggles when monitors aren't in the typical landscape orientation.
More specifically, you should abandon all use of Screen.Width, Screen.Height, Screen.TwipsPerPixelX, & Screen.TwipsPerPixelY. Those functions just return bad data in certain situations, and mine don't.
I'll let you peruse the functions available. With very little study, they should start making perfect sense. To use them, just throw them in a standard (BAS) module, and that's it.
The code is right at 15,000 characters (the VBForums limit) so I'll post it in the second post.
To test, you can do something as simple as throw a couple of command buttons on a Form1, and then put this code in the form:
There's much more to it than that, but that'll give you the idea. It's all been thoroughly tested. In fact, the vast majority of it has been in production for many years.
Enjoy,
Elroy
Also, it's important to make note that, in some ways, these are better than the built-in VB6 properties for doing the same thing. Specifically, if you intend to program for multi-monitor systems, or even for a single monitor system that has its monitor in portrait orientation. VB6 struggles when monitors aren't in the typical landscape orientation.
More specifically, you should abandon all use of Screen.Width, Screen.Height, Screen.TwipsPerPixelX, & Screen.TwipsPerPixelY. Those functions just return bad data in certain situations, and mine don't.
I'll let you peruse the functions available. With very little study, they should start making perfect sense. To use them, just throw them in a standard (BAS) module, and that's it.
The code is right at 15,000 characters (the VBForums limit) so I'll post it in the second post.
To test, you can do something as simple as throw a couple of command buttons on a Form1, and then put this code in the form:
Code:
Option Explicit
Private Sub Command1_Click()
CenterWindowOnMonitor Me.hWnd, MonitorHandle(1), True
End Sub
Private Sub Command2_Click()
CenterWindowOnMonitor Me.hWnd, MonitorHandle(2), True
End Sub
Enjoy,
Elroy