Chocolade19721309

Untitled

May 4th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  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.  
  11. namespace Screen_Recorder
  12. {
  13. public partial class Form1 : Form
  14. {
  15. private Button startButton;
  16. private Label countdownLabel;
  17. private NotifyIcon trayIcon;
  18. private Timer countdownTimer;
  19. private int countdownValue = 3;
  20. private ScreenRecorder screenRecorder;
  21.  
  22.  
  23. public Form1()
  24. {
  25. InitializeComponent();
  26.  
  27. Init();
  28. screenRecorder = new ScreenRecorder();
  29.  
  30. }
  31.  
  32. private void Init()
  33. {
  34. // Setup the form
  35. this.ClientSize = new Size(300, 100);
  36. this.Text = "Screen Recorder";
  37.  
  38. // Start button
  39. startButton = new Button
  40. {
  41. Text = "Start Recording",
  42. Location = new Point(50, 30),
  43. Size = new Size(200, 40)
  44. };
  45. startButton.Click += StartButton_Click;
  46. this.Controls.Add(startButton);
  47.  
  48. // Countdown label
  49. countdownLabel = new Label
  50. {
  51. Text = "",
  52. Location = new Point(50, 10),
  53. Size = new Size(200, 20),
  54. TextAlign = ContentAlignment.MiddleCenter
  55. };
  56. this.Controls.Add(countdownLabel);
  57.  
  58. // Notify icon for the system tray
  59. trayIcon = new NotifyIcon
  60. {
  61. Icon = SystemIcons.Application,
  62. Visible = false
  63. };
  64. trayIcon.DoubleClick += TrayIcon_DoubleClick;
  65.  
  66. // Countdown timer
  67. countdownTimer = new Timer { Interval = 1000 };
  68. countdownTimer.Tick += CountdownTimer_Tick;
  69. }
  70.  
  71. private void StartButton_Click(object sender, EventArgs e)
  72. {
  73. if (startButton.Text == "Start Recording")
  74. {
  75. startButton.Text = "Stop Recording";
  76. startButton.Enabled = false;
  77. countdownTimer.Start();
  78. }
  79. else if (startButton.Text == "Stop Recording")
  80. {
  81. screenRecorder.StopRecording();
  82. startButton.Text = "Start Recording";
  83. startButton.Enabled = true;
  84. trayIcon.Visible = false;
  85. this.WindowState = FormWindowState.Normal;
  86. }
  87. }
  88.  
  89. private void CountdownTimer_Tick(object sender, EventArgs e)
  90. {
  91. if (countdownValue > 0)
  92. {
  93. countdownLabel.Text = countdownValue.ToString();
  94. countdownValue--;
  95. }
  96. else
  97. {
  98. countdownTimer.Stop();
  99. countdownLabel.Text = "";
  100. screenRecorder.StartRecording(@"D:\output1.mp4");
  101. this.WindowState = FormWindowState.Minimized;
  102. trayIcon.Visible = true;
  103. trayIcon.BalloonTipText = "Recording...";
  104. trayIcon.ShowBalloonTip(1000);
  105. }
  106. }
  107.  
  108. private void TrayIcon_DoubleClick(object sender, EventArgs e)
  109. {
  110. this.WindowState = FormWindowState.Normal;
  111. trayIcon.Visible = false;
  112. startButton.Enabled = true;
  113. }
  114.  
  115. private void Form1_Load(object sender, EventArgs e)
  116. {
  117.  
  118. }
  119. }
  120. }
  121.  
Advertisement
Add Comment
Please, Sign In to add comment