gpt4 book ai didi

c# - 使用按钮向右和向左 move 面板单击 C#

转载 作者:太空狗 更新时间:2023-10-29 22:11:55 25 4
gpt4 key购买 nike

我正在使用 WinForms。在我的表单中,我有一个带有 move 面板按钮的面板。例如,向上和向下按钮向上或向下 move 面板。我很难用相应的按钮左右 move 面板。我做错了什么?

    private void Up_btn_Click(object sender, EventArgs e)
{
if (panel1.Location.Y > -2000)
{
panel1.Location = new Point(panel1.Location.X, panel1.Location.Y - 80);
}
}

private void Down_btn_Click(object sender, EventArgs e)
{
if (panel1.Location.Y < 720)
{
panel1.Location = new Point(panel1.Location.X, panel1.Location.Y + 80);
}
}

private void Left_btn_Click(object sender, EventArgs e)
{
if (panel1.Location.X < 720)
{
panel1.Location = new Point(panel1.Location.Y , panel1.Location.X + +55);
}
}

private void Right_btn_Click(object sender, EventArgs e)
{
if (panel1.Location.X < 720)
{
panel1.Location = new Point(panel1.Location.Y, panel1.Location.X -55);
}
}

enter image description here

最佳答案

在您的最后两种方法中,x 和 y 的顺序不正确。

向左 move ,你应该减少X :

panel1.Location = new Point(panel1.Location.X - 55, panel1.Location.Y);

要向右 move ,您应该增加X :

panel1.Location = new Point(panel1.Location.X + 55,  panel1.Location.Y , ); 

我还猜测您是否用完了 >-y 的标准向下 <y ,可能你需要这样的左右逻辑 >-x<x .

关于c# - 使用按钮向右和向左 move 面板单击 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34583851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com