Results 1 to 12 of 12

Thread: [RESOLVED] Form Moveable=False

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    57

    Resolved [RESOLVED] Form Moveable=False

    Hello..

    can anyone show me small lines of code that the users are unable to move to form?

    i already search on google and i found some code.. but it compose of many-many lines of code and i cant understand... i want a small lines of code... heheh

    thnx in advance...

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Form Moveable=False

    Change the "FormBorderStyle" to None
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Form Moveable=False

    Quote Originally Posted by Vectris View Post
    Change the "FormBorderStyle" to None
    That's not really practical if you don't want the form to have no border.

    There is no simple way to do this. There is no property that determines whether a form can be moved or not. It takes a bit of code. I'm not sure what you already have but if you follow the CodeBank link in my signature you'll find some code to do this.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Form Moveable=False

    class-level:
    vb Code:
    1. Dim originalpoint As Point
    2. Dim islocked As Boolean = False

    then, in a sub handling Me.LocationChanged:
    vb Code:
    1. If islocked Then Me.Location = originalpoint Else originalpoint = Me.Location

  5. #5
    Member MicLovin's Avatar
    Join Date
    Jul 2008
    Location
    Under a rock
    Posts
    62

    Re: Form Moveable=False

    Ive came across the same problem awhile ago so to make it easier on me I created a user control. I will provide it in this reply.

    Learn from it.... I know not my best work but it gets the job done.
    Attached Files Attached Files
    Beginner: Java
    Intermediate: VB.Net, C#, Delphi, Perl
    Master: HTML, XHTML, PHP, JavaScript, Pascal, SCAR

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Form Moveable=False

    Quote Originally Posted by MicLovin View Post
    Ive came across the same problem awhile ago so to make it easier on me I created a user control. I will provide it in this reply.

    Learn from it.... I know not my best work but it gets the job done.
    I think you've got it the wrong way around. The OP wants the form to be NOT movable and (as far as we're aware) WITH a border.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Form Moveable=False

    Quote Originally Posted by minitech View Post
    class-level:
    vb Code:
    1. Dim originalpoint As Point
    2. Dim islocked As Boolean = False

    then, in a sub handling Me.LocationChanged:
    vb Code:
    1. If islocked Then Me.Location = originalpoint Else originalpoint = Me.Location
    That will get the job done, so kudos for that, but it's a bit of a hack. It doesn't actually stop the form being moved but, rather, it moves the form back to its original location after it moves. As a result you can get an ugly visual effect when dragging the form. Run that code and then try dragging the form around the screen and you'll see that it appears in other locations momentarily, which looks a little unprofessional. It's not really worth allowing an application to look unprofessional to save 20 or 30 lines of code that someone else has already provided for you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Form Moveable=False

    Put this in the form you want to prevent from moving:

    vb.net Code:
    1. Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    2.         If (m.Msg = 274) AndAlso (m.WParam.ToInt32() = 61456) Then
    3.             Return
    4.         ElseIf (m.Msg = 161) AndAlso (m.WParam.ToInt32() = 2) Then
    5.             Return
    6.         End If
    7.         MyBase.WndProc(m)
    8.     End Sub
    Last edited by ForumAccount; May 24th, 2009 at 02:20 AM.

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    57

    Re: Form Moveable=False

    im glad many members reply to my thread... thanks to all you guys...


    Quote Originally Posted by ForumAccount View Post
    Put this in the form you want to prevent from moving:

    vb.net Code:
    1. Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    2.         If (m.Msg = 274) AndAlso (m.WParam.ToInt32() = 61456) Then
    3.             Return
    4.         ElseIf (m.Msg = 161) AndAlso (m.WParam.ToInt32() = 2) Then
    5.             Return
    6.         End If
    7.         MyBase.WndProc(m)
    8.     End Sub
    @ForumAccount: thank you so much sir u solved my problem...+rep

    may i know what is
    274
    61456
    161
    and
    2
    stands for?
    Last edited by Noob_Coder; May 24th, 2009 at 05:11 AM.

  10. #10
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: Form Moveable=False

    Quote Originally Posted by ForumAccount View Post
    Put this in the form you want to prevent from moving:

    vb.net Code:
    1. Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    2.         If (m.Msg = 274) AndAlso (m.WParam.ToInt32() = 61456) Then
    3.             Return
    4.         ElseIf (m.Msg = 161) AndAlso (m.WParam.ToInt32() = 2) Then
    5.             Return
    6.         End If
    7.         MyBase.WndProc(m)
    8.     End Sub
    The only way to improve this is if there was something that also disabled the "Move" option in the ContextMenu that appears when right-clicking the top-left icon.
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Form Moveable=False

    Quote Originally Posted by JugglingReferee View Post
    The only way to improve this is if there was something that also disabled the "Move" option in the ContextMenu that appears when right-clicking the top-left icon.
    Which is what the SystemMenuManager in my aforementioned CodeBank thread does.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: Form Moveable=False

    Quote Originally Posted by jmcilhinney View Post
    Which is what the SystemMenuManager in my aforementioned CodeBank thread does.
    I swear you've contributed something on every topic that comes up!
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

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