OK 여기에 내가 한 것과 세로로 설정된 값이 레이블에 복사되지만 가로로 표시됩니다. 한 열/행만 가능합니다. 그래서 여기 텍스트 상자의 값을 레이블 배열로 복사하는 방법은 무엇입니까?
public partial class Form1 : Form
{
private Label l;
private Button bStart;
private TextBox txtVnes;
private Label[] pole;
public Form1()
{
InitializeComponent();
bStart = new Button();
bStart.Location = new Point(240, 165);
bStart.Width = 75;
bStart.Height = 25;
bStart.Text = "START";
txtVnes = new TextBox();
txtVnes.Location = new Point(240, 10);
txtVnes.Width = 160;
txtVnes.Height = 130;
txtVnes.Multiline = true;
int a = 0;
pole = new Label[42];
for (int i = 1; i <= 6; i++)
{
for (int j = 1; j <= 7; j++)
{
l = new Label();
l.Name = "label" + i.ToString() + j.ToString();
l.Text = "Z";
l.Width = 20;
l.Height = 20;
l.TextAlign = ContentAlignment.MiddleCenter;
l.Parent = this;
l.BackColor = Color.FromArgb(100, 149, 237);
l.Location = new Point(10 + (j - 1) * 25, 15 + (i - 1) * 25);
pole[a] = l;
this.Controls.Add(l);
a++;
}
}
this.Controls.Add(bStart);
this.Controls.Add(txtVnes);
bStart.Click += new EventHandler(bStart_Click);
}
private void bStart_Click(object sender, EventArgs e)
{
Regex regex = new Regex(@"^(\s)*(\d){6}\d(\s)*$");
bool isValid = true;
string[] ts = txtVnes.Text.Split(new string[] { "\r\n" },
StringSplitOptions.RemoveEmptyEntries);
if (ts == null || ts.Length < 1 || ts.Length > 6)
{
MessageBox.Show("Not valid");
}
else
{
foreach (string t in ts)
{
if (regex.IsMatch(t) == false)
{
MessageBox.Show("Not valid");
break;
}
}
}
if (isValid)
{
for (int i = 0; i < 6; i++)
{
if (i < ts.Length && regex.IsMatch(ts[i]))
{
pole[i].Text = ts[i];
}
else
{
pole[i].Text = "not valid";
}
}
}
}
문제입니다 : 내가 버튼 bStart 하나의 값이 복사 및 라벨의 배열에서 하나 라베에서 교체를 클릭합니다. 이것은 다음과 같이 작동합니다 : 사용자가 bStart 버튼을 클릭하면 txtVnes 텍스트 상자의 모든 값을 레이블 배열의 각 레이블에 복사해야합니다. 모든 레이블에는 텍스트 "Z"가 있으며 단추를 클릭 한 후 텍스트 상자의 값으로 변경해야합니다. 당신이 볼 수 있듯이
l.Text = txtVnes.Text;
값을 복사하는 데 사용되지만 작동하지 않습니다. 네가 도와 준다면 고마워, 고마워!
모든 관련 코드를 표시하십시오. 관련 코드 만 표시하십시오. 우리가 볼 필요가있는 부분이 있지만 당신은 그 부분을 우리에게 보여주지 않습니다. 그리고 당신은 우리가 정말로 보지 않아도되는 부분을 우리에게 보여주고 있습니다. –
두 코드 부분 간의 관계가 표시되지 않습니다. –