gpt4 book ai didi

C# Gui 设置 control.Enabled 为 false 触发 OnClick 事件?

转载 作者:行者123 更新时间:2023-12-04 06:56:05 27 4
gpt4 key购买 nike

由于一些非常奇怪的原因,当我在一个小 GUI 上的一个简单文本框上将 .Enabled 属性设置为 false 时,它​​会触发一个单选按钮 OnClick 事件并导致很多问题。

我已经断点了 txtBox.Enabled = false;在跨过或进入它之后,我直接跳到单选按钮控件的 OnClick 事件

这是发生的调用堆栈:

TestGUI.exe!TestGUI.frmMain.radiobuttonClicked(object sender = {Text = "Download Single Episode" Checked = true}, System.EventArgs e = {System.EventArgs}) Line 67 C# System.Windows.Forms.dll!System.Windows.Forms.Control.OnClick(System.EventArgs e) + 0x70 bytes System.Windows.Forms.dll!System.Windows.Forms.RadioButton.OnClick(System.EventArgs e) + 0x27 bytes System.Windows.Forms.dll!System.Windows.Forms.RadioButton.OnEnter(System.EventArgs e = {System.EventArgs}) + 0x3e bytes System.Windows.Forms.dll!System.Windows.Forms.Control.NotifyEnter() + 0x20 bytes System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.UpdateFocusedControl() + 0x195 bytes System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.AssignActiveControlInternal(System.Windows.Forms.Control value = {Text = "Download Single Episode" Checked = true}) + 0x54 bytes System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.ActivateControlInternal(System.Windows.Forms.Control control, bool originator = false) + 0x76 bytes System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.SetActiveControlInternal(System.Windows.Forms.Control value = {Text = "Download Single Episode" Checked = true}) + 0x73 bytes System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.SetActiveControl(System.Windows.Forms.Control ctl) + 0x33 bytes System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.ActiveControl.set(System.Windows.Forms.Control value) + 0x5 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.Select(bool directed, bool forward) + 0x1b bytes System.Windows.Forms.dll!System.Windows.Forms.Control.SelectNextControl(System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) + 0x7b bytes System.Windows.Forms.dll!System.Windows.Forms.Control.SelectNextControlInternal(System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) + 0x4a bytes System.Windows.Forms.dll!System.Windows.Forms.Control.SelectNextIfFocused() + 0x61 bytes System.Windows.Forms.dll!System.Windows.Forms.Control.Enabled.set(bool value) + 0x42 bytes



我勒个去?

这与我订阅事件的方式无关吗?
this.radioBtnMultipleDownload.Click += radiobuttonClicked; this.radioBtnSingleDownload.Click += radiobuttonClicked; this.radioCustomUrl.Click += radiobuttonClicked;

最佳答案

调用堆栈的倒数第二行:

System.Windows.Forms.dll!System.Windows.Forms.Control.SelectNextIfFocused() + 0x61 bytes



显然, RadioButton火灾 OnClicked在其 OnEnter ,从其 UpdateFocusedControl 触发,这是因为这是下一个控件。您可以尝试调用 Control.Focus()TextBox 之前你想获得关注的其他事情被禁用,因此 SelectNextIfFocused()不会做任何事情,即:
dummyTextBox.Focus();
txtBox.Enabled = false;

关于C# Gui 设置 control.Enabled 为 false 触发 OnClick 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2557410/

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