Home > Net >  C # window parameter passing
C # window parameter passing

Time:09-26

How to input data in a window, click on the window of a button after input in another window display

CodePudding user response:

https://bbs.csdn.net/topics/360140208? List=lz

CodePudding user response:

After opening the new window content is to synchronize with the original window contents update

CodePudding user response:


 
///window 1

Private delegate void delegateRefMessage (string MSG);
Private event delegateRefMessage RefMsg;
Private void SetText (string MSG)
{
The string content=richTextBox1. Text. The Trim ();
}
Private void button1_Click (object sender, EventArgs e)
{
Form2 f2=new Form2 ();
RefMsg +=new delegateRefMessage (f2. SetTextFromOther);
F2. The Show ();
}

Private void richTextBox1_TextChanged (object sender, EventArgs e)
{
If (RefMsg!=null) RefMsg (richTextBox1. Text. The Trim ());
}



///window 2
Public void SetTextFromOther (string STR)
{
This. RichTextBox1. The Clear ();
Enclosing richTextBox1. Text=STR;
}

CodePudding user response:

Constructor, entrust, event

CodePudding user response:

In the new window object of the Tag to add data, and then read it out into a new window,

NewForm nf=new newForm ();
Nf. Tag=12;
Nf. The Show ();

CodePudding user response:

Use event subscription mechanism, click on the button after the trigger

CodePudding user response:

If the two Windows are linked (2) window 1 know window, define attributes directly, assignment,
If two unrelated window, to send messages between the need to use the commission,

CodePudding user response:

Constructor, entrust, event

CodePudding user response:

The simplest method is
Newform nf=new newform (string value)
Nf. Your control. The text=value;

CodePudding user response:

Static global variables, two Windows with casually, as follows:

Public static Color background Color=Color. Wheat;
Public static bool application load success=false;

CodePudding user response:

The
references to the tenth floor GTM00 response:
static global variables, two Windows with casually, as follows:

Public static Color background Color=Color. Wheat;
Public static bool application load success=false;


This method is not very good, well small project, project easy to abuse,
  •  Tags:  
  • C#
  • Related