This can be difficult at first, but i will attempt to keep it short and sweet.
Have you ever wanted to have a compartment that you could pull out of your form, one that extended beyond the border of the form? Well, this example doesn't exactly do that, but it does something that provides the same visual affect.
This section should include a description of the outcome; i.e., what will happen if the steps are followed (a task is completed, an application is installed, or the internet becomes available).
Option
Strict
On
Public
Class
SliderPanel
'Inherits means that this object will "inherit", or otherwise have the
'same properties as what it is inheriting from(panel in this case).
Inherits
Panel
'This property is for setting the height of the notch handle of the pullout
Property
HandleHeight
As
Integer
= 10
'This property is for setting how wide the notch handle portion of the pullout will be
HandleWidth
'This is a switch for determining when the user is pulling the panel out.
Dim
UpdatingSize
Boolean
'This variable stores the parent of this control for access in later routines
ParentObject
Object
Sub
New
()
'This panel does a lot of painting, so we make sure its doublebuffered.
Me
.DoubleBuffered =
True
'We set the cursor to hand
.Cursor = Cursors.Hand
'We make sure the backcolor of this panel is transparent
.BackColor = Color.Transparent
End
'We use overrides OnPaint so we can access the graphics object before event delegates are created
Protected
Overrides
OnPaint(
ByVal
e
System.Windows.Forms.PaintEventArgs)
'Capture the graphics object into a variable
Graphics
Graphics = e.Graphics
'Calculate a factor for calculating the locations of the corners of the notches
Offset
=
CInt
((
.Height - HandleHeight) / 2)
'Create a rectangle to fill the greater part of the notch handle
R1
Rectangle(
Point(0,
.Height / 2) - (HandleHeight / 2))),
Size(
.Width, HandleHeight))
'this will be the color of the tab that pulls out
FillBaseColor
Color = Color.Tan
'this will be the translucency of the tab control
FillAlpha
= 255
'Create a fill brush, combining the fillalpha and the base color
FillBrush
SolidBrush(Color.FromArgb(FillAlpha, FillBaseColor.R, FillBaseColor.G, FillBaseColor.B))
'Calculate 3 points to fill the upper triangle
P1
Point(
.Width - HandleWidth, 0)
P2
.Width, Offset)
P3
.Width - HandleWidth, Offset)
'Calculate 3 points to fill the lower triangle
B1
.Width - HandleWidth,
.Height)
B2
.Height - Offset)
B3
.Width,
'Calculate the rectangle for filling the greater portion of the pullout(discluding the handle)
R2
Rectangle(0, 0,
'Calculate the last rectangle which goes into the notch(in the center of the two triangles)
R3
.Width - HandleWidth, Offset, HandleWidth,
.Height - (Offset * 2))
'Draw the upper triangle(you can comment out any of these to see what it's doing)
Graphics.FillPolygon(FillBrush, {P1, P2, P3})
'Draw the lower triangle
Graphics.FillPolygon(FillBrush, {B1, B2, B3})
'Draw the main area of the pullout
Graphics.FillRectangle(FillBrush, R2)
'Draw the rectangle inbetween the upper triangle and the lower triangle
Graphics.FillRectangle(FillBrush, R3)
'Outline our pullout with black lines
Graphics.DrawLine(Pens.Black, P1, P2)
Graphics.DrawLine(Pens.Black, B1, B3)
Graphics.DrawLine(Pens.Black,
Point(P2.X - 1, P2.Y),
Point(B3.X - 1, B3.Y))
Point(0, 0), P1)
.Height - 1),
Point(B1.X, B1.Y - 1))
Point(0, 0),
.Height - 1))
'create the delegates for the paint event
MyBase
.OnPaint(e)
OnMouseDown(
System.Windows.Forms.MouseEventArgs)
'This is still somewhat of a test....
'This places the current panel that has been clicked
'on top of other panels if they overlap
.BringToFront()
'the mouse is down, so now we get ready to pull out the tab<goto the mousemove event>
'we make a mental note that we're updating now
UpdatingSize =
.OnMouseDown(e)
OnMouseUp(
'Mouse is no longer down, so we are no longer updating
False
.OnMouseUp(e)
OnMouseMove(
'If the mouse is still down, then this value is still true
If
Then
'Check if the mouse's X location is smaller than
'the panel's handle width
e.Location.X <
.HandleWidth
'If the mouse's X location is then
'Check that you are not expanding the
'panel beyond the invisible window(we're still really in the bounds of a form)
e.Location.X < Parent.ClientRectangle.Width -
.Left
'set the width of this panel
.Width =
'invalid call paint event
.Invalidate()
Else
'Check if updating the
'width will cause the panel to
'extend beyond the bounds of the invisible form
ProposedWidth
= e.Location.X
.Left + ProposedWidth > Parent.ClientRectangle.Width
'if it will, set it to be as wide is it can be
'while remaining visible
.Width = Parent.ClientRectangle.Width -
'redraw
'otherwise the proposed width
'will be used
.Width = ProposedWidth
.OnMouseMove(e)
OnParentChanged(
System.EventArgs)
'Change the stored parent object
ParentObject =
.Parent
Not
Is
Nothing
'Check if the parent object is a form or a control
TypeOf
(ParentObject)
Form
'Add a sizechanged event handler
AddHandler
DirectCast
(ParentObject, Form).SizeChanged,
AddressOf
ParentSizeChanged
(ParentObject, Control).SizeChanged,
.OnParentChanged(e)
Private
ParentSizeChanged(
sender
,
EventArgs)
(sender)
'Set the width of this to be the distance inbetween
'this panel's left and the parent's client rectangle.width
.Width >
(sender, Form).ClientRectangle.Width
(sender, Form).ClientRectangle.Width -
Parent.Invalidate(
)
(sender, Control).ClientRectangle.Width
(sender, Control).ClientRectangle.Width -
'Option strict is good for preventing the coding of errors
Form1
'Create a new instance of the sliderpanel
Friend
WithEvents
SliderPanel1
With
{.Parent =
, .Height = 200}
'Create a regular panel(this will be our borderless form)->with some properties
Panel1
{.Location =
Point(331, 154), .Size =
Size(551, 424), .Parent =
, .BackColor = Color.Silver, .BorderStyle = BorderStyle.FixedSingle}
'Variable for moving the form
Dragging
'variable for moving the form
MouseLocation
Point
Form1_Load(
System.
Handles
.Load
'Make the form's back color and transparency key the same
.BackColor = Color.Thistle
.TransparencyKey =
.BackColor
'make the form nice and big
.Size =
Size(1237, 833)
'make the form borderless
.FormBorderStyle = Windows.Forms.FormBorderStyle.None
'make the form doublebuffered for paint events
'this number will be how much shorter the pullout tab will be than the panel
SizeDifference
= 50
'set the slider's width to the handle width(for startup)--->closed
SliderPanel1.Width = SliderPanel1.HandleWidth
'Set the height of the panel(slider)
SliderPanel1.Height = Panel1.Height - SizeDifference
'Set the height of the edge of the handle to 95% of the height of the panel(slider)
SliderPanel1.HandleHeight =
(SliderPanel1.Height * 0.95)
'Set the location of the panel(slider)
SliderPanel1.Top = Panel1.Top + (SizeDifference \ 2)
SliderPanel1.Left = Panel1.Left + Panel1.Width - 1
'update the panel (slider)
SliderPanel1.Invalidate()
'Add the handlers to the panel for dragging the form around on the screen
Panel1.MouseDown,
Panel1_MouseDown
Panel1.MouseMove,
Panel1_MouseMove
Panel1.MouseUp,
Panel1_MouseUp
Panel1_MouseDown(
'enable moving of the form
Dragging =
'Store mouse location
MouseLocation.X = Windows.Forms.Cursor.Position.X -
MouseLocation.Y = Windows.Forms.Cursor.Position.Y -
.Top
Panel1_MouseMove(
'Check if moving the form is enabled
'if it is, set the new location of the form(this will keep happening while the mouse is down and moving)
.Top = Windows.Forms.Cursor.Position.Y - MouseLocation.Y
.Left = Windows.Forms.Cursor.Position.X - MouseLocation.X
Panel1_MouseUp(
'disable moving of the form
I hope you find this helpful!