对象引用问题请教 我感觉你是想做一个私有方法 private void show() { MessageBox.Show(textBox1.Text); } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 私有方法能访问到text1.text吗? 你这样写方法算方法吗?namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static void show(ss) { MessageBox.Show(ss); } private void button1_Click(object sender, EventArgs e) { show(textBox1.Text); } } } 改为: public void show() { MessageBox.Show(this.textBox1.Text); } private void button1_Click(object sender, EventArgs e) { this.show(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show(this.textBox1.Text); 或 ScriptManager.RegisterStartupScript(this, GetType(), "click", "window.alert('有异常:" + ex.Message + "');", true); } 一个非 static 的方法在调用 static 的方法时不会调用对象。 C#操作Excel,懂Excel也可以进来看下。 直接用Visual Studio2010打开.sln解决方案文件时VS界面无显示 webform中,如何设置弹出页面的位置? 关于服务端向客户端发信息问题(汉字变成乱码) 问一个关于按键处理的简单问题 关于IsPostBack Arraylist 有没有判断非空的方法 ★★★★★星级问题: 关于菜单和文本框! 问两个有关控件的问题 C# frameset 关于复制图片流的问题 dropdownlist 的Text和value问题
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static void show(ss)
{
MessageBox.Show(ss);
} private void button1_Click(object sender, EventArgs e)
{
show(textBox1.Text);
}
}
}
public void show()
{
MessageBox.Show(this.textBox1.Text);
} private void button1_Click(object sender, EventArgs e)
{
this.show();
}
{
MessageBox.Show(this.textBox1.Text);
或
ScriptManager.RegisterStartupScript(this, GetType(), "click", "window.alert('有异常:" + ex.Message + "');", true);
}