C# 按钮在单击时不更改标签位置?

C# 按钮在单击时不更改标签位置?,c#,winforms,C#,Winforms,我正在创造一个类似流氓的游戏。如果有人熟悉的话,我想让它有点像“少尉”这个游戏。当我尝试制作北、东、南和西按钮时,我很难让角色移动。为什么这个按钮不改变标签的位置?有更好的方法吗 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; usin

我正在创造一个类似流氓的游戏。如果有人熟悉的话,我想让它有点像“少尉”这个游戏。当我尝试制作北、东、南和西按钮时,我很难让角色移动。为什么这个按钮不改变标签的位置?有更好的方法吗

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 Rogue_Like2
{
    public partial class Form1 : Form
    {
        public int _x;
        public int _y;

        public Form1()

        {
            InitializeComponent();

            _x = lbl_char.Location.X;
            _y = lbl_char.Location.Y;
        }

        private void btn_north_Click(object sender, EventArgs e)
        {
            _x -= 10;
        }

        private void btn_south_Click(object sender, EventArgs e)
        {
            _y += 10;
        }
    }
}

如果要移动标签,请尝试此操作

lbl_char.Location = new Point( x, y);

\u x=lbl\u char.Location.x
不会为您提供
lbl\u char.Location.x
的引用,而只提供当前值,因此您的
\u x-=10什么都不做。您可能需要执行类似于
lbl\u char.Location=new Location(lbl\u char.Location.X-10,lbl\u char.Location.Y)
Ahh,非常感谢!“lbl_char.Location=新点(lbl_char.Location.X-10,lbl_char.Location.Y);”-成功!