using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
public class Win8StartForm : Form
{
const int padTop = 10;
SlidePanel slider;
public Win8StartForm()
{
this.BackColor = Color.FromArgb(50, 50, 50);
SlidePanel slidePanel = new SlidePanel()
{
Location = new Point(0, -padTop),
Size = new Size(this.DisplayRectangle.Width, this.DisplayRectangle.Height + padTop),
BackColor = Color.FromArgb(20, 170, 255)
};
slider = slidePanel;
this.Controls.Add(slidePanel);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
slider.Size = new Size(this.DisplayRectangle.Width, this.DisplayRectangle.Height + padTop);
}
public class SlidePanel : Panel
{
public SlidePanel()
{
this.DoubleBuffered = true;
T.Interval = 1;
T.Tick += T_Tick;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
#region Mouse Event Methods
Point hitPoint = Point.Empty;
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
hitPoint = e.Location;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
int delta = e.Y - hitPoint.Y;
Point dest = new Point(this.Location.X, this.Location.Y + delta);
if (dest.Y < 0)
{
this.Location = dest;
}
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (this.Bottom <= this.Height / 5)
{
SlideUp();
}
else
{
if (this.Location.Y < 0)
{
DropDown();
}
}
}
#endregion
int speed;
Direction direction;
private enum Direction
{
Up, Down
}
private System.Windows.Forms.Timer T = new System.Windows.Forms.Timer();
private void T_Tick(object sender, EventArgs e)
{
switch (direction)
{
case Direction.Up:
this.Location = new Point(this.Location.X, this.Location.Y - 1);
if (this.Bottom < 0)
{
T.Stop();
T.Interval = 1;
}
break;
case Direction.Down:
this.Location = new Point(this.Location.X, this.Location.Y + 5);
int delta = 0 - this.Location.Y;
if (delta < this.Height / 5 && speed < 10)
{
speed++;
T.Interval = speed;
}
if (this.Location.Y >= -padTop)
{
T.Stop();
T.Interval = 1;
speed = 1;
this.Location = new Point(this.Location.X, -padTop);
}
break;
}
}
private void SlideUp()
{
direction = Direction.Up;
T.Start();
}
private void DropDown()
{
speed = 1;
direction = Direction.Down;
T.Start();
}
}
}