Guest User

Untitled

a guest
Oct 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. //using System.Linq;
  4. using System.Windows.Forms;
  5. using System.Drawing;
  6. using System.Threading;
  7.  
  8. public delegate void Del();
  9.  
  10. class OneForm : Form
  11. {
  12. public TextBox OurTextBox1;
  13. public OneForm() // конструктор
  14. {
  15. Text = "OneForm";
  16. Size = new Size(300, 300);
  17. OurTextBox1 = new TextBox();
  18. Controls.Add(OurTextBox1);
  19. Control.CheckForIllegalCrossThreadCalls = false;
  20. Show();
  21. }
  22. }
  23.  
  24. class TwoForm : Form
  25. {
  26. public TextBox OurTextBox2;
  27. public TwoForm() // конструктор
  28. {
  29. Text = "TwoForm";
  30. Size = new Size(300, 300);
  31. OurTextBox2 = new TextBox();
  32. Controls.Add(OurTextBox2);
  33. Control.CheckForIllegalCrossThreadCalls = false;
  34. Show();
  35. }
  36. }
  37.  
  38. class MainForms : Form
  39. {
  40. TextBox OurTextBox3;
  41. OneForm one;
  42. TwoForm two;
  43. Thread t; // ссылка на поток
  44. bool life; // признак жизни потока
  45. public event Del ev; // событие
  46. public MainForms() // конструктор
  47. {
  48. one = new OneForm();
  49. two = new TwoForm();
  50. life = true;
  51. Text = "MainForm";
  52. Size = new Size(300, 300);
  53. OurTextBox3 = new TextBox();
  54. Controls.Add(OurTextBox3);
  55. t = new Thread(new ThreadStart(Cycle));
  56. t.Start();
  57. }
  58.  
  59. void Cycle()
  60. {
  61. int j = 1;
  62. while (life)
  63. {
  64. OurTextBox3.Text = j.ToString();
  65. one.OurTextBox1.Text = j.ToString(); // перехват события
  66. two.OurTextBox2.Text = (j % 10).ToString(); // перехват события
  67. Thread.Sleep(25);
  68. j++;
  69. if (ev != null) ev(); //генерирование события
  70. }
  71. }
  72.  
  73. public void HandlerEv()
  74. {
  75. Invalidate();
  76. }
  77.  
  78.  
  79. static void Main(string[] args) // главная функция
  80. {
  81. Application.Run(new MainForms()); // выполнить
  82. }
  83. }
Add Comment
Please, Sign In to add comment