Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.40 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace lab_2_2._0_var1_5
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public enum Direction { Right, Down, Left, Up, Stop, Go};
  10.         public Direction direction = Direction.Right;
  11.  
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private void label1_Click(object sender, EventArgs e)
  18.         {
  19.  
  20.  
  21.         }
  22.  
  23.         private void timer1_Tick(object sender, EventArgs e)
  24.         {
  25.  
  26.             if (label1.Left > ClientRectangle.Width - label1.Width)
  27.             {
  28.                 direction = Direction.Down;
  29.                 label1.Left = ClientRectangle.Width - label1.Width;
  30.  
  31.             }
  32.  
  33.             if (label1.Top > ClientRectangle.Height - label1.Height)
  34.             {
  35.                 direction = Direction.Left;
  36.  
  37.                 label1.Top = ClientRectangle.Height - label1.Height;
  38.             }
  39.  
  40.             if (label1.Left < 0)
  41.             {
  42.                 direction = Direction.Up;
  43.                 label1.Left = 0;
  44.  
  45.             }
  46.  
  47.             if (label1.Top < 0)
  48.             {
  49.                     direction = Direction.Right;
  50.                     label1.Top = 0;
  51.             }
  52.  
  53.  
  54.             switch (direction)
  55.             {
  56.                 case Direction.Right:
  57.                     label1.Left += 10;
  58.                     if (label1.Left < ClientRectangle.Width - label1.Width)
  59.                     {
  60.                         label1.ForeColor = Color.FromArgb(label1.Left * 255 / (ClientRectangle.Width - label1.Width), 0, 0);
  61.                     }
  62.                     break;
  63.  
  64.                 case Direction.Down:
  65.                     label1.Top += 10;//243 249 40
  66.                     if (label1.Top < ClientRectangle.Height - label1.Height)
  67.                     {
  68.                         label1.ForeColor = Color.FromArgb(255, label1.Top * 255 / (ClientRectangle.Height - label1.Height), 0);
  69.                     }
  70.                     break;
  71.  
  72.                 case Direction.Left:
  73.                     label1.Left -= 10;
  74.                     if (label1.Left > 0)
  75.                     {
  76.                         label1.ForeColor = Color.FromArgb(255, 255, ((ClientRectangle.Width - label1.Width) - label1.Left) * 255 / (ClientRectangle.Width));
  77.                     }
  78.                     break;
  79.  
  80.                 case Direction.Up:
  81.                     label1.Top -= 10;
  82.                     if (label1.Top > 0)
  83.                     {
  84.                         label1.ForeColor = Color.FromArgb(label1.Top * 255 / (ClientRectangle.Height - label1.Height), label1.Top * 255 / (ClientRectangle.Height - label1.Height), label1.Top * 255 / (ClientRectangle.Height - label1.Height));
  85.                     }
  86.                     break;
  87.  
  88.                 case Direction.Stop:
  89.                     break;
  90.  
  91.                 case Direction.Go:
  92.                     if (label1.Top == 0)
  93.                         direction = Direction.Right;
  94.                     if (label1.Top == ClientRectangle.Height - label1.Height)
  95.                         direction = Direction.Left;
  96.                     if (label1.Left == 0)
  97.                         direction = Direction.Up;
  98.                     if (label1.Left == ClientRectangle.Width - label1.Width)
  99.                         direction = Direction.Down;
  100.                     break;
  101.             }
  102.         }
  103.  
  104.         private void Form1_Shown(object sender, EventArgs e)
  105.         {
  106.  
  107.         }
  108.  
  109.         private void Form1_Load_1(object sender, EventArgs e)
  110.         {
  111.             Form2 newForm = new Form2();
  112.             newForm.Show();
  113.             newForm.form1 = this;
  114.         }
  115.  
  116.         private void button1_Click(object sender, EventArgs e)
  117.         {
  118.             MessageBox.Show(label1.Top.ToString() + "\n" + "label координата: " + label1.Left.ToString() + "\nклиент ширина: " + ClientRectangle.Width.ToString() + "\nlabel ширина: " + label1.Width.ToString() + "\nразница: " + (ClientRectangle.Width - label1.Width).ToString() );
  119.         }
  120.     }
  121. }
  122.  
  123.  
  124.  
  125. ________________________________________________________________________________________________________
  126.  
  127.  
  128.  
  129.  
  130.  
  131. using System;
  132. using System.Windows.Forms;
  133.  
  134. namespace lab_2_2._0_var1_5
  135. {
  136.     public partial class Form2 : Form
  137.     {
  138.         public Form1 form1;
  139.  
  140.         int counter = 0; // счетсик строк
  141.         int dlina;
  142.         public Form2()
  143.         {
  144.             InitializeComponent();
  145.             dlina = label1.Text.Length - 1;
  146.         }
  147.  
  148.         private void Form2_Load(object sender, EventArgs e)
  149.         {
  150.  
  151.         }
  152.  
  153.         private void button1_Click(object sender, EventArgs e)
  154.         {
  155.             if (button1.Text == "Выключить")
  156.             {
  157.                 form1.direction = Form1.Direction.Stop;
  158.  
  159.                 button1.Text = "Включить";
  160.             }
  161.             else
  162.             {
  163.                 form1.direction = Form1.Direction.Go;
  164.  
  165.                 button1.Text = "Выключить";
  166.             }
  167.  
  168.         }
  169.  
  170.         private void label1_Click(object sender, EventArgs e)// количество строк
  171.         {
  172.  
  173.         }
  174.  
  175.         private void richTextBox1_TextChanged(object sender, EventArgs e)//
  176.         {
  177.            
  178.         }
  179.  
  180.         private void button2_Click(object sender, EventArgs e)// добавить строку
  181.         {
  182.             if (textBox1.Text == "")
  183.                 MessageBox.Show("Введите строку");
  184.             else
  185.             {
  186.                 richTextBox1.Text += textBox1.Text + "\n";
  187.                 textBox1.Text = "";
  188.                 label1.Text = label1.Text.Remove(label1.Text.Length - (label1.Text.Length - dlina));
  189.                 label1.Text += (++counter);
  190.             }
  191.         }
  192.  
  193.         private void button3_Click(object sender, EventArgs e)// удалить строку
  194.         {
  195.             if (richTextBox1.Text != "")
  196.             {
  197.                 richTextBox1.Text = richTextBox1.Text.Remove(richTextBox1.GetFirstCharIndexFromLine(0), richTextBox1.Lines[0].Length + 1); // из интерента удаление строки
  198.                 label1.Text = label1.Text.Remove(label1.Text.Length - (label1.Text.Length - dlina));
  199.                 label1.Text += (--counter);
  200.             }
  201.         }
  202.  
  203.         private void textBox1_TextChanged(object sender, EventArgs e) // поле ввода
  204.         {
  205.  
  206.         }
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement