私はそれらを区別するために内部に多くのボタンがあるアプリケーションを持っています。 私のボタンが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ループスルーボタンのタイプのエラーをキャストすることができません) – Sinatr
検索するボタンの位置が明確ではありません。これは、FlowLayoutPanelコントロールコレクションまたはフォームコントロールコレクション内に含まれていますか? – Steve
私のボタンはフローパネル内にあります – Sheva07