0

在面板控件上的标签停靠中,我使用了以下代码:(这是用鼠标指针移动我的面板)

Point m_pntPosPanel = new Point();

private void lblMove_MouseUp(object sender, MouseEventArgs e)
{
    pnlCost.Location = new Point(e.X - m_pntPosPanel.X + pnlCosto.Location.X, e.Y - m_pntPosPanel.Y + pnlCosto.Location.Y);
    Cursor.Current = Cursors.Default;
    m_blnMouseDown = false;
}

private void lblMove_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        m_pntPosPanel.X = e.X;
        m_pntPosPanel.Y = e.Y;

        Cursor.Current = Cursors.Hand;
        m_blnMouseDown = true;
    }
}

我该如何移动该面板directional keyboard

4

1 回答 1

1

我将在控件上注册 KeyUp 事件,并按如下方式处理:

    private void lblMove_KeyUp(object server, KeyEventArgs e)
    {
          Point location = button1.Location;
          switch(e.KeyCode)
          {
            case Keys.Up: 
                location.Y = location.Y -1;
                break;
            case Keys.Down:
                location.Y = location.Y + 1;
                break;
            case Keys.Right:
                location.X = location.X + 1;
                break;
            case Keys.Left:
                location.X = location.X - 1;
                break;
          }

          button1.Location = location;
    }
于 2013-02-21T20:16:16.940 回答