Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


How to Remove a Titlebar from a .Sizable Form

How to Remove a Titlebar from a .Sizable Form

As some may already know, I am relatively new to the scene and I am learning as I go. With any luck, you guys can help me (yet again)! Everyone has been extremely helpful and patient with me so far. Let's see if you can assist with me with my latest conundrum:

I have created a new form with FormBorderStyle.Sizable as its border option. However, I do not want the Titlebar present on the form because I have created my own custom titlebars. However, when I removed the form's caption and controlbox, there is still a "ghost" titlebar present. Albeit, much smaller than the original, for some reason I cannot get it to disappear. (Screenshot attached) Any ideas?


newForm.FormBorderStyle = FormBorderStyle.Sizable
newForm.ControlBox = False
newForm.Text = "" 

In advance, thank you for you assistance!

RE: How to Remove a Titlebar from a .Sizable Form

A number of thoughts:

  1. You could use your current method, but lower the position of your titlebar by a few pixels - probably the easiest method.
  2. You could use FormBorderStyle.None, but then you would have to handle the various mouse events to do your own sizing code - not as easy as 1, but much easier than 3.
  3. The nastiest, but probably most effective would be to trap low level Windows Messages. I've not done this for several years, but there should be plenty of advice here or on other forums - in the meantime I'll try to find something I've written (although it will be for VS 2005 or VS 2008 and for Windows XP)

RE: How to Remove a Titlebar from a .Sizable Form

Sorry, I forgot to say that if you use method 3 you would need to look at Windows Messages relating to the ClientArea and NonClientArea - it may be possible to set the NonClientArea Size to 0, which should remove the TitleBar completely.

RE: How to Remove a Titlebar from a .Sizable Form

softhemc, again I appreciate all of the great help!

However, I am slightly unclear as to what you mean by "lower the position of your titlebar." Are you referencing the form-generated titlebar, or the custom designed one?

If it is the first option, I was not aware that we could manually control the height of the form titlebar. If so, I would like to set it at 0 so that my custom titlebar is at the very top of the form as a titlebar should be!

If it is the later, this will not work for the effect I want to achieve. If you view the screenshot there is the block of white space just above the titlebar that I need to get rid of. It is making my brain hurt trying to determine why the current code is not abolishing it from my current form. (Works fine in different FormBorderStyles)

I toyed with the idea of using FormBorderStyle.None, but I am not very familiar with the system drawing tools, nor am I sure of how I would add a handler for the created border itself. My fear is that if I used a "MouseOver" even for a rectangle area, it would cover the entire surface area of the form since the border encompasses it!

I have read a few article about manipulating &hwnd or some other things like that, but I do not understand most of it when I read it and am a bit hesitant with trying to jump into it.

Please provide any other ideas that you may come up with. I will mess with a few different hypothesis that I am boiling-up and return with my results.

Again, many thanks!

RE: How to Remove a Titlebar from a .Sizable Form

I'll be tied up for the next couple of hours - but I'll see what I can come up with a bit later.

RE: How to Remove a Titlebar from a .Sizable Form

I've had a quick look at the image and could you not move your custom titlebar up by a couple of pixels?

RE: How to Remove a Titlebar from a .Sizable Form


No, it's not really possible. The custom titlebar is currently set to TitleBar.Top = 0, unless there is some other method I could use. If this portion of the form was actually part of the client, though, wouldn't it be filled with the form background color?

RE: How to Remove a Titlebar from a .Sizable Form

What happens if you use SizableToolWindow instead of Sizable? And what version of Windows are you running this on?

RE: How to Remove a Titlebar from a .Sizable Form

Same result using FormBorderStyle.SizableToolWindow. I am running Visual Studio Community 2015 on Windows 10.

RE: How to Remove a Titlebar from a .Sizable Form

Well, your question inspired a functional investigation. I went ahead and compiled my current program and transferred it to a USB. I ran the program on my Windows 7 machine, and viola(!), the white space was gone!

So... now it appears that we have an API issue with Windows 10 when applying this code. pc1 I am not exactly sure how to tackle this, and that does not bode well for any past programs that utilize the same coding.

Will continue to dig to see if I can generate a plausible resolution. Please see the attached image to see the Windows 7 results.

RE: How to Remove a Titlebar from a .Sizable Form

Yep, the reason I asked was because my own testing on XP and W7 did not exhibit the problem.

RE: How to Remove a Titlebar from a .Sizable Form

I've just spotted your conversations with strongm, which makes redundant that I was going to say that the appearance is as required under Win7 using both VS2013 and VS2015, but that under Win10 the problem is experienced.

I've tried to remove the problem using the OnPaint event, but to no avail. I haven't been able to locate my low level stuff - it was written for a former client and I don't have a copy of the source.

I'm looking at one or two other things, so I'll get back to you later.

RE: How to Remove a Titlebar from a .Sizable Form

I appreciate all of the help. You guys have been absolutely splendid during this whole process. I attempted to simply set the FormBorderStyle to FormBorderStyle.FixedToolWindow and then handling mouse events to still make it sizable, but the program keeps throwing error codes and crashing.

I then attempted to do a borderless window and draw my own bounding box that allowed adjusting the form -- I apparently have no clue how to draw a box in

I opened a like-minded question on another forum to see if I could fish for more suggestions. The only thing provided was to set the border to None and that we had to override WndProc() and handle the WM_NCHITTEST message. Then somehow handle m.Result to the "appropriate edge constant". Now, reading this, it sounds like something I could try, but I must be honest -- it's like reading a foreign language to me! I do not know what any of these events or procedures are. I am going to do my research on them and attempt some sort of code based on it, but if you have any iota on what to do with this, feel free to make more suggestions!

Again, I will be sure to report back on any findings. Thanks!

RE: How to Remove a Titlebar from a .Sizable Form

That suggestion was my option 3 in my first reply, but I no longer have access to my original source code so I would need to research this again from scratch. It will take too long for me to do between now and the weekend, so if nothing has materialised between now and then I'll have a go at that.

Maybe strongm has something using the API that he could suggest, since I think he has answered some questions on that in the VB 6 forum.

RE: How to Remove a Titlebar from a .Sizable Form

I'm over 90% certain I have a solution - but it will take me a while to put a test program together, so as I said earlier I'll do this over the weekend. By the way it does not involve any nasty low level calls.

RE: How to Remove a Titlebar from a .Sizable Form

Let me know what you find out! I know that I was able to establish a drag-and-drop protocol without low level hub-bub, but this WndProc stuff has me stumped. I was able to successfully utilize it to resize forms set to FormBorderStyle.None and FormBorderStyle.FixedToolWindow, but I cannot seem to parse it in a way that I can effectively utilize it in a dynamically-created form. The code uses calls to Me.Bounds, but this form reference cannot be used in a form that doesn't currently exist! Trying to figure out how I can put this code into the form at creation time, but I'm running out of ideas.

So, anything new may provide me the steam and inspiration I need. If only Windows 10 has been as polite enough as to incorporate an easier way to perform what would seem such a standard task!

Thank you for all of the help, by all means, do not take unnecessary time out of your weekend for me! Get back to me at your leisure -- I'll be around.

RE: How to Remove a Titlebar from a .Sizable Form

Most of what I tried yesterday nearly worked - but I've got a new solution which will almost certainly work. I'll post this late tomorrow.

RE: How to Remove a Titlebar from a .Sizable Form

Well, I was able to produce the effect that I wanted, but the code seems to make for a very sluggish windowed interface and the click & drag subroutine that I created is now very jerky across the screen. May be due to a slower redraw rate due to whatever the new code is doing to slow things down. I will put my work-around resolution here, but if you are able to find something simpler and cleaner -- I will gladly accept it!

I modulated the WndProc code due to the need to put this as the handler for multiple windows when I needed it. So, I created a new class called SubclassHWND.vb:


Public Class SubclassHWND
    Inherits NativeWindow

    Public Const WM_NCHITTEST = &H84
    Public Const BorderSize As Integer = 10
    Public frm As Form = Nothing

    Public Sub setFrm(ByVal sender As Form)
        frm = sender
    End Sub

    Protected Overloads Overrides Sub WndProc(ByRef m As Message)
        if m.Msg = WM_NCHITTEST Then
            Dim x As Integer = m.LParam.ToInt32 And &HFFFF
            Dim y As Integer = (m.LParam.ToInt32 >> 16) And &HFFFF
            Dim p As Point = New Point(x, y)
            If frm.Bounds.Contains(p) Then
                Dim top As Boolean = Math.Abs(frm.Bounds.Y - y) < BorderSize
                Dim bottom As Boolean = Math.Abs(frm.Bounds.Bottom - y) < BorderSize
                Dim left As Boolean = Math.Abs(frm.Bounds.X - x) < BorderSize
                Dim right As Boolean = Math.Abs(frm.Bounds.Right - x) < BorderSize
                If top And left Then
                    m.Result = NCHITTEST.HTTOPLEFT
                ElseIf top And right Then
                    m.Result = NCHITTEST.HTTOPRIGHT
                ElseIf bottom And left Then
                    m.Result = NCHITTEST.HTBOTTOMLEFT
                ElseIf bottom And right Then
                    m.Result = NCHITTEST.HTBOTTOMRIGHT
                ElseIf top Then
                    m.Result = NCHITTEST.HTTOP
                ElseIf bottom Then
                    m.Result = NCHITTEST.HTBOTTOM
                ElseIf left Then
                    m.Result = NCHITTEST.HTLEFT
                ElseIf right Then
                    m.Result = NCHITTEST.HTRIGHT
                    m.Result = NCHITTEST.HTCAPTION
                End If
                Exit Sub
            End If
        End If
    End Sub
End Class

    HTBOTTOM = 15
    HTLEFT = 10
    HTRIGHT = 11
    HTTOP = 12
    HTTOPLEFT = 13
End Enum 

In the code I use to generate the forms I inserted:


newForm.FormBorderStyle = FormBorderStyle.FixedToolWindow
newForm.ControlBox = False
newForm.Text = String.Empty
Dim s As SubclassHWND = New SubclassHWND()

This is certainly a lot to swallow, and I was hoping that Windows would have a cleaner way to manipulate all of this, but alas, they do not. If you can think of anything that may work in it stead, please let me know! Again, thank you for all of the wonderful help and ideas that you have already supplied. I couldn't have done it otherwise. :)

Hoorah! A sizable window in Windows 10 without that pesky white bar at the top. Looks much cleaner.

RE: How to Remove a Titlebar from a .Sizable Form

Sorry this has taken so long, I've had a few other things on.

I've got a solution which seems to work very smoothly, but does involve a "cheat". I'm doing some more testing and also trying to remove the cheat.

I'll post the solution by the end of tomorrow, hopefully without the cheat.

RE: How to Remove a Titlebar from a .Sizable Form

I'm still using the 'cheat', however I think you might want to consider it aswell.

Create a very basic form with only what will be used in all your created forms e.g. Blank out the TitleBar and set the FormBorderStyle. Also if your replacement TitleBar is standard across all your created forms then include that as well. The benefits are all the prebuilt Events and Properties that come with the form avoiding potential AddHandler and RemoveHandler code etc.

So I've used this (below is the formname.Designer.vb page - use show all files to see it in Solution Explorer:)


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class MyCodeDesignedForm
	Inherits System.Windows.Forms.Form

	'Form overrides dispose to clean up the component list.
	<System.Diagnostics.DebuggerNonUserCode()> _
	Protected Overrides Sub Dispose(ByVal disposing As Boolean)
			If disposing AndAlso components IsNot Nothing Then
			End If
		End Try
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> _
	Private Sub InitializeComponent()
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(643, 299)
		Me.ControlBox = False
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "MyCodeDesignedForm"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen

	End Sub
End Class 

RE: How to Remove a Titlebar from a .Sizable Form

The hosting form.........:


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles CreateFormButton.Click

		Dim MyNewForm As New MyCodeDesignedForm

		'Use one of the following, solving the top border problem requires one of these
		'MyNewForm.FormBorderStyle = FormBorderStyle.FixedSingle
		'MyNewForm.FormBorderStyle = FormBorderStyle.FixedToolWindow

		'******* insert any other code here to design the rest of the form.


	End Sub 

If you need to refer to any specific form outside of this sub create a form variable such as an Array, Dictionary or other list containing type as being of Form type. That way you will be able to locate and refer to the individual forms after creation.

RE: How to Remove a Titlebar from a .Sizable Form

The code to handle the resizing is a combination of code that I wrote some years ago for a slightly different purpose and other code I found on the Internet.

I've used a lot of spacing between blocks of code to make it easier to read and follow ........


Public Class ResizeableForm

	Public Event ResizingDone(ByRef ftr As Form)

	Private WithEvents FormToResize As Form

	Private _Edge As EdgeEnum = EdgeEnum.None
	Private _AllowEdges As EdgeEnum = EdgeEnum.All

	Private _OutlineWidth As Integer = 4
	Private _OutlineDrawn As Boolean = False
	Private _OutlineColor As Drawing.Color = Color.Yellow

	Private _MouseDown As Boolean = False
	Private _MousePointerLastLocation As Point = New Point(0, 0)

	Private _OriginalCursor As Cursor = Nothing

	Private g As Graphics = Nothing

	Public Enum EdgeEnum

		None = 0
		Right = 1
		Left = 2
		Top = 4
		Bottom = 8

		All = Left Or Right Or Top Or Bottom

	End Enum

	Public Property AllowEdges() As EdgeEnum
			Return _AllowEdges
		End Get
		Set(ByVal value As EdgeEnum)
			_AllowEdges = value
		End Set
	End Property

	Public Property OutlineColor() As Drawing.Color
			Return _OutlineColor
		End Get
		Set(ByVal value As Drawing.Color)
			_OutlineColor = value
		End Set
	End Property

	Public Property MouseDown As Boolean
			Return _MouseDown
		End Get
		Set(value As Boolean)
			_MouseDown = value
		End Set
	End Property

	Public Property OriginalCursor As Cursor
			Return _OriginalCursor
		End Get
		Set(value As Cursor)
			_OriginalCursor = value
		End Set
	End Property

	Public Sub New(ByVal FormToResize As Form)

		Me.FormToResize = FormToResize

	End Sub

	Private Sub FormToResize_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormToResize.MouseDown

		If e.Button = MouseButtons.Left Then _MouseDown = True

	End Sub

	Private Sub FormToResize_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormToResize.MouseUp

		_MouseDown = False

	End Sub

	Private Sub FormToResize_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormToResize.MouseMove

		With FormToResize

			g = .CreateGraphics
			Dim b As New SolidBrush(OutlineColor)

			If _OutlineDrawn Then
				_OutlineDrawn = False
			End If

			Select Case _Edge
				Case EdgeEnum.Left
					g.FillRectangle(b, 0, 0, _OutlineWidth, .Height)
					_OutlineDrawn = True
				Case EdgeEnum.Right
					g.FillRectangle(b, .Width - _OutlineWidth, 0, .Width, .Height)
					_OutlineDrawn = True
				Case EdgeEnum.Top
					g.FillRectangle(b, 0, 0, .Width, _OutlineWidth)
					_OutlineDrawn = True
				Case EdgeEnum.Bottom
					g.FillRectangle(b, 0, .Height - _OutlineWidth, .Width, _OutlineWidth)
					_OutlineDrawn = True
			End Select

			If _MouseDown AndAlso _Edge <> EdgeEnum.None Then

				Select Case _Edge
					Case EdgeEnum.Left
						.SetBounds(.Left + e.X, .Top, .Width - e.X, .Height)
					Case EdgeEnum.Right
						.SetBounds(.Left, .Top, .Width - (.Width - e.X), .Height)
					Case EdgeEnum.Top
						.SetBounds(.Left, .Top + e.Y, .Width, .Height - e.Y)
					Case EdgeEnum.Bottom
						.SetBounds(.Left, .Top, .Width, .Height - (.Height - e.Y))
				End Select

				RaiseEvent ResizingDone(FormToResize)

				OriginalCursor = Cursor.Current
				Select Case True
					Case e.X <= _OutlineWidth
						.Cursor = Cursors.SizeWE
						_Edge = EdgeEnum.Left
					Case e.X > .Width - (_OutlineWidth + 1)
						.Cursor = Cursors.SizeWE
						_Edge = EdgeEnum.Right
					Case e.Y <= _OutlineWidth
						.Cursor = Cursors.SizeNS
						_Edge = EdgeEnum.Top
					Case e.Y > .Height - (_OutlineWidth + 1)
						.Cursor = Cursors.SizeNS
						_Edge = EdgeEnum.Bottom
					Case Else
						.Cursor = OrininalCursor
						_Edge = EdgeEnum.None
				End Select

			End If

		End With

	End Sub

	Private Sub FormToResize_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormToResize.MouseLeave

		FormToResize.Cursor = OriginalCursor
		_Edge = EdgeEnum.None

		g = Nothing

	End Sub

End Class 

RE: How to Remove a Titlebar from a .Sizable Form

One thing I forgot to mention - if you use FixedSingle then the form will have built in Minimum Height and Width therefore a side effect of the code is that when you reduce the size from the left border to the right border or from the top border to the bottom border, once these minimums have been reached the form will move down or left. If you use FixedToolWindow the form can be sized to the minimums you set (i.e. 0 by default).

RE: How to Remove a Titlebar from a .Sizable Form

I made some changes to the posted code, which I hadn't implemented in my code - and they don't work.

So change every reference to

= OrginalCursor


= Cursors.Default

Sorry about that - After posting it crossed my mind that you might have designed your own cursors and so that was a quick (but unfortunately untested solution to save the "incoming" cursor and restore it at the end. I should have tested first!!

RE: How to Remove a Titlebar from a .Sizable Form

I don't like being beaten, but I haven't had much time recently. I WILL solve these issues.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close