Hey just use following code.
Take a textBox control at your Form, make a mouse move event for Form eg. (Form1_MouseMove)
Note you can move textBox in any direction just keep mouse at any one edge like left, right, top or down. If you keep mouse at left end of textBox just move mouse at right direction..
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X == textBox1.Location.X - 1 && (e.Y >= textBox1.Location.Y - 1 && e.Y <= textBox1.Location.Y + textBox1.Height + 1))
{
textBox1.SetBounds(textBox1.Location.X + 5, textBox1.Location.Y, 75, 23);
}
if (e.X == textBox1.Location.X + textBox1.Width + 1 && (e.Y >= textBox1.Location.Y - 1 && e.Y <= textBox1.Location.Y + textBox1.Height + 1))
{
textBox1.SetBounds(textBox1.Location.X - 5, textBox1.Location.Y, 75, 23);
}
if (e.Y == textBox1.Location.Y - 1 && (e.X >= textBox1.Location.X - 1 && e.X <= textBox1.Location.X + textBox1.Width + 1))
{
textBox1.SetBounds(textBox1.Location.X, textBox1.Location.Y + 5, 75, 23);
}
if (e.Y == textBox1.Location.Y + textBox1.Height + 1 && (e.X >= textBox1.Location.X - 1 && e.X <= textBox1.Location.X + textBox1.Width + 1))
{
textBox1.SetBounds(textBox1.Location.X, textBox1.Location.Y - 5, 75, 23);
}
if (textBox1.Location.X >= this.Width - textBox1.Width - 1)
{
textBox1.SetBounds(1, textBox1.Location.Y, 75, 23);
}
if (textBox1.Location.X <= 1)
{
textBox1.SetBounds(textBox1.Location.X + textBox1.Width + 1, textBox1.Location.Y, 75, 23);
}
}