CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2004
    Posts
    391

    prevent move or resizing of MDI child

    Hi,

    I have an MDI application and I don't want the user to move or resize any of the child forms, i'e they need to have fixed size and location.

    I put fals eon contorl box, but they still can move and resize.

    Now i put some code in resize and move event sto prevent this successfully, but it's not elegent. There's lot of flickering when user has the mouse down and is attempting to move or resize.

    Is there soem nicer way to accomplish this, which won't look shabby like with all the flickering.

  2. #2
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: prevent move or resizing of MDI child

    to make the child unresizable change
    formBorderSize = fixedToolWindow
    minimizeBox = false
    maximizeBox = false

    to make the form imMoveable get this SystemMenuManager class
    add code to form load
    Code:
     Dim myMenuManager As New SystemMenuManager(Me, False, SystemMenuManager.MenuItemState.Greyed)
    hope u got it

  3. #3
    Join Date
    Aug 2004
    Posts
    391

    Re: prevent move or resizing of MDI child

    Thanks for you reply.
    The sizing probblem is fixed. But the moving isn't by using your exmaple.

    What I want is when someone click ont eh caption(title) bar of the form ( the control box is set to false ) and try to move form by dragging it , he should not be able to do so.

    what i did was:

    Private Sub CForm_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
    If Not mMove Then Me.Location = mRect.Location
    End Sub

    where mRect has been initiliazed to an area. This works but it produce the flickering effect.

    i tried you way by using that lien of code, but that dosn't stop em from draggin the form in MDI client area to where i want to

    Thanks again fot the reply

  4. #4
    Join Date
    Aug 2004
    Posts
    391

    Re: prevent move or resizing of MDI child

    One additional question. Is there a way to get rid of the title bar altogether, so that all i have in a form is the client area

  5. #5
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: prevent move or resizing of MDI child

    set the form text property empty and controlBox property to false ,u will have only the client area.

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: prevent move or resizing of MDI child

    Quote Originally Posted by venAdder
    what i did was:

    Private Sub CForm_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LocationChanged
    If Not mMove Then Me.Location = mRect.Location
    End Sub

    where mRect has been initiliazed to an area. This works but it produce the flickering effect.
    Just for interest sake.. I had a similar problem in moving forms, what I managed to do was use this code to remove the flickering.
    Code:
    'Declarations
    
        'constants to move form
        Private Const WM_NCHITTEST As Integer = &H84
        Private Const HTCLIENT As Integer = &H1
        Private Const HTCAPTION As Integer = &H2
    
        'move form
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Select Case m.Msg
                Case WM_NCHITTEST 'to drag
                    MyBase.WndProc(m)
                    If (m.Result.ToInt32 = HTCLIENT) Then 'client
                        m.Result = IntPtr.op_Explicit(HTCAPTION) 'name of window
                    End If
                    Exit Sub
            End Select
    
            MyBase.WndProc(m)
    
        End Sub
    I know you're looking for a way to prvent people from moving the form, but since you mentioned the flickering effect, I thought to post this to prevent the flickering event.

  7. #7
    Join Date
    Mar 2006
    Posts
    23

    Re: prevent move or resizing of MDI child

    Quote Originally Posted by venAdder
    One additional question. Is there a way to get rid of the title bar altogether, so that all i have in a form is the client area
    Wouldnt you simply set the "FormBorderStyle" in the Properties window to "None" That will give you a smooth (no border at all) finish.

  8. #8
    Join Date
    Jan 2006
    Posts
    293

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