本文介绍了如何创建一个永远不会吸引键盘焦点的按钮的winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 winform 上有几个文本框.我也有几个按钮.现在,当我在一个这样的文本框上键入并单击一个按钮时,输入焦点从文本框中丢失,按钮获得输入键盘焦点.也就是说,当我们单击按钮时,光标从文本框中消失了.我不想要这种行为.即使单击按钮,我也希望我的文本框将光标保留在其中.实际情况是我的文本框和数字按钮只能在触摸屏上使用.

I have a few textboxes on my winform. I have a few buttons on it too. Now when I am typing on one such textbox and clicks a button, then the input focus is lost from the textbox and the button gets the input keyboard focus. That is, the cursor is lost from the textbox the moment we click the button. I dont want this behavior. I want my textbox to retain the cursor within even when I click the button.The real situation is that I am having textbox and numeric buttons to be only used from touchscreen.

推荐答案

尝试创建自己的按钮控件,继承标准控件但关闭 Selectable 样式:

Try creating your own button control that inherits from the standard one but turns off the Selectable style:

public class ButtonEx : Button {
  public ButtonEx() {
    this.SetStyle(ControlStyles.Selectable, false);
  }
}

这篇关于如何创建一个永远不会吸引键盘焦点的按钮的winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:36
查看更多