C# 在Windows窗体中获取聚焦组件
我需要使用Windows窗体和.NETFramework2.0-C#或VisualBasic来获取当前关注的组件 我有一个事件,在某个时刻,接收到一条文本,它需要将该文本放入C# 在Windows窗体中获取聚焦组件,c#,winforms,compact-framework,.net-2.0,windows-ce,C#,Winforms,Compact Framework,.net 2.0,Windows Ce,我需要使用Windows窗体和.NETFramework2.0-C#或VisualBasic来获取当前关注的组件 我有一个事件,在某个时刻,接收到一条文本,它需要将该文本放入文本框组件中。但它不仅仅是一个组件。必须是重点组件。我的情况是:我正在处理从硬件读取器获取字符串的低级应用程序和硬件通信,我必须将此文本附加到聚焦的文本框中 _device = new Device(Device.AvailableDevices[0].DeviceName); _leitor = new Reader(_d
文本框
组件中。但它不仅仅是一个组件。必须是重点组件。我的情况是:我正在处理从硬件读取器获取字符串的低级应用程序和硬件通信,我必须将此文本附加到聚焦的文本框中
_device = new Device(Device.AvailableDevices[0].DeviceName);
_leitor = new Reader(_device);
_leitorDados = new ReaderData(ReaderDataTypes.Text, ReaderDataLengths.MaximumLabel);
_leitor.Actions.Enable();
_leitor.Actions.Read(_leitorDados);
_leitor.StatusNotify += delegate
{
if (_leitorDados.Text == String.Empty) return;
MessageBox.Show(_leitorDados.Text);
_leitorDados = new ReaderData(ReaderDataTypes.Text, ReaderDataLengths.MaximumLabel);
_leitor.Actions.Read(_leitorDados);
};
我的文本可以在leitorDados.text中找到,当我收到事件时,我需要
focusedControl.Text=\u leitorDados.Text代码>
但是我使用的是一个非常有限的.NETFramework版本,即2.0,我没有太多的可能性来实现它。
提前谢谢
- 这个问题与堆栈溢出中的其他问题不同,因为它涉及的是一个确定版本的.NET Framework,它没有执行此操作所需的资源
- .NETFramework2.0中没有
this.ActiveControl
。与Win CE一起
您应该使用递归方法来执行此操作。试试这个:
public static Control FindFocusedComponent(Control control)
{
foreach (Control child in control.Controls)
{
if (child.Focused)
{
return child;
}
}
foreach (Control child in control.Controls)
{
Control focused = FindFocusedComponent(child);
if (focused != null)
{
return focused;
}
}
return null;
}
我想没有.NET2.5吧。还可以用框架和Windows的哪个版本标记您的问题。我搞砸了。是.NET2.0。我现在在酒店登记了。谢谢你。根据它是支持的。受支持的平台有Windows CELet me截图…可能与