CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 1999
    Posts
    84

    Resizing MDI Child form--Urgent

    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

  2. #2
    Join Date
    May 2001
    Location
    Russia
    Posts
    200

    Re: Resizing MDI Child form--Urgent


    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




    Andy Tower

  3. #3
    Join Date
    Jul 1999
    Posts
    84

    Re: Resizing MDI Child form--Urgent

    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

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Resizing MDI Child form--Urgent

    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...s/ShowCode.htm

    John G

  5. #5
    Join Date
    Jul 1999
    Posts
    84

    Re: Resizing MDI Child form--Urgent

    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

  6. #6
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Resizing MDI Child form--Urgent

    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








Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured