- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经创建了一个 WinForms 用户控件。我阅读了一些关于 GotFocus()
和 LostFocus()
事件的地方,但我的用户控件没有在“属性”窗口的“事件”部分提供这些事件。
我什至尝试输入 override
来查看这些事件处理程序是否会出现,但他们没有。我到处都找不到它们。
所以我用这些名称创建了自己的方法,然后出现以下错误:
Warning 1 'mynamespace.mycontrol.GotFocus()' hides inherited member 'System.Windows.Forms.Control.GotFocus'. Use the new keyword if hiding was intended.
这到底是怎么回事。如果 GotFocus()
已经存在,为什么我找不到它并使用它?
最佳答案
它看起来像来自 MSDN Documentation它们是从 Control 继承的,但不鼓励使用。他们希望您使用进入和离开事件。
Note The GotFocus and LostFocus events are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocus and LostFocus events are only used when updating UICues or when writing custom controls. Instead the Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events.
也就是说,您可以按照 User1718294 使用 += 的建议访问它们,或者您可以覆盖 OnGotFocus
和 OnLostFocus
事件。
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
}
关于c# - 在我的用户控件中找不到 GotFocus()/LostFocus(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13355140/
我有一个使用 WPF 的 C# ComboBox。我有在 ComboBox 的 GotFocus 被激活时执行的代码。问题是每次从 ComboBox 中进行选择时都会执行 GotFocus 事件。例如
我有一个简单的任务要完成,或者至少在外观上...... 我想处理一个窗口当前是否是 Windows 环境中当前选定窗口的事实。 我以为我只需要处理我的窗口的两个事件 LostFocus 和 GotFo
我无法通过单击在 WPF 窗口中触发 GotFocus() 事件。但如果我单击任何控件,它将被触发。 我的要求如下:我有一个主机窗口,它有一个带有两个可以托管用户控件的数据网格的视口(viewport
我是 WPF 开发的新手。 我正在使用 MVVM 模式开发一个 wpf 应用程序。我有一个“ComboBox”和一个“TextBlock”控件。将焦点放在 ComboBox 上时,Textblock
非常简单: private void textBox1_GotFocus(object sender, EventArgs e) { this.textBox1.Text = "AAA"; } 这
我已经创建了一个 WinForms 用户控件。我阅读了一些关于 GotFocus() 和 LostFocus() 事件的地方,但我的用户控件没有在“属性”窗口的“事件”部分提供这些事件。 我什至尝试输
如果另一个字段设置为特定值,我的销售订单 (SalesTable) 中有一些字段需要禁用。为了做到这一点,我覆盖了表单域上的 enter 和 gotFocus 方法(我做了两个来测试它)。代码编译,没
每当我将焦点集中到一个特定单元格时,如果该单元格包含小于 2 的值,则该单元格中的内容应乘以 60。 顺便说一句,我可以通过使用导航键或单击一个特定单元格或任何其他内容将焦点集中到一个特定单元格。 例
当特定表单打开时,当用户将焦点返回到 Access 应用程序时,我试图调用一个事件。以下事件似乎根本没有发生。 Private Sub Form_GotFocus() Call crtList
具有以下 WinForms 对话框形式,我正在处理 GotFocus MyControl 的事件: MyControl 派生自 DevExpress XtraUserControl这又源自 Micro
GotFocus 和 GotKeyboardFocus 以及类似的 LostFocus 和 LostKeyboardFocus 之间有什么区别? 很抱歉这个简单的问题,但是,我用谷歌搜索并阅读了很多博
我有一个包含 ContentControl 的 UserControl .当用户点击这个 ContentControl我要换它ContentTemplate , 使其“可编辑”(例如,而不是标签显示文
每次焦点从一个 GridViewItem 转移到另一个时,GridView GotFocus 和 LostFocus 似乎都会触发。有什么方法可以知道 GridView 作为一个整体何时获得焦点和失去
在 swift Cocoa 中,当 NSTextField 获得编辑焦点时会触发一个事件。我来自 C#,它有 GotFocus() 和 LostFocus() 事件。 对于 NSTextfield,我
我想将 GotFocus 事件添加到 Windows 窗体文本框,所以我使用了 this 中描述的方法问题;它有效,但在我运行我的应用程序几次后,这段代码自行删除,我不知道为什么。 这是不断 self
我正在使用 WM 6.5 (.NET 3.5) 为移动设备开发应用程序,但遇到以下问题: 当在我的表单中的文本框上调用 textBox.gotFocus() 事件时,我调用此文本框的 SelectAl
我想要的:当任何文本框获得焦点时,将边框颜色更改为黄色。 我尝试过的:
我想在单击(或制表符)控件时选择 MaskedTextBox 的所有内容,以便它们可以轻松替换旧内容。我尝试在 Enter 事件中调用 SelectAll(),但这根本不起作用。 我切换到使用 Got
我有一个 prism/mvvm View ,如果 View 获得或失去焦点,我想通知 ViewModel。 我想我需要将 View 的 GotFocus 绑定(bind)到 ViewModel 中的一
我有一个具有 TextBox 的应用程序。获得焦点后,我需要将日历显示为弹出窗口。 我的问题是如何显示订阅 GotFocus 事件并通过 View 模型显示日历? 最佳答案 为像这样的特定于 View
我是一名优秀的程序员,十分优秀!