C# 为什么我的面板不显示我c应用程序中的所有按钮?
我的windows窗体应用程序中的面板没有包含我要求它显示的所有按钮。它只显示1个按钮,下面是代码C# 为什么我的面板不显示我c应用程序中的所有按钮?,c#,panel,dynamic,C#,Panel,Dynamic,我的windows窗体应用程序中的面板没有包含我要求它显示的所有按钮。它只显示1个按钮,下面是代码 private void AddAlphaButtons() { char alphaStart = Char.Parse("A"); char alphaEnd = Char.Parse("Z"); for (char i = alphaStart; i <= alphaEnd; i++)
private void AddAlphaButtons()
{
char alphaStart = Char.Parse("A");
char alphaEnd = Char.Parse("Z");
for (char i = alphaStart; i <= alphaEnd; i++)
{
string anchorLetter = i.ToString();
Button Buttonx = new Button();
Buttonx.Name = "button " + anchorLetter;
Buttonx.Text = anchorLetter;
Buttonx.BackColor = Color.DarkSlateBlue;
Buttonx.ForeColor = Color.GreenYellow;
Buttonx.Width = 30;
Buttonx.Height = 30;
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click += new System.EventHandler(this.MyButton_Click);
}
}
private void addalphabutions()
{
char alphaStart=char.Parse(“A”);
char alphaEnd=char.Parse(“Z”);
对于(char i=alphaStart;i来说,它们不是都将处于相同的位置吗
尝试设置Buttonx.Location=新点(100200);
(但是不同的按钮有不同的点)它们不是都在同一个位置吗
尝试设置Buttonx.Location=新点(100200);
(但不同的按钮有不同的点)您可以使用FlowLayoutPanel,该面板将为您处理布局,或者您需要自己跟踪位置,或者看起来像这样:
private void AddAlphaButtons()
{
char alphaStart = Char.Parse("A");
char alphaEnd = Char.Parse("Z");
int x = 0; // used for location info
int y = 0; // used for location info
for (char i = alphaStart; i <= alphaEnd; i++)
{
string anchorLetter = i.ToString();
Button Buttonx = new Button();
Buttonx.Name = "button " + anchorLetter;
Buttonx.Text = anchorLetter;
Buttonx.BackColor = Color.DarkSlateBlue;
Buttonx.ForeColor = Color.GreenYellow;
Buttonx.Width = 30;
Buttonx.Height = 30;
// set button location
Buttonx.Location = new Point(x, y);
x+=30;
if(x > panel1.Width - 30)
{
x = 30;
y+=30;
}
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click += new System.EventHandler(this.MyButton_Click);
}
}
private void addalphabutions()
{
char alphaStart=char.Parse(“A”);
char alphaEnd=char.Parse(“Z”);
int x=0;//用于位置信息
int y=0;//用于位置信息
用于(字符i=字母开始;i面板1.宽度-30)
{
x=30;
y+=30;
}
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click+=newsystem.EventHandler(this.MyButton\u Click);
}
}
您可以使用FlowLayoutPanel,它将为您处理布局,或者您需要自己跟踪位置,或者看起来像这样:
private void AddAlphaButtons()
{
char alphaStart = Char.Parse("A");
char alphaEnd = Char.Parse("Z");
int x = 0; // used for location info
int y = 0; // used for location info
for (char i = alphaStart; i <= alphaEnd; i++)
{
string anchorLetter = i.ToString();
Button Buttonx = new Button();
Buttonx.Name = "button " + anchorLetter;
Buttonx.Text = anchorLetter;
Buttonx.BackColor = Color.DarkSlateBlue;
Buttonx.ForeColor = Color.GreenYellow;
Buttonx.Width = 30;
Buttonx.Height = 30;
// set button location
Buttonx.Location = new Point(x, y);
x+=30;
if(x > panel1.Width - 30)
{
x = 30;
y+=30;
}
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click += new System.EventHandler(this.MyButton_Click);
}
}
private void addalphabutions()
{
char alphaStart=char.Parse(“A”);
char alphaEnd=char.Parse(“Z”);
int x=0;//用于位置信息
int y=0;//用于位置信息
用于(字符i=字母开始;i面板1.宽度-30)
{
x=30;
y+=30;
}
this.panelButtons.Controls.Add(Buttonx);
//Buttonx.Click+=newsystem.EventHandler(this.MyButton\u Click);
}
}
为什么否决?这可能是一个初学者问题,但它包含足够的信息和代码,能够找到可能的问题(就像Paul很快做的那样)。为什么否决?这可能是一个初学者问题,但它包含足够的信息和代码,能够找到可能的问题(就像Paul很快做的那样).成功了!!非常感谢,你是真正的程序员!!非常感谢,你是真正的程序员