请问在文本框中输入行列,点击按钮怎么实现与输入相一致的行列label控件?
解决方案 »
- C#引用C++的问题,指针问题....
- sql server 2008中数据库的麻烦
- 指定控件名称时,前面加不加 this,有区别吗?好像加不加都行呀?
- 求助论坛自动发帖的思路最好有例子!!!!!!
- 对文本的显示的规定
- C# winForm 如何在运行之后窗体上的控件可以调整大小 100分~
- c#如何取得动态网页信息
- winform 中datagrid 排序问题
- 在C# WEB里打开窗体的问题?
- SqlCommandBuilder的十分之诡异,匪夷所思的错误问题~~~~我快疯了
- 有关 循环与跳转 的一个菜鸟题
- 有谁用Wise Installation System 9.02做过打包的,求教程或者帮助说明!(有结果另外加分)
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 WindowsFormsApplication21
{
public partial class Form1 : Form
{
int TotalCount = 0; public Form1()
{
InitializeComponent(); TextBox TB = new TextBox();
TB.Parent = this;
TB.TextChanged += new EventHandler(TB_TextChanged);
} void TB_TextChanged(object sender, EventArgs e)
{
int Count;
if (((TextBox)sender).Text == String.Empty)
Count = 0;
else
if (!int.TryParse(((TextBox)sender).Text, out Count))
return; int Temp = 1; for (; Temp <= Count; Temp++)
if (this.Controls.Find("DyTB" + Temp.ToString(), true).Length == 0)
{
TextBox DyTB = new TextBox();
DyTB.Name = "DyTB" + Temp.ToString();
DyTB.Text = "DyTB" + Temp.ToString();
DyTB.Location = new Point(0, 20 + Temp * 20);
DyTB.Parent = this;
} for (int i = Temp; i <= TotalCount; i++)
this.Controls.Remove(this.Controls.Find("DyTB" + i.ToString(), true)[0]); TotalCount = Temp - 1;
}
}
}
private void btnRun_MouseClick(object sender, MouseEventArgs e)
{
int k = Convert.ToInt32(txtRows.Text);
int y = Convert.ToInt32(txtCols.Text);
for (int i = 1; i <= k; i++)
{
for (int j = 1; j <= y; j++)
{
// Console.Write(i + "-" + j + "\t");
Label lbl = new Label();
lbl.Text = i + "-" + j;
lbl.Location = new Point(e.X, e.Y);
lbl.BackColor = Color.Yellow;
this.groupBox1.Controls.Add(lbl);
}
} }
莫非都输出到一起了
Add后面的lbl每次都能循环赋值给它的text属性,可是lbl还是lbl,所以控件根本没有循环,还不知道怎么解决,??晕。
{
int k = Convert.ToInt32(txtRows.Text);
int y = Convert.ToInt32(txtCols.Text);
int px=5; //加了两个改变labl坐标的变量,你是一下效果
int py=10;
for (int i = 1; i <= k; i++)
{
py=10;
for (int j = 1; j <= y; j++)
{
// Console.Write(i + "-" + j + "\t");
Label lbl = new Label();
lbl.Text = i + "-" + j;
lbl.Location = new Point(px, py);
py+=10;
lbl.BackColor = Color.Yellow;
this.groupBox1.Controls.Add(lbl);
}
px+=10;
} }
py+=60;
就能看出效果了
循环的过程中一直在改变Lbl的text值与位置,可是结果只输出了最后一个控件。
没有看出效果,现在可以循环了。谢谢啊。
那来的 e.X, e.Y
for (int i = 1; i <= k; i++)
{
px=10;
for (int j = 1; j <= y; j++)
{
Label lbl = new Label();
lbl.Text = i + "-" + j;
lbl.Location = new Point(px, py);
px+=10; lbl.BackColor = Color.Yellow;
this.groupBox1.Controls.Add(lbl);
}
py+=10; }
可以在循环里加一句:lbl.Autosize=true;效果好一点。