AceInfinity
Emeritus, Contributor
Haha, so I was inspired by an idea out of boredom that randomly popped into my head... And this is what I came up with. Kind of cluttered, the structure is there, but what I really had in mind, was having this as some sort of welcome interface for an app. Like the Windows 8 OS inside of a desktop application.
You'd get the welcome screen, drag it up, and your entire program would be behind it with your form and all of it's controls.
I didn't get that far though, I was fooling around with the animation for a while :)
Code:
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();
}
}
}
Have fun with it. Just another little snippet i'll share. Timer ended up being too slow on it's fastest interval, so I had to change the displacement "stepping", and with that, sometimes it would go over, so I created a bit of padding to fix that. Originally I was thinking about expanding and contracting the control. But if you were to add something to this, nothing would look right when you dragged it up, because the control is just being shrunken down, not moved up.
:beerchug2: