c#点击一下红色按钮出现一个红色label,点击一下绿色按钮,右旁边再出现一个绿色label。
intX=10;intY=10;intSpace=20;intcol=1;intlabelWidth=40;intlabelheight=20;intlbNums=0;p...
int X = 10;
int Y = 10;
int Space = 20;
int col = 1;
int labelWidth = 40;
int labelheight = 20;
int lbNums = 0;
private void button1_Click(object sender, EventArgs e)
{
lbNums++;
Label label = new Label();
label.ForeColor = Color.Red;
label.Text = "你好" + lbNums;
label.Size = new Size(labelWidth, labelheight);
label.Location = new Point(X, Y);
this.panel1.Controls.Add(label);
X = col * (labelWidth + Space);
col++;
}
请问我应该怎么实现点击红色字体按钮出现一个红色字体的label,我再按绿色按钮的时候就会继续右边出现一个绿色字体的label.再点击红色字体按钮继续右边出现红色字体的label 展开
int Y = 10;
int Space = 20;
int col = 1;
int labelWidth = 40;
int labelheight = 20;
int lbNums = 0;
private void button1_Click(object sender, EventArgs e)
{
lbNums++;
Label label = new Label();
label.ForeColor = Color.Red;
label.Text = "你好" + lbNums;
label.Size = new Size(labelWidth, labelheight);
label.Location = new Point(X, Y);
this.panel1.Controls.Add(label);
X = col * (labelWidth + Space);
col++;
}
请问我应该怎么实现点击红色字体按钮出现一个红色字体的label,我再按绿色按钮的时候就会继续右边出现一个绿色字体的label.再点击红色字体按钮继续右边出现红色字体的label 展开
推荐于2016-09-27 · 知道合伙人软件行家
关注
展开全部
int X = 10;
int Y = 10;
int Space = 20;
int col = 1;
int labelWidth = 40;
int labelheight = 20;
int RowHeight = 30;
int lbNums = 0;
private void button1_Click(object sender, EventArgs e)
{
AddLabel(Color.Red);
}
private void AddLabel(Color color)
{
lbNums++;
if (X >= this.panel1.Width)
{
//换行
Y += RowHeight;//换一行
X = 10;
col = 1;//从新第一列
}
Label label = new Label();
label.ForeColor = color;
label.Text = "好" + lbNums;
label.Size = new Size(labelWidth, labelheight);
label.Location = new Point(X, Y);
this.panel1.Controls.Add(label);
X = col * (labelWidth + Space);
col++;
}
private void button2_Click(object sender, EventArgs e)
{
AddLabel(Color.Green);
}
追问
追答
this.panel1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panel1_Scroll);
this.panel2.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panel1_Scroll);
private void panel1_Scroll(object sender, ScrollEventArgs e)
{
if(e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
this.panel1.VerticalScroll.Value = e.NewValue;
this.panel2.VerticalScroll.Value = e.NewValue;
}
if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
{
this.panel1.HorizontalScroll.Value = e.NewValue;
this.panel2.HorizontalScroll.Value = e.NewValue;
}
}
早点结贴吧,问题不能一个接着一个。
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询