2 Replies - 12586 Views - Last Post: 27 October 2008 - 04:53 PM Rate Topic: -----

#1 Gaming Warrior  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 27-October 08

[2008] Custom Title Bar

Posted 27 October 2008 - 02:43 AM

I'm creating an app and have used the property Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None

I have then created a new bar which goes with the theme of my app using a rectangle shape. If have some images to close and minimize and all is well at this point.

I then came to making the window dragable via the rectangle shape, this is where the problems start

So far i have managed to get it semi working using the code below

Public Class chat
	Dim IsMouseDown = False
	Dim startPoint

	Private Sub TitleBar_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TitleBar.MouseUp
		IsMouseDown = False
	End Sub

	Private Sub TitleBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TitleBar.MouseDown
		startPoint = e.Location
		IsMouseDown = True

	End Sub

	Private Sub TitleBar_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TitleBar.MouseMove
		If IsMouseDown Then
			Dim p1 = New Point(e.X, e.Y)
			Dim p2 = PointToScreen(p1)
			Dim p3 = New Point(p2.X - startPoint.X, p2.Y - startPoint.Y)
			Location = p3
		End If
	End Sub



End Class



The problem with this code is that if the mouse is moved to fast it it tends to jump out of the area of the TitleBar and the form stops following the mouse. Is there a way to stop this happening or a better way to go about moving a form that doesn't have a title bar?

Is This A Good Question/Topic? 0
  • +

#21 WayneSpangler  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 106
  • Joined: 22-March 08

Re: [2008] Custom Title Bar

Posted 27 October 2008 - 01:05 PM

Try this. It is what I use. It uses a window api.
	Private Sub TitleBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TitleBar.MouseDown
		If e.Button = MouseButtons.Left Then
			Me.TitleBar.Capture = False   'change this to the control you will use to move the window
			' Create and send a WM_NCLBUTTONDOWN message.
			Const WM_NCLBUTTONDOWN As Integer = &HA1S
			Const HTCAPTION As Integer = 2
			Dim msg As Message = _
				Message.Create(Me.Handle, WM_NCLBUTTONDOWN, _
					New IntPtr(HTCAPTION), IntPtr.Zero)
			Me.DefWndProc(msg)
		End If

	End Sub

Was This Post Helpful? 1

#22 Gaming Warrior  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 27-October 08

Re: [2008] Custom Title Bar

Posted 27 October 2008 - 04:53 PM

Thank you so much!!!!!!!!!!!
Is there something i can press to mark the topic as solved?
Was This Post Helpful? 1

Page 1 of 1