提问者:小点点

保存4个鼠标位置


嗨,我想节省4个鼠标位置,当我点击按钮。

如下所示:ButtonClick->1.mouseClick/保存鼠标位置->2.mouseClick/保存鼠标位置.....

private void button2_Click_1(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox4.Text, out parsedValue))
            {
                MessageBox.Show("Wpsiz liczbe");
                return;
            }
            else
            {
                iset = int.Parse(textBox3.Text);
                ms = int.Parse(textBox4.Text);

                MouseDownFunction();
               
            }
        }

private void MouseDownFunction(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                eqhelmetx = MousePosition.X;
                eqhelmety = MousePosition.Y;
                if (e.Button == MouseButtons.Left)
                {
                    eqchestx = MousePosition.X;
                    eqchesty = MousePosition.Y;
                    if (e.Button == MouseButtons.Left)
                    {
                        eqleginsx = MousePosition.X;
                        eqleginsy = MousePosition.Y;
                        if (e.Button == MouseButtons.Left)
                        {
                            eqbootsx = MousePosition.X;
                            eqbootsy = MousePosition.Y;
                        }
                    }
                }
            }
        }```
I tried but it doesn't work. Thanks for any help

共1个答案

匿名用户

    List<Point> MousePositions = new List<Point>(); // list for saving mouse positions
    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        if (MousePositions.Count == 4) 
            MousePositions.RemoveAt(0); // for saving last 4 positions
        MousePositions.Add(e.Location); // when clicking form saving mouse location
    }
    private void button1_Click(object sender, EventArgs e)
    {
        foreach (var item in MousePositions)
            MessageBox.Show(item.ToString()); // showing mouse positions
    }