944,093 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1358
  • VB.NET RSS
Oct 9th, 2009
-1

Do Not Move Form At Runtime + VB.Net

Expand Post »
As u all know,at runtime we can move the form.
I use the foll. code,so dat form doesn't move.I want to ask dat is there any easy way to do it.
Mine code below working correctly,but lengthy-
VB.NET Syntax (Toggle Plain Text)
  1. Option Compare Text
  2. Option Strict On
  3. Option Explicit On
  4.  
  5. Public Class Form1
  6. Dim RCTransparentVerticalBar As Rectangle
  7.  
  8. Public Sub New()
  9. MyBase.New()
  10. 'This call is required by the Windows Form Designer.
  11. InitializeComponent()
  12. 'Make the fake caption rectangle
  13. RCTransparentVerticalBar = New Rectangle(0, 0, Me.Width, 29)
  14. End Sub
  15. Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
  16. 'We want to pretend that the rectangle RCTransparentVerticalBar, is the caption bar so we can drag the form by it...
  17. If m.Msg = WM_NCHITTEST Then
  18. Call FakeCaptionForCaptionlessWindow(Me, m, RCTransparentVerticalBar)
  19. Else
  20. MyBase.WndProc(m)
  21. End If
  22. End Sub
  23.  
  24. End Class
  25.  
  26.  
  27. ADD MODULE
  28. Option Strict On
  29. Option Explicit On
  30. Option Compare Text
  31.  
  32. Module ModMoveForm
  33. Public Const WM_NCHITTEST As Long = &H84
  34.  
  35. Public Enum HitTestResult
  36. HTBORDER = 18
  37. HTBOTTOM = 15
  38. HTBOTTOMLEFT = 16
  39. HTBOTTOMRIGHT = 17
  40. HTCAPTION = 2
  41. HTCLIENT = 1
  42. HTERROR = (-2)
  43. HTGROWBOX = 4
  44. HTHSCROLL = 6
  45. HTLEFT = 10
  46. HTMAXBUTTON = 9
  47. HTMENU = 5
  48. HTMINBUTTON = 8
  49. HTNOWHERE = 0
  50. HTRIGHT = 11
  51. HTSYSMENU = 3
  52. HTTOP = 12
  53. HTTOPLEFT = 13
  54. HTTOPRIGHT = 14
  55. HTVSCROLL = 7
  56. HTTRANSPARENT = (-1)
  57. HTOBJECT = 19
  58. HTCLOSE = 20
  59. HTHELP = 21
  60. End Enum
  61.  
  62. Public Sub FakeCaptionForCaptionlessWindow(ByVal fParent As Form, ByRef m As Message, ByVal CaptionRectangle As Rectangle)
  63.  
  64. If m.Msg = WM_NCHITTEST Then
  65. '\\ If the mouse is in the rectangle that is considered to be the caption set the return value to HTCAPTION
  66. Dim ptClickLocation As New Point(m.LParam.ToInt32)
  67. ptClickLocation = fParent.PointToClient(ptClickLocation)
  68.  
  69. If CaptionRectangle.Contains(ptClickLocation) Then
  70. m.Result = New IntPtr(HitTestResult.HTCAPTION)
  71. Else
  72. m.Result = New IntPtr(HitTestResult.HTCLIENT)
  73. End If
  74. End If
  75. End Sub
  76.  
  77. End Module
Similar Threads
Reputation Points: 0
Solved Threads: 8
Posting Whiz
sonia sardana is offline Offline
326 posts
since Mar 2008
Oct 9th, 2009
0
Re: Do Not Move Form At Runtime + VB.Net
Set FormBorderStyle
VB.NET Syntax (Toggle Plain Text)
  1. Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Oct 9th, 2009
-1
Re: Do Not Move Form At Runtime + VB.Net
Click to Expand / Collapse  Quote originally posted by adatapost ...
Set FormBorderStyle
VB.NET Syntax (Toggle Plain Text)
  1. Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
I don't think he is talking about resizing it.
Reputation Points: 8
Solved Threads: 7
Junior Poster
yorro is offline Offline
119 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Showing a Dialog Error on Design Time, when its suppose to show at runtime
Next Thread in VB.NET Forum Timeline: winmm.dll





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC