Home > Net >  WINFORM small white ask - how to make all controls to perform the same event at the same time
WINFORM small white ask - how to make all controls to perform the same event at the same time

Time:10-10

Winform small white consult
For example:
1, put a FlowLayoutPanel Form1
2, to build a Form2, inside put some controls, such as put a PictureBox
Mr Khoja 4, according to the data of dynamic loading Form2 into FlowLayoutPanel data, a data to generate a Form2.
I can now in the final interface to realize right click on the "display images", window click on the images, I want to click a button: display all pictures, let loading out of the window display images at the same time, could you tell me the how to implement,
Thank you very much!

CodePudding user response:

Form1 add:
Private void button1_Click (object sender, EventArgs e)
{
Form2 f2=new Form2 (pictureBox1. Image);
F2. The Show ();

}

Add form2
Public Form2 Image (b)
{
InitializeComponent ();
PictureBox1. Image=b;
}

CodePudding user response:

CodePudding user response:

NiuRan, after you this is click on the create a window for many times, at the same time give each window image data, and display! My demand is that open the f1, creates multiple f2, at the same time in order to seek speed, the default is not loading pictures, just preach the procession of associated data! I just give id f2 pass, for example, needs to be loaded image, the image data obtained by id again again!!! I can realize separate one by one, according to what I want to consulting is how to button, click the f1 or f2 brought on a widget, as long as one click all f2 display picture! after

CodePudding user response:

Two way

The first: create a event method such as

 
Protect void xxxClick (object sender, EventArgs e)
{
//todo
}


Then select what do you want to register event controls right-click properties have a lightning symbol to choose you to register the events and then choose your method can


The second:

In the constructor of all you want to register the events with +=followed by your name, but requires entrusted by the input and output parameters

CodePudding user response:

Like this?

CodePudding user response:

reference 5 floor f * * KCSDN reply:
like this?

Right, that is, to say the principle? See the code can be posted? Thank you very much!

CodePudding user response:

Is Jane a child form to subscribe to the parent form events and implement
 
Public partial class Form2: Form
{
Public Form2 ()
{
InitializeComponent ();
}

Public delegate void SetPic ();
The public event SetPic SetPic_Event;

Private void Form2_Load (object sender, EventArgs e)
{
for (int i=0; I & lt; 3; I++)
{
Form3 FRM=new Form3 (this);
FRM. PicId=Guid. NewGuid (), ToString ();
FRM. The Show ();
}
}

Private void Button1_Click (object sender, EventArgs e)
{

}

Private void Button2_Click (object sender, EventArgs e)
{
SetPic_Event ();
}
}

 
Public partial class Form3: Form
{
Public string PicId {get; set; }

Public Form3 () {InitializeComponent (); }

Public Form3 (Form2 FRM)
{
InitializeComponent ();
FRM. SetPic_Event +=Frm_SetPic_Event;
}

Private void Frm_SetPic_Event ()
{
Label1. Text=PicId;
}
}

CodePudding user response:

refer to 7th floor f * * KCSDN response:
is Jane a child form to subscribe to the parent form events and implement
 
Public partial class Form2: Form
{
Public Form2 ()
{
InitializeComponent ();
}

Public delegate void SetPic ();
The public event SetPic SetPic_Event;

Private void Form2_Load (object sender, EventArgs e)
{
for (int i=0; I & lt; 3; I++)
{
Form3 FRM=new Form3 (this);
FRM. PicId=Guid. NewGuid (), ToString ();
FRM. The Show ();
}
}

Private void Button1_Click (object sender, EventArgs e)
{

}

Private void Button2_Click (object sender, EventArgs e)
{
SetPic_Event ();
}
}

 
Public partial class Form3: Form
{
Public string PicId {get; set; }

Public Form3 () {InitializeComponent (); }

Public Form3 (Form2 FRM)
{
InitializeComponent ();
FRM. SetPic_Event +=Frm_SetPic_Event;
}

Private void Frm_SetPic_Event ()
{
Label1. Text=PicId;
}
}

According to your method, thank you very much!
  •  Tags:  
  • C#
  • Related