微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

添加 Button

如何解决添加 Button

我在 C# Visual Studio 中使用了 Winform。起初我有一个 OnKeyDown 并且它运行良好。在此之后,我在表单中添加一个按钮。我从工具箱中拖出按钮并双击它。然后它为我生成了 public void 函数

按钮现在也工作正常,但我不能再使用 KeyEvent。我需要改变什么?

protected override void OnKeyDown(KeyEventArgs e)
{
    Debug.WriteLine("hello Keyevent");
}

private void button1_Click_1(object sender,EventArgs e)
{
    Debug.WriteLine("hello button");
}

绘制方法

protected override void OnPaint(PaintEventArgs e)
{
    grafik = e.Graphics;
    using (Font font1 = new Font("Arial",20,FontStyle.Regular,GraphicsUnit.Point))
    {
        StringFormat textformat = new StringFormat()
        {
            Alignment = Stringalignment.Center,};

        Rectangle myRectangle = new Rectangle();

        for (int i = 0; i < maze.GetLength(0); i++)
        {
            for (int j = 0; j < maze.GetLength(1); j++)
            {
                string sign = char.ToString(Labyrinth[i,j]);
                myRectangle.Location = new Point(i * 30,j * 30);
                myRectangle.Size = new Size(10,10);

                grafik.DrawString(sign,font1,red,myRectangle,textformat);
            }
        }
    }
}

解决方法

我想我现在明白了。我刚用的方法:

main_obj[date[0]][date[1]][date[2]]

代替

protected override bool ProcessCmdKey(ref Message msg,Keys keyData)

我现在可以使用箭头键控制我的表单

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。