Chocolade19721309

Untitled

May 4th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 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. startButton.Enabled = false;
  74. countdownTimer.Start();
  75. }
  76.  
  77. private void CountdownTimer_Tick(object sender, EventArgs e)
  78. {
  79. if (countdownValue > 0)
  80. {
  81. countdownLabel.Text = countdownValue.ToString();
  82. countdownValue--;
  83. }
  84. else
  85. {
  86. countdownTimer.Stop();
  87. countdownLabel.Text = "";
  88. screenRecorder.StartRecording(@"D:\output1.mp4");
  89. this.WindowState = FormWindowState.Minimized;
  90. trayIcon.Visible = true;
  91. trayIcon.BalloonTipText = "Recording...";
  92. trayIcon.ShowBalloonTip(1000);
  93. }
  94. }
  95.  
  96. private void TrayIcon_DoubleClick(object sender, EventArgs e)
  97. {
  98. this.WindowState = FormWindowState.Normal;
  99. trayIcon.Visible = false;
  100. screenRecorder.StopRecording();
  101. startButton.Enabled = true;
  102. }
  103.  
  104. private void Form1_Load(object sender, EventArgs e)
  105. {
  106.  
  107. }
  108. }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment