這可能是我遇到的最奇怪的(也可能是最簡單的)錯誤。我有一個ComboBox
3項。根據選定的索引,我設置了3 PictureBoxes
和標籤文本的可見性。後者的問題是:未在組合框的SelectedIndexChanged上設置標籤值(僅在一種情況下)
private void myCombo_SelectedIndexChanged(object sender, EventArgs e)
{
switch (myCombo.SelectedIndex)
{
case 0: // basic
pictureBoxBasicCampaign.Visible = true;
pictureBoxApsisCampaign.Visible = false;
pictureBoxPushCampaign.Visible = false;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that writes the recipient data into a file or another database table.";
break;
case 1: // apsis
pictureBoxBasicCampaign.Visible = false;
pictureBoxApsisCampaign.Visible = true;
pictureBoxPushCampaign.Visible = false;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that sends a newsletter or SMS message to recipients via APSIS.";
break;
case 2: // push
pictureBoxBasicCampaign.Visible = false;
pictureBoxApsisCampaign.Visible = false;
pictureBoxPushCampaign.Visible = true;
lblCampaignTypeDescription.Text = "Runs or schedules a campaign that sends a push notification to devices running an iOS or Android app.";
break;
}
}
一切工作正常!但是我的lblCampaignTypeDescription
的文本只有在SelectedIndex
爲0時纔會更改,並且我得到一個空標籤。沒有異常拋出,我的調試遍歷了lblCampaignTypeDescription.Text
。但沒有文字。案例1和2正確顯示文本。
有沒有人有過這個問題?還是我做了一些愚蠢的事情?
更新:
所有在我的項目lblCampaignTypeDescription
引用:
private MetroFramework.Controls.MetroLabel lblCampaignTypeDescription;
this.lblCampaignTypeDescription = new MetroFramework.Controls.MetroLabel();
this.metroTabPageSelectType.Controls.Add(this.lblCampaignTypeDescription);
//
// lblCampaignTypeDescription
//
this.lblCampaignTypeDescription.FontSize = MetroFramework.MetroLabelSize.Small;
this.lblCampaignTypeDescription.FontWeight = MetroFramework.MetroLabelWeight.Regular;
this.lblCampaignTypeDescription.Location = new System.Drawing.Point(121, 261);
this.lblCampaignTypeDescription.Name = "lblCampaignTypeDescription";
this.lblCampaignTypeDescription.Size = new System.Drawing.Size(700, 18);
this.lblCampaignTypeDescription.Style = MetroFramework.MetroColorStyle.Silver;
this.lblCampaignTypeDescription.TabIndex = 11;
this.lblCampaignTypeDescription.Text = "campaign_type_description";
this.lblCampaignTypeDescription.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblCampaignTypeDescription.Theme = MetroFramework.MetroThemeStyle.Light;
this.lblCampaignTypeDescription.UseStyleColors = true;
該標籤可從MetroFramework
的Winform UI庫中的自定義標籤控制。但是我一直在使用它一百萬次,這是第一次發生這種情況。
只要它應該按照設計工作。其他地方是否改變標籤上的文字? –
你可以嘗試調用lblCampaignTypeDescription.Update();我不知道爲什麼你的解決方案無法正常工作。 – Bgl86
您的交換機在使用「默認」時會更好。文本屬性在所有情況下都無法更新? – Bazinga