Form with None FormBorderStyle but with ControlBox

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

I want to create a small Form wthich doesn't have a border (because it have
to be very small and the Border and that blue thing on top takes to much
time, but I do want a Controlbox (minimize, maximize and close).

Anybody knows how to do this?

Thanks a lot in advance!

Pieter
 
Hi Pieter,

Have a look at this, it is a crazy form, but it explains itself very easy.
is the whole form, but to give you an idea.

Cor

\\\coproduction Herfried, Fergus, Cor
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim g As New System.Drawing.Drawing2D.GraphicsPath
g.AddString( _
"Pieter", _
System.Drawing.FontFamily.GenericSansSerif, _
System.Drawing.FontStyle.Bold, _
200, _
New Point(0, 0), _
System.Drawing.StringFormat.GenericDefault _
)
Me.BackColor = Color.Red
Me.Region = New System.Drawing.Region(g)
g.Dispose()
Me.AutoScaleBaseSize = New System.Drawing.Size(0, 0)
Me.ClientSize = New System.Drawing.Size(800, 800)
Button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
Button1.ForeColor = System.Drawing.Color.Red
Button1.Location = New System.Drawing.Point(50, 40)
Button1.Size = New System.Drawing.Size(20, 20)
Button1.Text = "X"
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
///
 
Hehe it's indeed crazy, but on first sight it doesn't help me a lot. But
maybe I can find something playing with that kidn of properties. Thanks
anyways!

Pieter
 
* "DraguVaso said:
I want to create a small Form wthich doesn't have a border (because it have
to be very small and the Border and that blue thing on top takes to much
time, but I do want a Controlbox (minimize, maximize and close).

Add this code, for example, to the form's 'Load' event handler:

\\\
Dim g As New System.Drawing.Drawing2D.GraphicsPath
g.AddRectangle( _
New Rectangle( _
SystemInformation.Border3DSize.Width, _
SystemInformation.Border3DSize.Height, _
Me.Width - SystemInformation.Border3DSize.Width * 2, _
Me.Height - SystemInformation.Border3DSize.Height * 2 _
) _
)
Me.Region = New Region(g)
///
 
* "DraguVaso said:
Hehe it's indeed crazy, but on first sight it doesn't help me a lot. But
maybe I can find something playing with that kidn of properties. Thanks
anyways!

The 'Region' property is the way to go. I have posted some source code
in my other reply.
 
Ok I don't have a border now, but I still do have the blue bar on top of the
form.
Is there a way to remove the blue bar but keep the controlbox on the top
right corner?

Thanks, Pieter
 
* "DraguVaso said:
Ok I don't have a border now, but I still do have the blue bar on top of the
form.
Is there a way to remove the blue bar but keep the controlbox on the top
right corner?

AFAIK, no. You will have to implement the controlbox yourself.
 
simple create a form wint FormBorderStyle = none and NO title (dont
put anything in text property of the form)

1) add pictureBoxes holding your icons for maximize, minimize, close
2) behind click event of the picture boxes set WindowState property as
me.WindowsState = WindowsState.Maximized ' to maximize
me.WindowsState = WindowsState.Minimized ' to minimize
me.Close ' to close form

Note that you wont be able to move or resize this form. If you want
to be able to meve it, add this code in your form.

Protected Overrides Sub WndProc(ByRef m as
System.Windows.Forms.Message)
MyBase.WndProc(m)
if m.Msg = &H84 then
if m.Result.ToInt32 = 1 Then m.Result = New IntPtr(2)
end if
End Sub

this allows you to move your form on the screen provided you click
with the mouse on an form empty area (not on a control of the form)

This is how I do it. Let me know if it works for you.
Dino
 
Back
Top