Do Not Move Form At Runtime + VB.Net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 324
Reputation: sonia sardana has a little shameless behaviour in the past 
Solved Threads: 7
sonia sardana sonia sardana is offline Offline
Posting Whiz

Do Not Move Form At Runtime + VB.Net

 
-1
  #1
Oct 9th, 2009
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-
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,655
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 472
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven
 
0
  #2
Oct 9th, 2009
Set FormBorderStyle
  1. Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 94
Reputation: yorro has a little shameless behaviour in the past 
Solved Threads: 6
yorro yorro is offline Offline
Junior Poster in Training
 
-1
  #3
Oct 9th, 2009
Originally Posted by adatapost View Post
Set FormBorderStyle
  1. Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
I don't think he is talking about resizing it.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC