Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Resizing Problem 2

Status
Not open for further replies.

CenturioN101

Programmer
Jan 24, 2001
8
GB
Hi everyone,

Sorry to trouble lot again with the same problem. But I still need to know how to make objects resize with the window. Also to make Buttons move with the window ie. make the button move with the window when it is resized and make it stay in the top right corner of the form no matter how much it is resized. I would also like to make the from have a max resize and a min resize. Remember I need code and/or help (explanation) for me to learn and not having to keep pestering you lot. I need it for VB 6. That's Visual Basic 6. NOT VB5!

Thnx for you time and patience,

Brent Newbury

ps. Please try and not make it have any moduals or msflexi grid (or whatever it's called). If it does HAVE to have it then I'll just have to like it won't I. And again thnx for you time folks.
 
[tt]
Private Sub Form_Resize

if Me.Windowstate = vbminimized then
[tab]Exit Sub
End If
if Me.width < MINIMUM_WIDTH then
[tab]Me.width = MINIMUM_WIDTH
[tab]Exit Sub
End If
if Me.Height < MINIMUM_HEIGHT then
[tab]Me.Height = MINIMUM_HEIGHT
[tab]Exit Sub
End If

' Relocate OK button to top-right
cmdOK.move me.scalewidth - cmdOK.width, 0

' Relocate Cancel button underneath OK button plus a small gap
cmdCancel.move me.scalewidth - cmdCancel.width, cmdOK.height + 60

End Sub
[/tt]

The difference between Width and ScaleWidth properties is that ScaleWidth is the interior of the form, and Width includes the window's borders. When checking for the minimum size, you want to use the Width property since you can't change the size by assigning to the ScaleWidth property.

Hope this helps.

Chip H.
 
Thnx alot Chip,

That works quite well, and you've done EXACTLY what I wanted. You helped me understand whats goin' off with the code. But, (sorry to spring it on you again) how do I make those buttons reletive to the height of the form NOT just the width? Please could you do the same thing as you've done with the last script.

Thnx for your time,

Brent Newbury
 
It's pretty easy, just change the properties used from those in the &quot;width&quot; family to those in the &quot;height&quot; family. And reverse the order in the Move method so you're affecting the Y coordinate, not the X coordinate.

It helps to understand the coordinate system Microsoft uses. Back when Microsoft was working on OS/2, the IBM architects decided that the OS/2 coordinate system would be in Quadrant I (remember your high-school geometry?) since their mainframe GUI system (called GDDM, pronounced how you might expect) used the same thing. This way, all values both X and Y would be positive as they moved further from the origin. Made terrific sense (if you're a scientist). Once Microsoft started working on Windows 1.0, they knew that under OS/2 you had to invert all Y values to properly calculate screen positions -- a real pain. They realized that most people think in terms of a piece of paper -- you start at the top-left and go down and to the right, making paper coordinates exist in Quadrant IV. So when they wrote the graphics part of Windows, all increasing Y values move further down the screen, and X value behave as you expect, with increasing values moving to the right. So to be 100% technically correct, Windows is upside down all the time :)

Now, what all this history means is that the origin (0,0) in Windows is at the upper-left of the screen. Same applies to all the windows, controls, etc. (but not text -- it's a special case). So to position one control underneath another, you add the height of the topmost control to it's Y position, and that becomes the top of the bottommost control. Plus a little more if you want a gap between them.

Got it?

Chip H.
 
Thnx again Chip,

Yes I now know how stupidly easy that was, and what a dunce I am. thnx again, if I have any questions again, just look out for your name as the subject &quot;Chip&quot;. Like I said thnx alot for your time.

Brent Newbury
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top