相关疑难解决方法(0)

小组没有得到关注

我将继续在我的简单图形程序(使用C#)中编程某种键盘导航.我又一次陷入困境.

替代文字

我的问题是我想处理键盘输入以移动图层.使用鼠标移动图层已经很好地工作了,但控件没有得到焦点(此控件都没有触发KeyUp/KeyDown/KeyPress和GotFocus/LostFocus).由于我的类派生自Panel(并覆盖了几个事件),我也覆盖了上面提到的事件,但是我无法成功触发这些事件.

我想我可以设法使用Keyboard.GetState()或ProcessCmdWnd之类的东西来实现键盘响应.但是:我仍然必须知道控件何时得到关注.

是否有一种或多或少的优雅方式将此功能添加到用户控件(基于Panel)?

我在这里检查了很多线程,我可能会使用这种方法进行键盘输入.然而,焦点问题仍然存在.

非常感谢您提前获取信息!

伊戈尔.

ps:我使用VS2008在C#.NET v3.5中编程.它是Windows.Forms应用程序,而不是WPF.

c# keyboard focus panel winforms

28
推荐指数
2
解决办法
3万
查看次数

在哪里调用base.WndProc()或base.DefWndProc()?

我有一些关于覆盖Windows窗体/ NativeWindow的WndProc方法的问题.

WndProc和DefWndProc之间究竟有什么区别(编辑:我之前认为它叫做"DefaultWndProc")?我只能覆盖WndProc,但什么是DefWndProc,我可以随时调用它?

在我的重写方法中调用base.WndProc的位置?或者我应该调用DefWndProc吗?我想到了以下立场:

protected override void WndProc(ref Message m)
{
    // 1st: I call the base handler at the start, in front of my handling.
    // Are there disadvantages here?
    base.WndProc(ref m);

    switch (m.Msg)
    {
        case (int)WindowsMessage.Paint:
            // 2nd: Do whatever you want to do now. I could also place
            // base.WndProc for each message manually here, at a point I
            // can control myself. It makes the method a little messy
            // since I have several base calls …
Run Code Online (Sandbox Code Playgroud)

c# overriding base wndproc

5
推荐指数
1
解决办法
6667
查看次数

标签 统计

c# ×2

base ×1

focus ×1

keyboard ×1

overriding ×1

panel ×1

winforms ×1

wndproc ×1