winform 动态加载表以按钮形式显示机器状态
2016-12-19 14:49
232 查看
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection("Data Source=192.168.1.234;Initial Catalog=wiktest;User ID=sa;Password=*****"))
{
SqlCommand comm=new SqlCommand("select id,name,des,zt from machine", conn);
comm.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(ds, "UserTable");
}
int mint = ds.Tables[0].Rows.Count;
int row = 0;
string s = "test";
//bool zt;
for (int rr=0;rr<mint;rr++)
{
if (rr % 10 == 0 && rr != 0)
{
row++;
}
Button btn = new Button();
//控件名称
btn.Name = "mybutton" + rr.ToString();
//控件显示文本
btn.Text = string.Format("机器{0}", ds.Tables[0].Rows[rr][0].ToString());
s = ds.Tables[0].Rows[rr][2].ToString();
if (ds.Tables[0].Rows[rr][3].ToString() == "True")
btn.BackColor = Color.Red;
else
btn.BackColor = Color.Blue;
//控件大小
btn.Size = new Size(50, 50);
//控件位置【动态变化】
btn.Location = new Point(50 + rr % 10 * 100, 50 + row * 100);
//添加到窗体
this.Controls.Add(btn);
ToolTip msg = new ToolTip();
msg.ShowAlways = true;
msg.SetToolTip(btn, s);
using (SqlConnection conn = new SqlConnection("Data Source=192.168.1.234;Initial Catalog=wiktest;User ID=sa;Password=*****"))
{
SqlCommand comm=new SqlCommand("select id,name,des,zt from machine", conn);
comm.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(comm);
da.Fill(ds, "UserTable");
}
int mint = ds.Tables[0].Rows.Count;
int row = 0;
string s = "test";
//bool zt;
for (int rr=0;rr<mint;rr++)
{
if (rr % 10 == 0 && rr != 0)
{
row++;
}
Button btn = new Button();
//控件名称
btn.Name = "mybutton" + rr.ToString();
//控件显示文本
btn.Text = string.Format("机器{0}", ds.Tables[0].Rows[rr][0].ToString());
s = ds.Tables[0].Rows[rr][2].ToString();
if (ds.Tables[0].Rows[rr][3].ToString() == "True")
btn.BackColor = Color.Red;
else
btn.BackColor = Color.Blue;
//控件大小
btn.Size = new Size(50, 50);
//控件位置【动态变化】
btn.Location = new Point(50 + rr % 10 * 100, 50 + row * 100);
//添加到窗体
this.Controls.Add(btn);
ToolTip msg = new ToolTip();
msg.ShowAlways = true;
msg.SetToolTip(btn, s);
相关文章推荐
- 设计winform自带动态加载工具按钮和实现热键响应
- [WinForm]dataGridView动态加载以本地图片显示列
- [WinForm]dataGridView动态加载以本地图片显示列
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- 以列表形式显示动态加载的数据
- sap 显示状态栏时动态排除部分按钮
- 解决winform中mdi子窗体加载时显示最大化最小化按钮的方法
- [转]以列表形式显示动态加载的数据(JavaScript,Java,JSP,HTML)
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)
- extjs4 动态加载树菜单和相应的按钮是否显示 ,到对权限的控制粒度细化到按钮
- 关于WPF加载WinForm界面,WinForm界面显示错位、按钮大小变大的问题
- Winform窗体中左边显示TreeView右边显示动态加载的窗体的实现
- WinForm MDI动态加载form
- winform 通过摄像头将本机的监控视频传送到远端机器显示
- 动态加载CBitmapButton的四副状态图
- ASP.Net 动态加载控件 未能加载视图状态 的解决
- web页面加载时显示加载状态
- WinForm中使用XtraGrid控件,实现在界面中动态修改列显示,列名列宽等(进阶)
- Flex :自定义Loading载入状态(含图标) 及解决Flex中GIF动画图片加载时显示动起来
- 给Swing程序添加一个动态显示内存情况的状态条