Results 1 to 9 of 9

Thread: [RESOLVED] Keep borders, prevent relocation of forms

  1. #1

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Resolved [RESOLVED] Keep borders, prevent relocation of forms

    I have a lot of forms that get placed in specific locations at run time. I need to disable relocating these forms, but I would like to keep the borders and titlebar.

    I have tried jmc's codebank submission called "immobilise" but did not work for me, forms were still draggable (could be my mis_use, but no errors were thrown)

    If this isn't doable, is there a way to hide only the titlebar, but maintain the 3D blue borders all around?

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Keep borders, prevent relocation of forms

    The codebank submission should work just fine so you probably did something wrong.

    If you want to hide the titlebar but keep the borders, you need to set the ControlBox property to False and the Text property to an empty string. You can still resize the form this way though, so perhaps you want to set the FormBorderStyle to something that does not allow resizing.

  3. #3
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Keep borders, prevent relocation of forms

    Add this to your forms:

    vb.net Code:
    1. Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    2.         Const WM_NCLBUTTONDOWN As Integer = 161
    3.         Const WM_SYSCOMMAND As Integer = 274
    4.         Const HTCAPTION As Integer = 2
    5.         Const SC_MOVE As Integer = 61456
    6.  
    7.         If (m.Msg = WM_SYSCOMMAND) AndAlso (m.WParam.ToInt32() = SC_MOVE) Then
    8.             Exit Sub
    9.         End If
    10.  
    11.         If (m.Msg = WM_NCLBUTTONDOWN) AndAlso (m.WParam.ToInt32() = HTCAPTION) Then
    12.             Exit Sub
    13.         End If
    14.  
    15.         MyBase.WndProc(m)
    16. End Sub

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Keep borders, prevent relocation of forms

    If you are using my suggestion to get rid of the titlebar, then you don't need any additional code at all because there is no way to move the form that way. The only possible way I can think of would be to right-click the taskbar item and select Move in the context menu (I'm not even sure if this contextmenu is available if you set ControlBox to false, don't think so!), but from your other threads I think you are hiding the taskbar item, so that is not possible either I can't think of any other way to move the form.

  5. #5

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Keep borders, prevent relocation of forms

    If I only wanted this functionality on a handful of select forms, what's the best way to do that.
    cicatrix, I think your solution would do it for all forms within the project.

  6. #6
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Keep borders, prevent relocation of forms

    Quote Originally Posted by stateofidleness View Post
    If I only wanted this functionality on a handful of select forms, what's the best way to do that.
    cicatrix, I think your solution would do it for all forms within the project.
    No, cicatrix's code goes in the form itself, so it will only do something for every instance of that one form.

    The same goes for my suggestion. Setting the ControlBox property to False and the Text property to an empty string can be done in the form itself, and any instance you create of that form will have those properties. It's really no different than any other property...

    In summary: cicatrix's code will disable form moving (I think, did not test it but I assume it works), but the form will still display the titlebar.

    My suggestion will hide the titlebar, which, in combination with hiding the taskbar item, gives the user no way to even try to move the form in the first place. So, you could still use cicatrix's code in combination with my suggestion, but it will never get used.

  7. #7

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Keep borders, prevent relocation of forms

    Actually did a combo of the solutions as I needed some to maintain the titlebar and some it wasn't necessary. Here's what I ended up with and it is working beautifully! Thank you both!
    Attached Images Attached Images  

  8. #8
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [RESOLVED] Keep borders, prevent relocation of forms

    Looks good. Might I suggest that you use non-rounded edges for the toolstrips in the camera windows? I think that will look better. To do that, you can use:
    Code:
    DirectCast(ToolStrip1.Renderer, ToolStripProfessionalRenderer).RoundedEdges = False

  9. #9

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