Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace lab_2_2._0_var1_5
- {
- public partial class Form1 : Form
- {
- public enum Direction { Right, Down, Left, Up, Stop, Go};
- public Direction direction = Direction.Right;
- public Form1()
- {
- InitializeComponent();
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (label1.Left > ClientRectangle.Width - label1.Width)
- {
- direction = Direction.Down;
- label1.Left = ClientRectangle.Width - label1.Width;
- }
- if (label1.Top > ClientRectangle.Height - label1.Height)
- {
- direction = Direction.Left;
- label1.Top = ClientRectangle.Height - label1.Height;
- }
- if (label1.Left < 0)
- {
- direction = Direction.Up;
- label1.Left = 0;
- }
- if (label1.Top < 0)
- {
- direction = Direction.Right;
- label1.Top = 0;
- }
- switch (direction)
- {
- case Direction.Right:
- label1.Left += 10;
- if (label1.Left < ClientRectangle.Width - label1.Width)
- {
- label1.ForeColor = Color.FromArgb(label1.Left * 255 / (ClientRectangle.Width - label1.Width), 0, 0);
- }
- break;
- case Direction.Down:
- label1.Top += 10;//243 249 40
- if (label1.Top < ClientRectangle.Height - label1.Height)
- {
- label1.ForeColor = Color.FromArgb(255, label1.Top * 255 / (ClientRectangle.Height - label1.Height), 0);
- }
- break;
- case Direction.Left:
- label1.Left -= 10;
- if (label1.Left > 0)
- {
- label1.ForeColor = Color.FromArgb(255, 255, ((ClientRectangle.Width - label1.Width) - label1.Left) * 255 / (ClientRectangle.Width));
- }
- break;
- case Direction.Up:
- label1.Top -= 10;
- if (label1.Top > 0)
- {
- 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));
- }
- break;
- case Direction.Stop:
- break;
- case Direction.Go:
- if (label1.Top == 0)
- direction = Direction.Right;
- if (label1.Top == ClientRectangle.Height - label1.Height)
- direction = Direction.Left;
- if (label1.Left == 0)
- direction = Direction.Up;
- if (label1.Left == ClientRectangle.Width - label1.Width)
- direction = Direction.Down;
- break;
- }
- }
- private void Form1_Shown(object sender, EventArgs e)
- {
- }
- private void Form1_Load_1(object sender, EventArgs e)
- {
- Form2 newForm = new Form2();
- newForm.Show();
- newForm.form1 = this;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- MessageBox.Show(label1.Top.ToString() + "\n" + "label координата: " + label1.Left.ToString() + "\nклиент ширина: " + ClientRectangle.Width.ToString() + "\nlabel ширина: " + label1.Width.ToString() + "\nразница: " + (ClientRectangle.Width - label1.Width).ToString() );
- }
- }
- }
- ________________________________________________________________________________________________________
- using System;
- using System.Windows.Forms;
- namespace lab_2_2._0_var1_5
- {
- public partial class Form2 : Form
- {
- public Form1 form1;
- int counter = 0; // счетсик строк
- int dlina;
- public Form2()
- {
- InitializeComponent();
- dlina = label1.Text.Length - 1;
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (button1.Text == "Выключить")
- {
- form1.direction = Form1.Direction.Stop;
- button1.Text = "Включить";
- }
- else
- {
- form1.direction = Form1.Direction.Go;
- button1.Text = "Выключить";
- }
- }
- private void label1_Click(object sender, EventArgs e)// количество строк
- {
- }
- private void richTextBox1_TextChanged(object sender, EventArgs e)//
- {
- }
- private void button2_Click(object sender, EventArgs e)// добавить строку
- {
- if (textBox1.Text == "")
- MessageBox.Show("Введите строку");
- else
- {
- richTextBox1.Text += textBox1.Text + "\n";
- textBox1.Text = "";
- label1.Text = label1.Text.Remove(label1.Text.Length - (label1.Text.Length - dlina));
- label1.Text += (++counter);
- }
- }
- private void button3_Click(object sender, EventArgs e)// удалить строку
- {
- if (richTextBox1.Text != "")
- {
- richTextBox1.Text = richTextBox1.Text.Remove(richTextBox1.GetFirstCharIndexFromLine(0), richTextBox1.Lines[0].Length + 1); // из интерента удаление строки
- label1.Text = label1.Text.Remove(label1.Text.Length - (label1.Text.Length - dlina));
- label1.Text += (--counter);
- }
- }
- private void textBox1_TextChanged(object sender, EventArgs e) // поле ввода
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement