gpt4 book ai didi

c# - 在我的自定义文本框中读取表单中的所有文本框

转载 作者:行者123 更新时间:2023-11-30 12:11:02 27 4
gpt4 key购买 nike

我在 winform 项目中使用自定义 TextBox,我在自定义 TextBox 中添加了这个属性:

private TextBox _nextControl;

public TextBox NextControl
{
set { _nextControl=value; }
get { return _nextControl; }
}

我的自定义 TextBox 属性中包含 2 个 TextBox(textBox1 和 textBox2),属性为 NextControl;我可以在表单中看到所有 TextBoxes:

enter image description here

在这种情况下,属性 NextControl 将在我的表单中显示所有 TextBox 以选择我的下一个控件。

但是当我想在我的新 WPF 服装 TextBox 中做同样的事情时,我得到了同样的条件(2 TextBoxes,文本框 1 和文本框 2):

enter image description here

为什么我没有得到相同的结果?以及如何在我的 WPF 项目中执行此操作?


更新:

有关更多说明,在我的 winform 项目中,我使用属性 NextControl 从 UI 属性中选择下一个控件。

protected override void OnKeyDown(KeyEventArgs e) 
{
if(e.KeyCode==Keys.Down)
// select the next TextBox chosen in this TextBox option
_nextControl.Select();
}

因为我已经可以在 UI 中选择下一个 TextBox 的名称,我不想用额外的代码来做到这一点

但这在 WPF 中不起作用:我在属性 NextControl 的窗口中看不到我的 TextBoxes 的名称(如果我选择属性类型 = 文本框)。

p.s. 我的自定义 TextBox 继承自 System.Windows.Controls.TextBox


更新:

我上传了一个带有自定义 TextBox 的 winform 项目 [here]我想要的示例项目的 WPF 可以表现相同。

我已经更新了这个示例的链接。

最佳答案

快速查看您的代码告诉我您的 Windows 窗体用户控件与 WPF 不兼容,特别是 Windows 窗体中的 keyDown 事件解析参数“KeyEventArgs e”,这是一个 System.Windows.Form.Key 但 WPF 解析“System.Windows.Input.Key”和 WPF 没有用于文本框的“Select() 方法。此外,WPF 以非常不同的方式将控件绑定(bind)到 WinForm,因此您的 WinFromuserControl 将无法在 WPF 表单中工作。

如果您想在 WPF 表单中使用类似的行为,则必须编写 WPF 支持的表单。

关于c# - 在我的自定义文本框中读取表单中的所有文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16338924/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com