111,092
社区成员




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace T395615469
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int max = 0;
private string no = "一,二,三,四,五,六,七,八,九,十,十一,十二";
public void RemoveSegment()
{
if (max > 0)
{
if (max > 2)
{
Controls["btn" + (max * 2 - 3).ToString()].Visible = true;
Controls["btn" + (max * 2 - 4).ToString()].Visible = true;
}
else if (max > 1)
{
Controls["btn" + (max * 2 - 4).ToString()].Visible = true;
}
Controls.Remove(Controls["lbl" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["lbl" + (max * 2 - 2).ToString()]);
Controls.Remove(Controls["cbo" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["cbo" + (max * 2 - 2).ToString()]);
Controls.Remove(Controls["btn" + (max * 2 - 1).ToString()]);
Controls.Remove(Controls["btn" + (max * 2 - 2).ToString()]);
max--;
}
}
public void AddSegment()
{
if (max == no.Split(',').Count())
return;
Label lbl = new Label();
lbl.Text = "第" + no.Split(',')[max] + "段";
lbl.Name = "lbl" + (max * 2).ToString();
lbl.Left = 25 + AutoScrollPosition.X;
lbl.Top = 60 + max * 40 + AutoScrollPosition.Y;
lbl.AutoSize = true;
Controls.Add(lbl);
ComboBox cbo = new ComboBox();
cbo.Items.AddRange(Enumerable.Range(0, 23).Select(x => (object)x).ToArray());
cbo.Left = 90 + AutoScrollPosition.X;
cbo.Top = 57 + max * 40 + AutoScrollPosition.Y;
cbo.Name = "cbo" + (max * 2).ToString();
Controls.Add(cbo);
lbl = new Label();
lbl.Text = "-----";
lbl.Name = "lbl" + (max * 2 + 1).ToString();
lbl.Left = 225 + AutoScrollPosition.X;
lbl.Top = 60 + max * 40 + AutoScrollPosition.Y;
lbl.AutoSize = true;
Controls.Add(lbl);
cbo = new ComboBox();
cbo.Items.AddRange(Enumerable.Range(0, 23).Select(x => (object)x).ToArray());
cbo.Left = 265 + AutoScrollPosition.X;
cbo.Top = 57 + max * 40 + AutoScrollPosition.Y;
cbo.Name = "cbo" + (max * 2 + 1).ToString();
Controls.Add(cbo);
Button btn = new Button();
btn.Text = "Add";
btn.Left = 410 + AutoScrollPosition.X;
btn.Top = 56 + max * 40 + AutoScrollPosition.Y;
btn.Name = "btn" + (max * 2).ToString();
btn.Click += new EventHandler(btn1_Click);
Controls.Add(btn);
btn = new Button();
btn.Text = "Remove";
btn.Left = 490 + AutoScrollPosition.X;
btn.Top = 56 + max * 40 + AutoScrollPosition.Y;
btn.Name = "btn" + (max * 2 + 1).ToString();
btn.Click += new EventHandler(btn2_Click);
Controls.Add(btn);
if (max == no.Split(',').Count() - 1)
{
Controls["btn" + (max * 2).ToString()].Visible = false;
Controls["btn" + (max * 2 - 1).ToString()].Visible = false;
Controls["btn" + (max * 2 - 2).ToString()].Visible = false;
}
else if (max == 0)
{
Controls["btn" + (max * 2 + 1).ToString()].Visible = false;
}
else
{
Controls["btn" + (max * 2 - 1).ToString()].Visible = false;
Controls["btn" + (max * 2 - 2).ToString()].Visible = false;
}
max++;
}
private void btn1_Click(object sender, EventArgs e)
{
AddSegment();
}
private void btn2_Click(object sender, EventArgs e)
{
RemoveSegment();
}
private void Form1_Load(object sender, EventArgs e)
{
AddSegment();
}
}
}