如何创建具有永远不会吸引键盘焦点按钮一个winform [英] How to create a winform with buttons that will never attract keyboard focus

查看:402
本文介绍了如何创建具有永远不会吸引键盘焦点按钮一个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.

推荐答案

尝试创建自己的按钮控制,是这样的:

Try creating your own button control, like this:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆