我有一个应用程序,其中我有内部,以便区分它们许多按键,我创建一个类中,我把这个: 我不得不说,我的按钮是在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