I'm trying to move my form around by using the left, right, up & down key on the keyboard, but nothing happens.
Here is the code i'm trying:
Here is the code i'm trying:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SC1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) { this.Left += e.X - lastPoint.X; this.Top += e.Y - lastPoint.Y; }
}
Point lastPoint;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
lastPoint = new Point(e.X, e.Y);
}
//Move form to the Right
private void RightButton_Click(object sender, EventArgs e)
{
this.Location = new Point(this.Location.X + 10, this.Location.Y);
}
//Move form to the left:
private void LeftButton_Click(object sender, EventArgs e)
{
this.Location = new Point(this.Location.X - 10, this.Location.Y);
}
//Move form up:
private void UpButton_Click(object sender, EventArgs e)
{
this.Location = new Point(this.Location.X, this.Location.Y - 10);
}
//Move form down:
private void DownButton_Click(object sender, EventArgs e)
{
this.Location = new Point(this.Location.X, this.Location.Y + 10);
}
}
}
Last edited: