Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- //using System.Linq;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Threading;
- public delegate void Del();
- class OneForm : Form
- {
- public TextBox OurTextBox1;
- public OneForm() // конструктор
- {
- Text = "OneForm";
- Size = new Size(300, 300);
- OurTextBox1 = new TextBox();
- Controls.Add(OurTextBox1);
- Control.CheckForIllegalCrossThreadCalls = false;
- Show();
- }
- }
- class TwoForm : Form
- {
- public TextBox OurTextBox2;
- public TwoForm() // конструктор
- {
- Text = "TwoForm";
- Size = new Size(300, 300);
- OurTextBox2 = new TextBox();
- Controls.Add(OurTextBox2);
- Control.CheckForIllegalCrossThreadCalls = false;
- Show();
- }
- }
- class MainForms : Form
- {
- TextBox OurTextBox3;
- OneForm one;
- TwoForm two;
- Thread t; // ссылка на поток
- bool life; // признак жизни потока
- public event Del ev; // событие
- public MainForms() // конструктор
- {
- one = new OneForm();
- two = new TwoForm();
- life = true;
- Text = "MainForm";
- Size = new Size(300, 300);
- OurTextBox3 = new TextBox();
- Controls.Add(OurTextBox3);
- t = new Thread(new ThreadStart(Cycle));
- t.Start();
- }
- void Cycle()
- {
- int j = 1;
- while (life)
- {
- OurTextBox3.Text = j.ToString();
- one.OurTextBox1.Text = j.ToString(); // перехват события
- two.OurTextBox2.Text = (j % 10).ToString(); // перехват события
- Thread.Sleep(25);
- j++;
- if (ev != null) ev(); //генерирование события
- }
- }
- public void HandlerEv()
- {
- Invalidate();
- }
- static void Main(string[] args) // главная функция
- {
- Application.Run(new MainForms()); // выполнить
- }
- }
Add Comment
Please, Sign In to add comment