• <tfoot id='wWF6h'></tfoot>

      <small id='wWF6h'></small><noframes id='wWF6h'>

      1. <i id='wWF6h'><tr id='wWF6h'><dt id='wWF6h'><q id='wWF6h'><span id='wWF6h'><b id='wWF6h'><form id='wWF6h'><ins id='wWF6h'></ins><ul id='wWF6h'></ul><sub id='wWF6h'></sub></form><legend id='wWF6h'></legend><bdo id='wWF6h'><pre id='wWF6h'><center id='wWF6h'></center></pre></bdo></b><th id='wWF6h'></th></span></q></dt></tr></i><div id='wWF6h'><tfoot id='wWF6h'></tfoot><dl id='wWF6h'><fieldset id='wWF6h'></fieldset></dl></div>

      2. <legend id='wWF6h'><style id='wWF6h'><dir id='wWF6h'><q id='wWF6h'></q></dir></style></legend>
          <bdo id='wWF6h'></bdo><ul id='wWF6h'></ul>

        面板没有得到焦点

        Panel not getting focus(面板没有得到焦点)
        • <bdo id='egZ7I'></bdo><ul id='egZ7I'></ul>
              <legend id='egZ7I'><style id='egZ7I'><dir id='egZ7I'><q id='egZ7I'></q></dir></style></legend>

            • <small id='egZ7I'></small><noframes id='egZ7I'>

                <tbody id='egZ7I'></tbody>
                <i id='egZ7I'><tr id='egZ7I'><dt id='egZ7I'><q id='egZ7I'><span id='egZ7I'><b id='egZ7I'><form id='egZ7I'><ins id='egZ7I'></ins><ul id='egZ7I'></ul><sub id='egZ7I'></sub></form><legend id='egZ7I'></legend><bdo id='egZ7I'><pre id='egZ7I'><center id='egZ7I'></center></pre></bdo></b><th id='egZ7I'></th></span></q></dt></tr></i><div id='egZ7I'><tfoot id='egZ7I'></tfoot><dl id='egZ7I'><fieldset id='egZ7I'></fieldset></dl></div>
              • <tfoot id='egZ7I'></tfoot>

                1. 本文介绍了面板没有得到焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我将继续在我的简单图形程序(使用 C#)中编写某种键盘导航.我又遇到了麻烦.

                  I am continuing to program some kind of keyboard navigation in my simple graphic program (using C#). And I ran into trouble once again.

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

                  My problem is that I want to process the keyboard input to move a layer around. Moving the layer with the mouse already works quite well, yet the control doesn't get the focus (neither KeyUp/KeyDown/KeyPress nor GotFocus/LostFocus is triggered for this control). Since my class derives from Panel (and overwrites a couple of events), I've also overwritten the events mentioned above, but I can't succeed in getting those events triggered.

                  我想我可以使用 Keyboard.GetState() 或 ProcessCmdWnd 之类的东西来实现键盘响应.但是:我仍然必须能够判断控件何时获得焦点.

                  I think I could manage to implement keyboard response either using something like Keyboard.GetState() or ProcessCmdWnd or something. However: I still have to be able to tell when the control got the focus.

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

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

                  I've checked many threads in here and I might use this approach for keyboard input. The focus problem however still remains.

                  非常感谢您提前提供信息!

                  Thank you very much for information in advance!

                  伊戈尔.

                  p.s.:我正在使用 VS2008 在 C# .NET v3.5 中编程.这是一个 Windows.Forms 应用程序,不是 WPF.

                  p.s.: I am programming in C# .NET v3.5, using VS2008. It's a Windows.Forms application, not WPF.

                  推荐答案

                  Panel 类被设计为容器,它避免了获取焦点,因此子控件将始终获取它.你需要做一些手术来解决这个问题.我还在 KeyDown 事件中输入了代码以获取光标击键:

                  The Panel class was designed as container, it avoids taking the focus so a child control will always get it. You'll need some surgery to fix that. I threw in the code to get cursor key strokes in the KeyDown event as well:

                  using System;
                  using System.Drawing;
                  using System.Windows.Forms;
                  
                  class SelectablePanel : Panel {
                      public SelectablePanel() {
                          this.SetStyle(ControlStyles.Selectable, true);
                          this.TabStop = true;
                      }
                      protected override void OnMouseDown(MouseEventArgs e) {
                          this.Focus();
                          base.OnMouseDown(e);
                      }
                      protected override bool IsInputKey(Keys keyData) {
                          if (keyData == Keys.Up || keyData == Keys.Down) return true;
                          if (keyData == Keys.Left || keyData == Keys.Right) return true;
                          return base.IsInputKey(keyData);
                      }
                      protected override void OnEnter(EventArgs e) {
                          this.Invalidate();
                          base.OnEnter(e);
                      }
                      protected override void OnLeave(EventArgs e) {
                          this.Invalidate();
                          base.OnLeave(e);
                      }
                      protected override void OnPaint(PaintEventArgs pe) {
                          base.OnPaint(pe);
                          if (this.Focused) {
                              var rc = this.ClientRectangle;
                              rc.Inflate(-2, -2);
                              ControlPaint.DrawFocusRectangle(pe.Graphics, rc);
                          }
                      }
                  }
                  

                  这篇关于面板没有得到焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                  • <legend id='vY5O7'><style id='vY5O7'><dir id='vY5O7'><q id='vY5O7'></q></dir></style></legend>

                      <tbody id='vY5O7'></tbody>
                      <tfoot id='vY5O7'></tfoot>

                            <bdo id='vY5O7'></bdo><ul id='vY5O7'></ul>
                          • <i id='vY5O7'><tr id='vY5O7'><dt id='vY5O7'><q id='vY5O7'><span id='vY5O7'><b id='vY5O7'><form id='vY5O7'><ins id='vY5O7'></ins><ul id='vY5O7'></ul><sub id='vY5O7'></sub></form><legend id='vY5O7'></legend><bdo id='vY5O7'><pre id='vY5O7'><center id='vY5O7'></center></pre></bdo></b><th id='vY5O7'></th></span></q></dt></tr></i><div id='vY5O7'><tfoot id='vY5O7'></tfoot><dl id='vY5O7'><fieldset id='vY5O7'></fieldset></dl></div>

                            <small id='vY5O7'></small><noframes id='vY5O7'>