Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Screen_Recorder
- {
- public partial class Form1 : Form
- {
- private Button startButton;
- private Label countdownLabel;
- private NotifyIcon trayIcon;
- private Timer countdownTimer;
- private int countdownValue = 3;
- private ScreenRecorder screenRecorder;
- public Form1()
- {
- InitializeComponent();
- Init();
- screenRecorder = new ScreenRecorder();
- }
- private void Init()
- {
- // Setup the form
- this.ClientSize = new Size(300, 100);
- this.Text = "Screen Recorder";
- // Start button
- startButton = new Button
- {
- Text = "Start Recording",
- Location = new Point(50, 30),
- Size = new Size(200, 40)
- };
- startButton.Click += StartButton_Click;
- this.Controls.Add(startButton);
- // Countdown label
- countdownLabel = new Label
- {
- Text = "",
- Location = new Point(50, 10),
- Size = new Size(200, 20),
- TextAlign = ContentAlignment.MiddleCenter
- };
- this.Controls.Add(countdownLabel);
- // Notify icon for the system tray
- trayIcon = new NotifyIcon
- {
- Icon = SystemIcons.Application,
- Visible = false
- };
- trayIcon.DoubleClick += TrayIcon_DoubleClick;
- // Countdown timer
- countdownTimer = new Timer { Interval = 1000 };
- countdownTimer.Tick += CountdownTimer_Tick;
- }
- private void StartButton_Click(object sender, EventArgs e)
- {
- startButton.Enabled = false;
- countdownTimer.Start();
- }
- private void CountdownTimer_Tick(object sender, EventArgs e)
- {
- if (countdownValue > 0)
- {
- countdownLabel.Text = countdownValue.ToString();
- countdownValue--;
- }
- else
- {
- countdownTimer.Stop();
- countdownLabel.Text = "";
- screenRecorder.StartRecording(@"D:\output1.mp4");
- this.WindowState = FormWindowState.Minimized;
- trayIcon.Visible = true;
- trayIcon.BalloonTipText = "Recording...";
- trayIcon.ShowBalloonTip(1000);
- }
- }
- private void TrayIcon_DoubleClick(object sender, EventArgs e)
- {
- this.WindowState = FormWindowState.Normal;
- trayIcon.Visible = false;
- screenRecorder.StopRecording();
- startButton.Enabled = true;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment