Form6.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace Praktika409
  11. {
  12. public partial class Form6 : Form
  13. {
  14. int koef = 1;
  15. public Form6()
  16. {
  17. InitializeComponent();
  18. // установка обработчика события Scroll
  19. trackBar1.Scroll += trackBar1_Scroll;
  20. InitializeComponent();
  21. this.Width = 400;
  22. button1.Width = 40;
  23. button1.Left = 40;
  24. button1.Text = "";
  25. button1.BackColor = Color.Aqua;
  26. timer1.Interval = 500; // 500 миллисекунд
  27. timer1.Enabled = true;
  28. button1.Click += button1_Click;
  29. timer1.Tick += timer1_Tick;
  30. }
  31. private void trackBar1_Scroll(object sender, EventArgs e)
  32. {
  33. label1.Text = String.Format("Текущее значение: {0}", trackBar1.Value);
  34. }
  35. private void button1_Click(object sender, EventArgs e)
  36. {
  37. if (timer1.Enabled == true)
  38. {
  39. timer1.Stop();
  40. }
  41. else
  42. {
  43. timer1.Start();
  44. }
  45. }
  46. void timer1_Tick(object sender, EventArgs e)
  47. {
  48. if (button1.Left == (this.Width - button1.Width - 10))
  49. {
  50. koef = -1;
  51. }
  52. else if (button1.Left == 0)
  53. {
  54. koef = 1;
  55. }
  56. button1.Left += 10 * koef;
  57. progressBar1.PerformStep();
  58. }
  59. private void progressBar1_Click(object sender, EventArgs e)
  60. {
  61. }
  62. }
  63. }