windows-secure-shell / SecureShellForm.cs
GamiDPC's picture
Создай интерфейс защищенной оболочки Windows на C# WinForms с темной темой.
ea7379a verified
Raw
History Blame Contribute Delete
9.8 kB
csharp
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace SecureShell
{
public class SecureShellForm : Form
{
private Panel topPanel;
private Panel bottomPanel;
private FlowLayoutPanel appsPanel;
private Label titleLabel;
private Label timeLabel;
private Button adminButton;
private Timer clockTimer;
private const string AdminPassword = "secure123";
public SecureShellForm()
{
InitializeComponents();
SetupDarkTheme();
SetupClock();
CreateAppIcons();
}
private void InitializeComponents()
{
// Main form setup
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.BackColor = Color.FromArgb(30, 30, 30);
this.Text = "Secure Shell";
// Top panel
topPanel = new Panel();
topPanel.Dock = DockStyle.Top;
topPanel.Height = 60;
topPanel.BackColor = Color.FromArgb(43, 87, 154);
titleLabel = new Label();
titleLabel.Text = "ЗАЩИЩЕННАЯ ОБОЛОЧКА";
titleLabel.Font = new Font("Segoe UI", 14, FontStyle.Bold);
titleLabel.ForeColor = Color.White;
titleLabel.AutoSize = true;
titleLabel.Location = new Point(20, 20);
timeLabel = new Label();
timeLabel.Font = new Font("Segoe UI", 14, FontStyle.Bold);
timeLabel.ForeColor = Color.White;
timeLabel.AutoSize = true;
timeLabel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
topPanel.Controls.Add(titleLabel);
topPanel.Controls.Add(timeLabel);
this.Controls.Add(topPanel);
// Bottom panel
bottomPanel = new Panel();
bottomPanel.Dock = DockStyle.Bottom;
bottomPanel.Height = 60;
bottomPanel.BackColor = Color.FromArgb(43, 87, 154);
adminButton = new Button();
adminButton.Text = "АДМИН ДОСТУП";
adminButton.Font = new Font("Segoe UI", 10, FontStyle.Bold);
adminButton.ForeColor = Color.White;
adminButton.BackColor = Color.FromArgb(30, 30, 30);
adminButton.FlatStyle = FlatStyle.Flat;
adminButton.FlatAppearance.BorderSize = 0;
adminButton.Height = 40;
adminButton.Width = 150;
adminButton.Anchor = AnchorStyles.None;
adminButton.Click += AdminButton_Click;
bottomPanel.Controls.Add(adminButton);
this.Controls.Add(bottomPanel);
// Apps panel
appsPanel = new FlowLayoutPanel();
appsPanel.Dock = DockStyle.Fill;
appsPanel.Padding = new Padding(50);
appsPanel.BackColor = Color.FromArgb(30, 30, 30);
appsPanel.AutoScroll = true;
this.Controls.Add(appsPanel);
}
private void SetupDarkTheme()
{
this.BackColor = Color.FromArgb(30, 30, 30);
this.ForeColor = Color.White;
}
private void SetupClock()
{
clockTimer = new Timer();
clockTimer.Interval = 1000;
clockTimer.Tick += (s, e) => UpdateTime();
clockTimer.Start();
UpdateTime();
}
private void UpdateTime()
{
timeLabel.Text = DateTime.Now.ToString("HH:mm:ss");
timeLabel.Location = new Point(
topPanel.Width - timeLabel.Width - 20,
(topPanel.Height - timeLabel.Height) / 2
);
}
private void CreateAppIcons()
{
// Example apps - in real app you would load these from config
AddAppIcon("Notepad", "notepad.exe");
AddAppIcon("Calculator", "calc.exe");
AddAppIcon("Paint", "mspaint.exe");
AddAppIcon("Explorer", "explorer.exe");
AddAppIcon("CMD", "cmd.exe");
AddAppIcon("Browser", "iexplore.exe");
AddAppIcon("Word", "winword.exe");
AddAppIcon("Excel", "excel.exe");
AddAppIcon("PowerPoint", "powerpnt.exe");
}
private void AddAppIcon(string name, string exePath)
{
var iconButton = new Button();
iconButton.Width = 120;
iconButton.Height = 120;
iconButton.FlatStyle = FlatStyle.Flat;
iconButton.FlatAppearance.BorderSize = 0;
iconButton.Margin = new Padding(20);
iconButton.BackColor = Color.FromArgb(50, 50, 50);
iconButton.ForeColor = Color.White;
iconButton.Font = new Font("Segoe UI", 10, FontStyle.Regular);
iconButton.Text = name;
iconButton.TextAlign = ContentAlignment.BottomCenter;
iconButton.TextImageRelation = TextImageRelation.ImageAboveText;
try
{
var icon = Icon.ExtractAssociatedIcon(exePath);
iconButton.Image = icon.ToBitmap();
iconButton.ImageAlign = ContentAlignment.TopCenter;
}
catch
{
// Use default icon if extraction fails
iconButton.Image = SystemIcons.Application.ToBitmap();
}
iconButton.Click += (s, e) => LaunchApplication(exePath);
appsPanel.Controls.Add(iconButton);
}
private void LaunchApplication(string exePath)
{
try
{
Process.Start(exePath);
}
catch (Exception ex)
{
MessageBox.Show($"Error launching application: {ex.Message}",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AdminButton_Click(object sender, EventArgs e)
{
using (var passwordForm = new PasswordForm())
{
if (passwordForm.ShowDialog() == DialogResult.OK)
{
if (passwordForm.Password == AdminPassword)
{
MessageBox.Show("Admin access granted!", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Invalid password!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SecureShellForm());
}
}
public class PasswordForm : Form
{
private TextBox passwordBox;
private Button okButton;
private Button cancelButton;
public string Password { get; private set; }
public PasswordForm()
{
InitializeComponents();
SetupDarkTheme();
}
private void InitializeComponents()
{
this.Text = "Admin Access";
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.ClientSize = new Size(300, 150);
this.AcceptButton = okButton;
this.CancelButton = cancelButton;
var label = new Label();
label.Text = "Enter admin password:";
label.Location = new Point(20, 20);
label.AutoSize = true;
label.ForeColor = Color.White;
passwordBox = new TextBox();
passwordBox.Location = new Point(20, 50);
passwordBox.Size = new Size(260, 20);
passwordBox.PasswordChar = '*';
okButton = new Button();
okButton.Text = "OK";
okButton.Location = new Point(120, 90);
okButton.Size = new Size(75, 30);
okButton.DialogResult = DialogResult.OK;
okButton.Click += (s, e) =>
{
Password = passwordBox.Text;
this.Close();
};
cancelButton = new Button();
cancelButton.Text = "Cancel";
cancelButton.Location = new Point(205, 90);
cancelButton.Size = new Size(75, 30);
cancelButton.DialogResult = DialogResult.Cancel;
this.Controls.Add(label);
this.Controls.Add(passwordBox);
this.Controls.Add(okButton);
this.Controls.Add(cancelButton);
}
private void SetupDarkTheme()
{
this.BackColor = Color.FromArgb(30, 30, 30);
this.ForeColor = Color.White;
foreach (Control control in this.Controls)
{
if (control is Button button)
{
button.BackColor = Color.FromArgb(43, 87, 154);
button.ForeColor = Color.White;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
}
else if (control is TextBox textBox)
{
textBox.BackColor = Color.FromArgb(50, 50, 50);
textBox.ForeColor = Color.White;
textBox.BorderStyle = BorderStyle.FixedSingle;
}
}
}
}
}
</html>