Click to See Complete Forum and Search --> : Resizing MDI Child form--Urgent


Harini
June 25th, 2001, 02:40 PM
Hello,

I am facing a problem in resizing the form to the specified size.

That is when the form's caption is dbl-clicked for maximizing the form, the form should be resized to a specific height and width, rather than completely being maximized.

Similarly, when the form's caption is dbl-clicked from the above state, the should be resized back to its previous size.

I have tried all the options with the properties, but could not find any solution.

It would be great if some one can help me immediately.


Thanks
Harini

Tower
June 25th, 2001, 07:48 PM
private Sub Form_Resize()
static iWidth as Integer, iHeight as Integer
static iTop as Integer, iLeft as Integer
static bMax as Boolean

If Form1.WindowState = vbMaximized And Not bMax then
bMax = true
Form1.WindowState = vbNormal
Form1.Width = 1000
Form1.Height = 1000
Form1.Top = 0
Form1.Left = 0
ElseIf bMax = true And Form1.WindowState = vbMaximized then
Form1.WindowState = vbNormal
Form1.Width = iWidth
Form1.Height = iHeight
Form1.Top = iTop
Form1.Left = iLeft
bMax = false
ElseIf Not bMax then
iWidth = Form1.Width
iHeight = Form1.Height
iTop = Form1.Top
iLeft = Form1.Left
End If
End Sub

Harini
June 29th, 2001, 09:05 AM
Hello,

With the above code, we are resizing the maximized form to the size that we want, after it is actually maximized. However it leaves some flickering effect on the screen. Is there any way that we can use to directly size the form to the required size when we double click the title bar.

Thanks
Harini

John G Duffy
June 29th, 2001, 09:50 AM
What you ned to do is get rid of the VB Supplied (er Widows Supplied) min and max buttons and replace them with your own. The following URL will point you to a Sample App that adds buttons to the Windows TitleBar
http://www.planet-source-code.com/xq/ASP/txtCodeId.11292/lngWId.1/qx/vb/scripts/ShowCode.htm

John G

Harini
June 29th, 2001, 10:15 AM
Hello John,

I have set the control box property of the form to false, hence I donot have any vb-supplied min, max and closing btns on the screen. Now, the problem is if I dbl-click on the title bar, still the form gets maximized to windows default size. However, we can make the window not to get maximized, when dbl-clicked by making max btn property to false.
But my requirement is that it should be maximized to the size that I specify when dbl-clicked.

Thanks
Harini

shree
June 29th, 2001, 10:58 AM
Then it's easy. Delete the form's caption so that the title bar altogether disappears. Then put a label at the top of the form and make its background color equal to &H80000002&, the active title bar color.
Now you have to make this label work like a title bar:


Dim FormMaximized as Boolean
private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval lParam as Long) as Long
private Declare Function ReleaseCapture Lib "user32" () as Long
private Const WM_NCLBUTTONDOWN = &HA1
private Const HTCAPTION = 2

private Sub Form_Resize()
Label1.Width = Form1.ScaleWidth
End Sub

private Sub Label1_DblClick()
If FormMaximized then
me.Move me.Left, me.Top, 800 * Screen.TwipsPerPixelX, 600 * Screen.TwipsPerPixelY
else
me.Move me.Left, me.Top, 400 * Screen.TwipsPerPixelX, 300 * Screen.TwipsPerPixelY
End If
FormMaximized = Not FormMaximized
End Sub

private Sub Label1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
If Button = vbLeftButton then
ReleaseCapture
Call SendMessage(me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub