• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Form resizing itself when using code to drag form around

Hi,
    Using VB.NET 2005 and I have a form that I want to be able to drag around by clicking anywhere in the form window. I achieve this by using the below code that has been posted on this site several times. The problem is: after I add this code to a form any time I make changes in the code for the form and then switch back to the design view of that form the form is resizing itself to a smaller size. So if my form size is (453, 200) , after making some changes and going back into the design view the form will all of a sudden be (449, 196).  This keeps happening over and over, the form keeps getting smaller ! So I am constantly having to change the size of the form back and move the controls around again to reposition them. Any idea why this is happening ? Is there a way to prevent this ?  Any help would be greatly appreciated ! Thanks !

Code:
    Const WM_NCHITTEST As Integer = &H84
    Const HTCLIENT As Integer = &H1
    Const HTCAPTION As Integer = &H2
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg
            Case WM_NCHITTEST
                MyBase.WndProc(m)
                If m.Result.ToInt32 = HTCLIENT Then m.Result = IntPtr.op_Explicit(HTCAPTION)
            Case Else
                MyBase.WndProc(m)
        End Select
    End Sub
0
kasowitz
Asked:
kasowitz
  • 2
  • 2
1 Solution
 
JonMnyCommented:
I think you want to check if your in designmode before executing the code

if not me.designmode then...
0
 
kasowitzAuthor Commented:
The resizing is not happening when I execute the code. It is happening while I am still working on and designing the code/form.
0
 
JonMnyCommented:
So if you remove the code it doesnt resize in design? Is this a usercontrol?
0
 
kasowitzAuthor Commented:
Actually, I just tried Removing the code out of my form, and it is still doing it. Why would my form be making itself smaller all the time?  Its just a standard form with a couple of buttons on it.  Any time I make a change to the code of the form, and switch back to the design view of the form, the form size is getting smaller.  This makes no sense.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try creating a NEW project with just ONE form on it.  Does the problem persist?

If it is only happening on one project/form then it is something local to that project.  It is either "corrupt" or possibly it has a third party control on it?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now