我有一個應用程序,其中我有內部,以便區分它們許多按鍵,我創建一個類中,我把這個: 我不得不說,我的按鈕是在FlowLayoutPanel。無法轉換類型的對象「System.Windows.Forms.FlowLayoutPanel」到「System.Windows.Forms.Button C#
public static void SetButtonPos(Form f1,FlowLayoutPanel fk)
{
foreach (Button c in f1.Controls)
{
if(c.Name.Contains("BTN_Menu"))
{
c.Size= new Size(247, 45);
c.BackColor = ColorTranslator.FromHtml("#373737");
c.ForeColor = ColorTranslator.FromHtml("#FFFFFF");
c.FlatStyle = FlatStyle.Flat;
c.FlatAppearance.BorderSize = 0;
c.TextAlign = ContentAlignment.MiddleLeft;
c.TextImageRelation = TextImageRelation.ImageBeforeText;
c.Height = 45;
c.Width = fk.Width - 6;
}
}
}
但是我在標題中出現了錯誤,你有什麼想法嗎?
無法轉換類型 'System.Windows.Forms.FlowLayoutPanel' 的目標,以「System.Windows.Forms.Button
謝謝。
的可能的複製[走走無法投類型的對象,通過Button控件上的表單試圖循環時,錯誤](HTTP: //stackoverflow.com/questions/28468613/ge tting-unable-cast-object-of-type-error-when-trying-to-loop-through-button) – Sinatr
目前還不清楚你正在搜索的按鈕位於何處。它包含在FlowLayoutPanel控件集合中還是在表單控件集合中? – Steve
我的按鈕是flowpanel – Sheva07