可在C窗口的load事件中写处理过程,如果要获得A中的数据,则可将A中所需的数据变为static类型来访问。
解决方案 »
- 为什么对程序设置区域信息,在多线程内无效?
- C#
- C# webBrowser 如何向web中的js赋值
- 怎么在前台(aspx页)获取datalist中的控件值,在线等。。。。。
- c#能判断字符串在文本文件中所在的列吗
- C#如何截取文件名。。。。。。
- JS里面怎么获取当天日期?5分钟结贴!
- C# 导出Excel的问题
- ImageButton问题,附原码!
- 在创建一个form之前,如何判断它是否已经被创建 ?
- 在.Net中如何实现在后台程序执行任务时前端界面显示动画效果,就像vb/dephi中的Animate,解决即刻给分,谢谢,谢谢!
- 我做了一个控件,第一次从工具箱添加后没有问题,但是我又修改了那个控件,重新编译后再添加近来后,可是那个控件并没有刷新,还是以前的
...... //你的事务处理代码 ,在Form2模式显示之前执行Form2.ShowDialog();...... //这里的代码要在模式窗体关闭以后才可以执行
我想我可以在窗体C的代码中去处理这些事情,问题是我模式的显示C后,立刻就要执行这段代码,我该把这段代码放哪儿,或者说是哪个函数,哪个事件处理中呢???
//////////////////////////////////////////////
你放在Form_Load事件里不行么?
不行,我试过了
Form_paint也
不行啊,如果我移动了窗体呢??
Q2:在.net里TEXTBOX等的增加用AppendText()方法:
textBox1.AppendText("appendtext\n");
其中“\n”是换行符,如果不想换行,请将其去掉。
关于字符转义请参阅帮助:
ms-help://MS.VSCC/MS.MSDNVS.2052/cpgenref/html/cpconcharacterescapes.htm
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication4 {
public interface IDoWork{ //回调接口
void DoWork();} public class Form1 : System.Windows.Forms.Form,IDoWork {
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
private Form2 mfrm2=null; public Form1() {
InitializeComponent();
} protected override void Dispose( bool disposing ) {
if( disposing ) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(176, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(152, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 317);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion [STAThread]
static void Main() {
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e) {
mfrm2=new Form2();
mfrm2.objServer=this;
mfrm2.ShowDialog();
} public void DoWork(){
mfrm2.label1.Text ="Do Work";
}
} public class Form2 : System.Windows.Forms.Form {
public System.Windows.Forms.Label label1;
public IDoWork objServer=null;
private bool blnAtDoWork=false;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components; public Form2() {
InitializeComponent();
} protected override void Dispose( bool disposing ) {
if( disposing ) {
if(components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(224, 16);
this.label1.TabIndex = 0;
this.label1.Text = "正在... ...";
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 48);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Form2";
this.Activated += new System.EventHandler(this.Form2_Activated);
this.ResumeLayout(false); }
#endregion private void Form2_Activated(object sender, System.EventArgs e) {
if(!blnAtDoWork){
blnAtDoWork =true;
objServer.DoWork();
timer1.Enabled=true;
}
} private void timer1_Tick(object sender, System.EventArgs e) {
this.Close();
}
}}
!!首先,你在DoWork后调用Close()是没有用的。 这里的计时器设置为1秒,是为演示的目的。
使用定时器好像可以,不过我感觉怪怪的,我觉得应该有更好的方法阿