打个比方说,我想在程序中用
Label lab1 = new Label();
和Form1.controls.add(lab1); 方法添加一个label到窗体上,并同理添加一个Button到窗体上,然后Button得Click事件要MEssageBox.show出这个lab1的text属性,但是编译时C#提示这个lab1还为创建,不知道怎么解决这个问题,谢谢;
诚心求教!
Label lab1 = new Label();
和Form1.controls.add(lab1); 方法添加一个label到窗体上,并同理添加一个Button到窗体上,然后Button得Click事件要MEssageBox.show出这个lab1的text属性,但是编译时C#提示这个lab1还为创建,不知道怎么解决这个问题,谢谢;
诚心求教!
解决方案 »
- 一个无线PDA读取电脑串口数据,大家觉得可行性如何
- winform连接超时
- Winform中Datagrid的修改与删除问题
- 求身份证号验证函数
- 已知三角形三边长度及两点坐标,求第三点坐标
- excel.Save("D:" + "123.xls");出现Exception from HRESULT: 0x800A03EC
- 咨询:请问用C#进行网络通信编程好不好?如果要和plc通信呢,最好选用什么语言?
- 请教一个数据库查询问题
- 如何在连接数据库的过程中用progressbar显示进度
- 什么是。NET啊?
- 通过ImageButton Calendar TextBox做一个自定义控件(高手请教)
- 线程中使用join和单线程有区别吗?
private Label lab1 = null;
(2)
修改你的函数
Label lab1 = new Label();=》lab1 = new Label();OK
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication1
{
public partial class Form1 : Form
{
Label lable1 = new Label();
Button btnadd = new Button();
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
this.axAXPlayer1.SetConnectString("10.34.78.10",8000,@"c:\");
// this.axAXPlayer1.Play("10.34.78.13", 8000, @"c:\");
} private void Form1_Load(object sender, EventArgs e)
{
lable1.Text = "hello,world";
this.Controls.Add(lable1);
btnadd.Width = 20;
btnadd.Height = 100;
btnadd.Text = "测试";
btnadd.Click += new EventHandler(btnadd_click);
this.Controls.Add(btnadd); }
private void btnadd_click(object sender, EventArgs e)
{
MessageBox.Show(lable1.Text);
}
}
}