当我拖动表单时,我想实时获取form1位置。 由于表单是透明的,我只能将其拖到它的边框上。
我试过了:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Form_Location
{
public partial class Form1 : Form
{
private Point MouseDownLocation;
public Form1()
{
InitializeComponent();
BackColor = Color.LightGreen;
TransparencyKey = Color.LightGreen;
this.TopMost = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
MouseDownLocation = e.Location;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Point p = e.Location;
}
}
}
}
首先这段代码不正确我尝试了表格不重复的时候它没有在拖动表格时给我这个位置。
第二个问题是当表单透明时,您无法在表单上获得点击事件。所以事件/ s Form1_MouseDown和Form1_MouseMove不起作用。
我希望在实时拖动表单的同时获取form1位置的X和Y.