参考《C#Windows程序设计》
里面有一章专门讲dialog
里面有一章专门讲dialog
解决方案 »
- 关于控制台程序多线程问题。希望老大们给些建议
- 请教ListView的用法
- 求 LZ77 压缩/解压类库
- 调用EXE,CONNECTIONSTRING尚未初始化
- 打开阿拉伯语的word文件乱码,求帮助...
- 原則提醒: 專案 'Common.csproj' (項目 projSystem, projCSharpProject) 不允許 參考 'System.Windows.Forms' (項目 refSystem.Windows.F
- WinForm中如何展示PDF文件
- devexpress XtraCharts 画图控件中怎么固定坐标轴的小数位
- 请教如何判定一个输入是水仙花状,如66566是,542dg4不是
- 高手请进来看一下,谢谢了!
- 关于SQL脚本问题?
- 有没有ASCII数据类型?
private string _receivedStr;
public string ReceivedString
{
get{
return _receivedStr;
}
set {
_receivedStr = value;
}
}private void ShowForm2()
{
Form2 frm = new Form2();
frm.Show( this );
}
...Form2 OnClosed: ((Form1)this.Parent).ReceivedString = "Some value";
Show Form2的时候应该是:private void ShowForm2()
{
Form2 frm = new Form2();
frm.ShowDialog( this );
}
{
this._form1 = frm;
}private Form1 _form1;OnClosed:
if( this._form1!=null )
this._form1.ReceivedString = "Some Value";Form1中的代码:
...
private string _receivedStr;
public string ReceivedString
{
get{
return _receivedStr;
}
set {
_receivedStr = value;
}
}private void ShowForm2()
{
Form2 frm = new Form2(this);
frm.Show();
}
...
利用
((Form1)this.Parent).label1.Text = this.textBox1.Text;传递数据,编译时没有错误,可是在运行关闭Form2时,出现错误.详细如下.
有关调用实时 (JIT) 调试而不是此对话框的详细信息,
请参阅此消息的结尾。************** 异常文本 **************
System.NullReferenceException: 未将对象引用设置到对象的实例。
at test1.Form2.Form2_Closing(Object sender, CancelEventArgs e) in f:\projects\test1\form2.cs:line 96
at System.Windows.Forms.Form.OnClosing(CancelEventArgs e)
at System.Windows.Forms.Form.WmClose(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已加载的程序集 **************
mscorlib
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.209
基本代码:file:///c:/windows/microsoft.net/framework/v1.0.3705/mscorlib.dll
----------------------------------------
test1
程序集版本:1.0.1170.32516
Win32 版本:1.0.1170.32516
基本代码:file:///F:/projects/test1/bin/Debug/test1.exe
----------------------------------------
System.Windows.Forms
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/windows/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/windows/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/windows/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Xml
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/windows/assembly/gac/system.xml/1.0.3300.0__b77a5c561934e089/system.xml.dll
----------------------------------------
mscorlib.resources
程序集版本:1.0.3300.0
Win32 版本:1.0.3300.0
基本代码:file:///c:/windows/assembly/gac/mscorlib.resources/1.0.3300.0_zh-chs_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本:1.0.3300.0
Win32 版本:1.0.3300.0
基本代码:file:///c:/windows/assembly/gac/system.windows.forms.resources/1.0.3300.0_zh-chs_b77a5c561934e089/system.windows.forms.resources.dll
----------------------------------------************** JIT 调试 **************
若要启用实时 (JIT) 调试,此
应用程序或计算机的配置文件 (machine.config) 的
system.windows.forms 节中必须设置 jitDebugging 值。
编译应用程序时还必须启用
调试。例如:<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>启用 JIT 调试后,任何未处理的异常
将被发送到此计算机上注册的 JIT 调试器,
而不是由此对话框处理。
private void button1_Click(object sender, System.EventArgs e)
{
Form2 fm = new Form2();
fm.Show();
}
public static void ShowResult()
{
MessageBox.Show(Class1.getValue());
}//Form2中
private void button1_Click(object sender, System.EventArgs e)
{
Class1.setValue(this.textBox1.Text);
this.Visible = false;
Form1.ShowResult();
this.Close();
}
//Class1中
public class Class1
{
static string t;
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public static void setValue(string sNew)
{
t = sNew;
} public static string getValue()
{
return t;
}
}
============================================================
Class1即可在Form1中访问,也可在Form2中访问
然后判断是点了那个按钮,再直接调用form2上的控件就可以了