Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在windows窗体应用程序中启用或重新启用文本框,或者为什么我的tbx.enable=true;代码不起作用?(C#)_C#_Winforms_Controls_Wpf Controls - Fatal编程技术网

如何在windows窗体应用程序中启用或重新启用文本框,或者为什么我的tbx.enable=true;代码不起作用?(C#)

如何在windows窗体应用程序中启用或重新启用文本框,或者为什么我的tbx.enable=true;代码不起作用?(C#),c#,winforms,controls,wpf-controls,C#,Winforms,Controls,Wpf Controls,我在以下代码中有一个多行文本框(tbxrementertext),它没有响应我的请求,包括tbxrementertext.Enabled=true,即使尝试将其包含在多个其他位置。在设计器属性列表中,我是否将启用属性设置为true或false没有区别。试图刷新控件,或者我想尝试的任何其他操作都不起作用。以下是适用的代码: private void EditEntry_Load(object sender, EventArgs e) { EntryType.Entries currentTyp

我在以下代码中有一个多行文本框(
tbxrementertext
),它没有响应我的请求,包括
tbxrementertext.Enabled=true,即使尝试将其包含在多个其他位置。在设计器属性列表中,我是否将
启用
属性设置为true或false没有区别。试图刷新控件,或者我想尝试的任何其他操作都不起作用。以下是适用的代码:

private void EditEntry_Load(object sender, EventArgs e) {
  EntryType.Entries currentTypeEdited = new EntryType.Entries();

  if (mainForm.alarmCLB.SelectedIndex != -1) {
    currentTypeEdited = EntryType.Entries.Alarm;
  } else if (mainForm.reminderCLB.SelectedIndex != -1) {
    currentTypeEdited = EntryType.Entries.Reminder;
  } else {
    currentTypeEdited = EntryType.Entries.Timer;

    //lets change the controls accordingly
    //(no event handler to remove for the existing dtp
    this.Controls.Remove(dtpActiveAt);

    //change existing label
    lblRingAt.Text = "Duration:";

    //set up new control properties

    /* MUCH dynamic insertion of controls removed here for brevity;
     * -+=this is in part of the above if/else branch not used for the
     *    EntryType.Entries.Reminder, which is where my issue lies=+-  */

    this.Controls.Add(nudTmrHrs);
    this.Controls.Add(lblTmrHours);
    this.Controls.Add(nudTmrMin);
    this.Controls.Add(lblTmrMinutes);
    this.Controls.Add(nudTmrSec);
    this.Controls.Add(lblTmrSeconds);
  }

  switch (currentTypeEdited) {
    case EntryType.Entries.Alarm:
      //edit our alarm entry heah
      tbxReminderText.Text = "unavailable";
      tbxReminderText.Enabled = false;
      tbxName.Text =
        HeadsUp.activeAlarms[mainForm.alarmCLB.SelectedIndex].Name;
      dtpActiveAt.Value =
        HeadsUp.activeAlarms[mainForm.alarmCLB.SelectedIndex].ActiveAt;

      break;
    case EntryType.Entries.Timer:
      //edit timer heah
      tbxReminderText.Text = "unavailable";
      tbxReminderText.Enabled = false;
      tbxName.Text =
        HeadsUp.activeTimers[mainForm.timerCLB.SelectedIndex].Name;
      //okay the following isn't a DTP, it's a 3 number field; we're
      //going to have to handle this one differently, hopefully not with
      //a completely different form
      /*dtpActiveAt.Value =
        HeadsUp.activeTimers[mainForm.timerCLB.SelectedIndex].remaining*/

      break;
    case EntryType.Entries.Reminder:
      //reminder tiem
      tbxReminderText.Text =
        HeadsUp.activeReminders[mainForm.reminderCLB.SelectedIndex].Msg;
      tbxReminderText.Enabled = true;
      tbxName.Text =
        HeadsUp.activeReminders[mainForm.reminderCLB.SelectedIndex].Name;
      dtpActiveAt.Value =
        HeadsUp.activeReminders[
          mainForm.reminderCLB.SelectedIndex].ActiveAt;

      break;
  }
}
如块注释内联中所述,问题在于当
mainForm.rementerclb.SelectedIndex!=-1
(已验证它正在执行此分支),并且在开关/案例块中,当
currentTypeEdited=EntryType.Entries.Remembers时处于活动状态

我在谷歌上搜索了很多,但我没有发现任何类似的东西。我猜我在某个地方犯了一个愚蠢的错误,我只是没有在代码审查中看到它。。。有谁能帮我指出我犯的错误、指向适用资源的指针(我已经看过MSDN上的控件。*等),或者让我知道我应该包括哪些其他信息以便更好地进行故障排除


非常感谢您的帮助。

很可能父容器已将属性Enabled设置为false。未启用父容器时,即使您尝试将其设置为true,也不会启用子容器

编辑


尝试在监视窗口中检查
tbxrementertext.Parent.Enabled
属性值,并在将
tbxrementertext.Enabled
设置为true之前检查其值。

是否尝试过在
tbxrementertext.Enabled=true的调试器中设置断点以确保在预定时间命中它?