private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Location = new System.Drawing.Point(2, 3);
}
public partial class Form1 : Form
{
int tickX = 0;
int tickY = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.textBox1.Location = new System.Drawing.Point(28, 38);
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Location = new Point(0, 0);
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
this.textBox1.Location = new System.Drawing.Point(tickX, tickY);
tickX++;
tickY++;
}
}
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);
}
}
http://www.codeproject.com/Questions/167670/How-to-Move-the-Textbox-Control-in-C