mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-06 08:00:44 +08:00
Add files via upload
This commit is contained in:
@@ -1,34 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供基本数学运算功能的工具类
|
||||
/// </summary>
|
||||
public static class Calculator
|
||||
{
|
||||
/// <summary>
|
||||
/// 加法运算
|
||||
/// </summary>
|
||||
public static double Add(double a, double b) => a + b;
|
||||
|
||||
/// <summary>
|
||||
/// 减法运算
|
||||
/// </summary>
|
||||
public static double Subtract(double a, double b) => a - b;
|
||||
|
||||
/// <summary>
|
||||
/// 乘法运算
|
||||
/// </summary>
|
||||
public static double Multiply(double a, double b) => a * b;
|
||||
|
||||
/// <summary>
|
||||
/// 除法运算
|
||||
/// </summary>
|
||||
public static double Divide(double a, double b)
|
||||
{
|
||||
if (b == 0) throw new DivideByZeroException("除数不能为零");
|
||||
return a / b;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供基本数学运算功能的工具类
|
||||
/// </summary>
|
||||
public static class Calculator
|
||||
{
|
||||
/// <summary>
|
||||
/// 加法运算
|
||||
/// </summary>
|
||||
public static double Add(double a, double b) => a + b;
|
||||
|
||||
/// <summary>
|
||||
/// 减法运算
|
||||
/// </summary>
|
||||
public static double Subtract(double a, double b) => a - b;
|
||||
|
||||
/// <summary>
|
||||
/// 乘法运算
|
||||
/// </summary>
|
||||
public static double Multiply(double a, double b) => a * b;
|
||||
|
||||
/// <summary>
|
||||
/// 除法运算
|
||||
/// </summary>
|
||||
public static double Divide(double a, double b)
|
||||
{
|
||||
if (b == 0) throw new DivideByZeroException("除数不能为零");
|
||||
return a / b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,118 +1,118 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using AppStore;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
public class CalculatorForm : Form
|
||||
{
|
||||
private TextBox display = new TextBox();
|
||||
private double firstNumber = 0;
|
||||
private string operation = "";
|
||||
|
||||
public CalculatorForm()
|
||||
{
|
||||
this.Text = "计算器";
|
||||
this.Size = new Size(300, 400);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
CreateControls();
|
||||
}
|
||||
|
||||
private void CreateControls()
|
||||
{
|
||||
// 显示框
|
||||
display = new TextBox();
|
||||
display.ReadOnly = true;
|
||||
display.TextAlign = HorizontalAlignment.Right;
|
||||
display.Font = new Font("Microsoft YaHei", 14);
|
||||
display.Size = new Size(260, 40);
|
||||
display.Location = new Point(20, 20);
|
||||
this.Controls.Add(display);
|
||||
|
||||
// 按钮布局
|
||||
string[] buttonLabels = {
|
||||
"7", "8", "9", "/",
|
||||
"4", "5", "6", "*",
|
||||
"1", "2", "3", "-",
|
||||
"0", ".", "=", "+"
|
||||
};
|
||||
|
||||
for (int i = 0; i < buttonLabels.Length; i++)
|
||||
{
|
||||
var btn = new Button();
|
||||
btn.Text = buttonLabels[i];
|
||||
btn.Size = new Size(60, 50);
|
||||
btn.Location = new Point(20 + (i % 4) * 65, 70 + (i / 4) * 55);
|
||||
btn.Font = new Font("Microsoft YaHei", 12);
|
||||
btn.Click += ButtonClickHandler;
|
||||
this.Controls.Add(btn);
|
||||
}
|
||||
|
||||
// 清除按钮
|
||||
var clearBtn = new Button();
|
||||
clearBtn.Text = "C";
|
||||
clearBtn.Size = new Size(260, 40);
|
||||
clearBtn.Location = new Point(20, 300);
|
||||
clearBtn.Font = new Font("Microsoft YaHei", 12);
|
||||
clearBtn.Click += (s, e) => {
|
||||
display.Text = "";
|
||||
firstNumber = 0;
|
||||
operation = "";
|
||||
};
|
||||
this.Controls.Add(clearBtn);
|
||||
}
|
||||
|
||||
private void ButtonClickHandler(object sender, EventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
if (button == null) return;
|
||||
|
||||
switch (button.Text)
|
||||
{
|
||||
case "+":
|
||||
case "-":
|
||||
case "*":
|
||||
case "/":
|
||||
if (!string.IsNullOrEmpty(display.Text))
|
||||
{
|
||||
firstNumber = double.Parse(display.Text);
|
||||
operation = button.Text;
|
||||
display.Text = "";
|
||||
}
|
||||
break;
|
||||
|
||||
case "=":
|
||||
if (!string.IsNullOrEmpty(operation) && !string.IsNullOrEmpty(display.Text))
|
||||
{
|
||||
double secondNumber = double.Parse(display.Text);
|
||||
double result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
result = operation switch
|
||||
{
|
||||
"+" => AppStore.Calculator.Add(firstNumber, secondNumber),
|
||||
"-" => AppStore.Calculator.Subtract(firstNumber, secondNumber),
|
||||
"*" => AppStore.Calculator.Multiply(firstNumber, secondNumber),
|
||||
"/" => AppStore.Calculator.Divide(firstNumber, secondNumber),
|
||||
_ => 0
|
||||
};
|
||||
|
||||
display.Text = result.ToString();
|
||||
}
|
||||
catch (DivideByZeroException)
|
||||
{
|
||||
MessageBox.Show("除数不能为零", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
operation = "";
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
display.Text += button.Text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using AppStore;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
public class CalculatorForm : Form
|
||||
{
|
||||
private TextBox display = new TextBox();
|
||||
private double firstNumber = 0;
|
||||
private string operation = "";
|
||||
|
||||
public CalculatorForm()
|
||||
{
|
||||
this.Text = "计算器";
|
||||
this.Size = new Size(300, 400);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
CreateControls();
|
||||
}
|
||||
|
||||
private void CreateControls()
|
||||
{
|
||||
// 显示框
|
||||
display = new TextBox();
|
||||
display.ReadOnly = true;
|
||||
display.TextAlign = HorizontalAlignment.Right;
|
||||
display.Font = new Font("Microsoft YaHei", 14);
|
||||
display.Size = new Size(260, 40);
|
||||
display.Location = new Point(20, 20);
|
||||
this.Controls.Add(display);
|
||||
|
||||
// 按钮布局
|
||||
string[] buttonLabels = {
|
||||
"7", "8", "9", "/",
|
||||
"4", "5", "6", "*",
|
||||
"1", "2", "3", "-",
|
||||
"0", ".", "=", "+"
|
||||
};
|
||||
|
||||
for (int i = 0; i < buttonLabels.Length; i++)
|
||||
{
|
||||
var btn = new Button();
|
||||
btn.Text = buttonLabels[i];
|
||||
btn.Size = new Size(60, 50);
|
||||
btn.Location = new Point(20 + (i % 4) * 65, 70 + (i / 4) * 55);
|
||||
btn.Font = new Font("Microsoft YaHei", 12);
|
||||
btn.Click += ButtonClickHandler;
|
||||
this.Controls.Add(btn);
|
||||
}
|
||||
|
||||
// 清除按钮
|
||||
var clearBtn = new Button();
|
||||
clearBtn.Text = "C";
|
||||
clearBtn.Size = new Size(260, 40);
|
||||
clearBtn.Location = new Point(20, 300);
|
||||
clearBtn.Font = new Font("Microsoft YaHei", 12);
|
||||
clearBtn.Click += (s, e) => {
|
||||
display.Text = "";
|
||||
firstNumber = 0;
|
||||
operation = "";
|
||||
};
|
||||
this.Controls.Add(clearBtn);
|
||||
}
|
||||
|
||||
private void ButtonClickHandler(object sender, EventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
if (button == null) return;
|
||||
|
||||
switch (button.Text)
|
||||
{
|
||||
case "+":
|
||||
case "-":
|
||||
case "*":
|
||||
case "/":
|
||||
if (!string.IsNullOrEmpty(display.Text))
|
||||
{
|
||||
firstNumber = double.Parse(display.Text);
|
||||
operation = button.Text;
|
||||
display.Text = "";
|
||||
}
|
||||
break;
|
||||
|
||||
case "=":
|
||||
if (!string.IsNullOrEmpty(operation) && !string.IsNullOrEmpty(display.Text))
|
||||
{
|
||||
double secondNumber = double.Parse(display.Text);
|
||||
double result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
result = operation switch
|
||||
{
|
||||
"+" => AppStore.Calculator.Add(firstNumber, secondNumber),
|
||||
"-" => AppStore.Calculator.Subtract(firstNumber, secondNumber),
|
||||
"*" => AppStore.Calculator.Multiply(firstNumber, secondNumber),
|
||||
"/" => AppStore.Calculator.Divide(firstNumber, secondNumber),
|
||||
_ => 0
|
||||
};
|
||||
|
||||
display.Text = result.ToString();
|
||||
}
|
||||
catch (DivideByZeroException)
|
||||
{
|
||||
MessageBox.Show("除数不能为零", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
operation = "";
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
display.Text += button.Text;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
public class CalculatorToolCard : ToolCard
|
||||
{
|
||||
public CalculatorToolCard()
|
||||
{
|
||||
ToolName = "计算器";
|
||||
try
|
||||
{
|
||||
string iconPath = Path.Combine(Application.StartupPath, "img", "resource", "png", "Calculator.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
ToolIcon = Image.FromFile(iconPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
this.ToolCardClicked += OnCalculatorCardClicked;
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
private void OnCalculatorCardClicked(object sender, EventArgs e)
|
||||
{
|
||||
var calculatorForm = new CalculatorForm();
|
||||
calculatorForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
public class CalculatorToolCard : ToolCard
|
||||
{
|
||||
public CalculatorToolCard()
|
||||
{
|
||||
ToolName = "计算器";
|
||||
try
|
||||
{
|
||||
string iconPath = Path.Combine(Application.StartupPath, "img", "resource", "png", "Calculator.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
ToolIcon = Image.FromFile(iconPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
this.ToolCardClicked += OnCalculatorCardClicked;
|
||||
UpdateDisplay();
|
||||
}
|
||||
|
||||
private void OnCalculatorCardClicked(object sender, EventArgs e)
|
||||
{
|
||||
var calculatorForm = new CalculatorForm();
|
||||
calculatorForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,136 +1,136 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using ZXing;
|
||||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
public class QrCodeGeneratorForm : Form
|
||||
{
|
||||
private TextBox? inputTextBox;
|
||||
private PictureBox? qrCodePictureBox;
|
||||
private Button? generateButton;
|
||||
private Button? saveButton;
|
||||
|
||||
public QrCodeGeneratorForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Text = "二维码生成器";
|
||||
this.Size = new Size(500, 600);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// 输入文本框
|
||||
inputTextBox = new TextBox();
|
||||
inputTextBox.Multiline = true;
|
||||
inputTextBox.ScrollBars = ScrollBars.Vertical;
|
||||
inputTextBox.Size = new Size(400, 100);
|
||||
inputTextBox.Location = new Point(50, 30);
|
||||
inputTextBox.PlaceholderText = "请输入要生成二维码的文本内容...";
|
||||
this.Controls.Add(inputTextBox);
|
||||
|
||||
// 生成按钮
|
||||
generateButton = new Button();
|
||||
generateButton.Text = "生成二维码";
|
||||
generateButton.Size = new Size(150, 40);
|
||||
generateButton.Location = new Point(50, 150);
|
||||
generateButton.Click += GenerateButton_Click;
|
||||
this.Controls.Add(generateButton);
|
||||
|
||||
// 二维码显示区域
|
||||
qrCodePictureBox = new PictureBox();
|
||||
qrCodePictureBox.Size = new Size(300, 300);
|
||||
qrCodePictureBox.Location = new Point(100, 220);
|
||||
qrCodePictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
qrCodePictureBox.BorderStyle = BorderStyle.FixedSingle;
|
||||
this.Controls.Add(qrCodePictureBox);
|
||||
|
||||
// 保存按钮
|
||||
saveButton = new Button();
|
||||
saveButton.Text = "保存二维码";
|
||||
saveButton.Size = new Size(150, 40);
|
||||
saveButton.Location = new Point(300, 150);
|
||||
saveButton.Click += SaveButton_Click;
|
||||
this.Controls.Add(saveButton);
|
||||
}
|
||||
|
||||
private void GenerateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(inputTextBox?.Text))
|
||||
{
|
||||
MessageBox.Show("请输入要生成二维码的文本内容", "提示",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var writer = new BarcodeWriterPixelData
|
||||
{
|
||||
Format = BarcodeFormat.QR_CODE,
|
||||
Options = new QrCodeEncodingOptions
|
||||
{
|
||||
Width = 300,
|
||||
Height = 300,
|
||||
Margin = 1
|
||||
}
|
||||
};
|
||||
|
||||
var pixelData = writer.Write(inputTextBox.Text);
|
||||
var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height),
|
||||
System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
try
|
||||
{
|
||||
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
}
|
||||
qrCodePictureBox!.Image = bitmap;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"生成二维码失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (qrCodePictureBox?.Image == null)
|
||||
{
|
||||
MessageBox.Show("请先生成二维码", "提示",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var saveDialog = new SaveFileDialog())
|
||||
{
|
||||
saveDialog.Filter = "PNG 图片|*.png|JPEG 图片|*.jpg|BMP 图片|*.bmp";
|
||||
saveDialog.Title = "保存二维码图片";
|
||||
if (saveDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
qrCodePictureBox!.Image.Save(saveDialog.FileName);
|
||||
MessageBox.Show("二维码保存成功", "成功",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"保存二维码失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using ZXing;
|
||||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
|
||||
namespace AppStore
|
||||
{
|
||||
public class QrCodeGeneratorForm : Form
|
||||
{
|
||||
private TextBox? inputTextBox;
|
||||
private PictureBox? qrCodePictureBox;
|
||||
private Button? generateButton;
|
||||
private Button? saveButton;
|
||||
|
||||
public QrCodeGeneratorForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.Text = "二维码生成器";
|
||||
this.Size = new Size(500, 600);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// 输入文本框
|
||||
inputTextBox = new TextBox();
|
||||
inputTextBox.Multiline = true;
|
||||
inputTextBox.ScrollBars = ScrollBars.Vertical;
|
||||
inputTextBox.Size = new Size(400, 100);
|
||||
inputTextBox.Location = new Point(50, 30);
|
||||
inputTextBox.PlaceholderText = "请输入要生成二维码的文本内容...";
|
||||
this.Controls.Add(inputTextBox);
|
||||
|
||||
// 生成按钮
|
||||
generateButton = new Button();
|
||||
generateButton.Text = "生成二维码";
|
||||
generateButton.Size = new Size(150, 40);
|
||||
generateButton.Location = new Point(50, 150);
|
||||
generateButton.Click += GenerateButton_Click;
|
||||
this.Controls.Add(generateButton);
|
||||
|
||||
// 二维码显示区域
|
||||
qrCodePictureBox = new PictureBox();
|
||||
qrCodePictureBox.Size = new Size(300, 300);
|
||||
qrCodePictureBox.Location = new Point(100, 220);
|
||||
qrCodePictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
qrCodePictureBox.BorderStyle = BorderStyle.FixedSingle;
|
||||
this.Controls.Add(qrCodePictureBox);
|
||||
|
||||
// 保存按钮
|
||||
saveButton = new Button();
|
||||
saveButton.Text = "保存二维码";
|
||||
saveButton.Size = new Size(150, 40);
|
||||
saveButton.Location = new Point(300, 150);
|
||||
saveButton.Click += SaveButton_Click;
|
||||
this.Controls.Add(saveButton);
|
||||
}
|
||||
|
||||
private void GenerateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(inputTextBox?.Text))
|
||||
{
|
||||
MessageBox.Show("请输入要生成二维码的文本内容", "提示",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var writer = new BarcodeWriterPixelData
|
||||
{
|
||||
Format = BarcodeFormat.QR_CODE,
|
||||
Options = new QrCodeEncodingOptions
|
||||
{
|
||||
Width = 300,
|
||||
Height = 300,
|
||||
Margin = 1
|
||||
}
|
||||
};
|
||||
|
||||
var pixelData = writer.Write(inputTextBox.Text);
|
||||
var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height),
|
||||
System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
||||
try
|
||||
{
|
||||
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
|
||||
}
|
||||
finally
|
||||
{
|
||||
bitmap.UnlockBits(bitmapData);
|
||||
}
|
||||
qrCodePictureBox!.Image = bitmap;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"生成二维码失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (qrCodePictureBox?.Image == null)
|
||||
{
|
||||
MessageBox.Show("请先生成二维码", "提示",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
using (var saveDialog = new SaveFileDialog())
|
||||
{
|
||||
saveDialog.Filter = "PNG 图片|*.png|JPEG 图片|*.jpg|BMP 图片|*.bmp";
|
||||
saveDialog.Title = "保存二维码图片";
|
||||
if (saveDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
qrCodePictureBox!.Image.Save(saveDialog.FileName);
|
||||
MessageBox.Show("二维码保存成功", "成功",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"保存二维码失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb/stb_image.h>
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void ShowHelp() {
|
||||
std::cout << "图片压缩工具 v1.0\n";
|
||||
std::cout << "用法: image_compressor [选项] 输入文件 输出文件\n";
|
||||
std::cout << "选项:\n";
|
||||
std::cout << " -t <type> 压缩类型: lossy(有损)/lossless(无损) (默认: lossy)\n";
|
||||
std::cout << " -q <quality> 压缩质量 (1-1000) (默认: 80)\n";
|
||||
std::cout << " -e 保留EXIF信息 (默认: 不保留)\n";
|
||||
std::cout << " -h 显示帮助信息\n";
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// 默认参数
|
||||
std::string compressType = "lossy";
|
||||
int quality = 80;
|
||||
bool keepExif = false;
|
||||
std::string inputFile;
|
||||
std::string outputFile;
|
||||
|
||||
// 解析命令行参数
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string arg = argv[i];
|
||||
if (arg == "-h") {
|
||||
ShowHelp();
|
||||
return 0;
|
||||
} else if (arg == "-t" && i + 1 < argc) {
|
||||
compressType = argv[++i];
|
||||
} else if (arg == "-q" && i + 1 < argc) {
|
||||
quality = std::stoi(argv[++i]);
|
||||
} else if (arg == "-e") {
|
||||
keepExif = true;
|
||||
} else if (inputFile.empty()) {
|
||||
inputFile = arg;
|
||||
} else {
|
||||
outputFile = arg;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证参数
|
||||
if (inputFile.empty() || outputFile.empty()) {
|
||||
std::cerr << "错误: 必须指定输入文件和输出文件\n";
|
||||
ShowHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (quality < 1 || quality > 1000) {
|
||||
std::cerr << "错误: 压缩质量必须在1-1000之间\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
std::cout << "正在压缩: " << inputFile << " -> " << outputFile << std::endl;
|
||||
std::cout << "类型: " << compressType << std::endl;
|
||||
std::cout << "质量: " << quality << std::endl;
|
||||
std::cout << "保留EXIF: " << (keepExif ? "是" : "否") << std::endl;
|
||||
|
||||
// 加载图片
|
||||
int width, height, channels;
|
||||
unsigned char* image = stbi_load(inputFile.c_str(), &width, &height, &channels, 0);
|
||||
if (!image) {
|
||||
std::cerr << "错误: 无法加载图片 " << inputFile << " - " << stbi_failure_reason() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 压缩图片
|
||||
int result = 0;
|
||||
if (compressType == "lossy") {
|
||||
// 有损压缩 (JPEG)
|
||||
int jpeg_quality = quality / 10; // 将1-1000映射到1-100
|
||||
jpeg_quality = std::max(1, std::min(jpeg_quality, 100));
|
||||
result = stbi_write_jpg(outputFile.c_str(), width, height, channels, image, jpeg_quality);
|
||||
} else {
|
||||
// 无损压缩 (PNG)
|
||||
result = stbi_write_png(outputFile.c_str(), width, height, channels, image, width * channels);
|
||||
}
|
||||
|
||||
// 释放内存
|
||||
stbi_image_free(image);
|
||||
|
||||
if (!result) {
|
||||
std::cerr << "错误: 无法保存图片 " << outputFile << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "压缩完成\n";
|
||||
return 0;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "发生错误: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb/stb_image.h>
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void ShowHelp() {
|
||||
std::cout << "图片压缩工具 v1.0\n";
|
||||
std::cout << "用法: image_compressor [选项] 输入文件 输出文件\n";
|
||||
std::cout << "选项:\n";
|
||||
std::cout << " -t <type> 压缩类型: lossy(有损)/lossless(无损) (默认: lossy)\n";
|
||||
std::cout << " -q <quality> 压缩质量 (1-1000) (默认: 80)\n";
|
||||
std::cout << " -e 保留EXIF信息 (默认: 不保留)\n";
|
||||
std::cout << " -h 显示帮助信息\n";
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// 默认参数
|
||||
std::string compressType = "lossy";
|
||||
int quality = 80;
|
||||
bool keepExif = false;
|
||||
std::string inputFile;
|
||||
std::string outputFile;
|
||||
|
||||
// 解析命令行参数
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string arg = argv[i];
|
||||
if (arg == "-h") {
|
||||
ShowHelp();
|
||||
return 0;
|
||||
} else if (arg == "-t" && i + 1 < argc) {
|
||||
compressType = argv[++i];
|
||||
} else if (arg == "-q" && i + 1 < argc) {
|
||||
quality = std::stoi(argv[++i]);
|
||||
} else if (arg == "-e") {
|
||||
keepExif = true;
|
||||
} else if (inputFile.empty()) {
|
||||
inputFile = arg;
|
||||
} else {
|
||||
outputFile = arg;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证参数
|
||||
if (inputFile.empty() || outputFile.empty()) {
|
||||
std::cerr << "错误: 必须指定输入文件和输出文件\n";
|
||||
ShowHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (quality < 1 || quality > 1000) {
|
||||
std::cerr << "错误: 压缩质量必须在1-1000之间\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
std::cout << "正在压缩: " << inputFile << " -> " << outputFile << std::endl;
|
||||
std::cout << "类型: " << compressType << std::endl;
|
||||
std::cout << "质量: " << quality << std::endl;
|
||||
std::cout << "保留EXIF: " << (keepExif ? "是" : "否") << std::endl;
|
||||
|
||||
// 加载图片
|
||||
int width, height, channels;
|
||||
unsigned char* image = stbi_load(inputFile.c_str(), &width, &height, &channels, 0);
|
||||
if (!image) {
|
||||
std::cerr << "错误: 无法加载图片 " << inputFile << " - " << stbi_failure_reason() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 压缩图片
|
||||
int result = 0;
|
||||
if (compressType == "lossy") {
|
||||
// 有损压缩 (JPEG)
|
||||
int jpeg_quality = quality / 10; // 将1-1000映射到1-100
|
||||
jpeg_quality = std::max(1, std::min(jpeg_quality, 100));
|
||||
result = stbi_write_jpg(outputFile.c_str(), width, height, channels, image, jpeg_quality);
|
||||
} else {
|
||||
// 无损压缩 (PNG)
|
||||
result = stbi_write_png(outputFile.c_str(), width, height, channels, image, width * channels);
|
||||
}
|
||||
|
||||
// 释放内存
|
||||
stbi_image_free(image);
|
||||
|
||||
if (!result) {
|
||||
std::cerr << "错误: 无法保存图片 " << outputFile << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "压缩完成\n";
|
||||
return 0;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "发生错误: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
bool IsAdmin() {
|
||||
BOOL isAdmin = FALSE;
|
||||
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
|
||||
PSID AdminGroup;
|
||||
|
||||
if (AllocateAndInitializeSid(&NtAuthority, 2,
|
||||
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
||||
0, 0, 0, 0, 0, 0, &AdminGroup)) {
|
||||
if (!CheckTokenMembership(NULL, AdminGroup, &isAdmin)) {
|
||||
isAdmin = FALSE;
|
||||
}
|
||||
FreeSid(AdminGroup);
|
||||
}
|
||||
return isAdmin == TRUE;
|
||||
}
|
||||
|
||||
void CleanDirectory(const fs::path& dir, size_t& deletedCount, size_t& errorCount) {
|
||||
if (!fs::exists(dir)) {
|
||||
std::cout << "目录不存在: " << dir << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& entry : fs::directory_iterator(dir)) {
|
||||
try {
|
||||
if (fs::is_regular_file(entry)) {
|
||||
fs::remove(entry);
|
||||
deletedCount++;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "删除文件失败: " << entry.path() << " - " << e.what() << std::endl;
|
||||
errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
if (!IsAdmin()) {
|
||||
std::cerr << "请以管理员身份运行此程序以清理所有目录" << std::endl;
|
||||
}
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
size_t totalDeleted = 0;
|
||||
size_t totalErrors = 0;
|
||||
|
||||
// 定义要清理的目录列表
|
||||
std::vector<fs::path> directories = {
|
||||
"C:\\Windows\\Temp",
|
||||
fs::path(std::getenv("USERPROFILE")) / "AppData" / "Local" / "Temp",
|
||||
"C:\\Windows\\SoftwareDistribution\\Download",
|
||||
"C:\\Windows\\Logs",
|
||||
"C:\\Windows\\Minidump"
|
||||
};
|
||||
|
||||
// 只有管理员才能清理Prefetch目录
|
||||
if (IsAdmin()) {
|
||||
directories.push_back("C:\\Windows\\Prefetch");
|
||||
}
|
||||
|
||||
// 清理每个目录
|
||||
for (const auto& dir : directories) {
|
||||
size_t dirDeleted = 0;
|
||||
size_t dirErrors = 0;
|
||||
|
||||
std::cout << "正在清理: " << dir << std::endl;
|
||||
CleanDirectory(dir, dirDeleted, dirErrors);
|
||||
|
||||
totalDeleted += dirDeleted;
|
||||
totalErrors += dirErrors;
|
||||
|
||||
std::cout << "已删除 " << dirDeleted << " 个文件" << std::endl;
|
||||
}
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
std::cout << "\n清理完成:" << std::endl;
|
||||
std::cout << "总共删除文件数: " << totalDeleted << std::endl;
|
||||
std::cout << "总共错误数: " << totalErrors << std::endl;
|
||||
std::cout << "耗时: " << duration.count() << " 毫秒" << std::endl;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "发生错误: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <windows.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
bool IsAdmin() {
|
||||
BOOL isAdmin = FALSE;
|
||||
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
|
||||
PSID AdminGroup;
|
||||
|
||||
if (AllocateAndInitializeSid(&NtAuthority, 2,
|
||||
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
||||
0, 0, 0, 0, 0, 0, &AdminGroup)) {
|
||||
if (!CheckTokenMembership(NULL, AdminGroup, &isAdmin)) {
|
||||
isAdmin = FALSE;
|
||||
}
|
||||
FreeSid(AdminGroup);
|
||||
}
|
||||
return isAdmin == TRUE;
|
||||
}
|
||||
|
||||
void CleanDirectory(const fs::path& dir, size_t& deletedCount, size_t& errorCount) {
|
||||
if (!fs::exists(dir)) {
|
||||
std::cout << "目录不存在: " << dir << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& entry : fs::directory_iterator(dir)) {
|
||||
try {
|
||||
if (fs::is_regular_file(entry)) {
|
||||
fs::remove(entry);
|
||||
deletedCount++;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "删除文件失败: " << entry.path() << " - " << e.what() << std::endl;
|
||||
errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
if (!IsAdmin()) {
|
||||
std::cerr << "请以管理员身份运行此程序以清理所有目录" << std::endl;
|
||||
}
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
size_t totalDeleted = 0;
|
||||
size_t totalErrors = 0;
|
||||
|
||||
// 定义要清理的目录列表
|
||||
std::vector<fs::path> directories = {
|
||||
"C:\\Windows\\Temp",
|
||||
fs::path(std::getenv("USERPROFILE")) / "AppData" / "Local" / "Temp",
|
||||
"C:\\Windows\\SoftwareDistribution\\Download",
|
||||
"C:\\Windows\\Logs",
|
||||
"C:\\Windows\\Minidump"
|
||||
};
|
||||
|
||||
// 只有管理员才能清理Prefetch目录
|
||||
if (IsAdmin()) {
|
||||
directories.push_back("C:\\Windows\\Prefetch");
|
||||
}
|
||||
|
||||
// 清理每个目录
|
||||
for (const auto& dir : directories) {
|
||||
size_t dirDeleted = 0;
|
||||
size_t dirErrors = 0;
|
||||
|
||||
std::cout << "正在清理: " << dir << std::endl;
|
||||
CleanDirectory(dir, dirDeleted, dirErrors);
|
||||
|
||||
totalDeleted += dirDeleted;
|
||||
totalErrors += dirErrors;
|
||||
|
||||
std::cout << "已删除 " << dirDeleted << " 个文件" << std::endl;
|
||||
}
|
||||
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||
|
||||
std::cout << "\n清理完成:" << std::endl;
|
||||
std::cout << "总共删除文件数: " << totalDeleted << std::endl;
|
||||
std::cout << "总共错误数: " << totalErrors << std::endl;
|
||||
std::cout << "耗时: " << duration.count() << " 毫秒" << std::endl;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "发生错误: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public interface IImageViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载图片文件
|
||||
/// </summary>
|
||||
/// <param name="filePath">图片文件路径</param>
|
||||
void LoadImage(string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// 显示图片
|
||||
/// </summary>
|
||||
void ShowImage();
|
||||
|
||||
/// <summary>
|
||||
/// 关闭图片查看器
|
||||
/// </summary>
|
||||
void CloseViewer();
|
||||
}
|
||||
}
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public interface IImageViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载图片文件
|
||||
/// </summary>
|
||||
/// <param name="filePath">图片文件路径</param>
|
||||
void LoadImage(string filePath);
|
||||
|
||||
/// <summary>
|
||||
/// 显示图片
|
||||
/// </summary>
|
||||
void ShowImage();
|
||||
|
||||
/// <summary>
|
||||
/// 关闭图片查看器
|
||||
/// </summary>
|
||||
void CloseViewer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public static class ImageFileHandler
|
||||
{
|
||||
private static readonly string[] SupportedExtensions =
|
||||
{
|
||||
".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff", ".tif"
|
||||
};
|
||||
|
||||
public static bool IsImageFile(string filePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return false;
|
||||
|
||||
string extension = Path.GetExtension(filePath).ToLower();
|
||||
return Array.Exists(SupportedExtensions, ext => ext == extension);
|
||||
}
|
||||
|
||||
public static Image LoadImage(string filePath)
|
||||
{
|
||||
if (!IsImageFile(filePath))
|
||||
throw new ArgumentException("不支持的图片格式");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException("图片文件不存在", filePath);
|
||||
|
||||
try
|
||||
{
|
||||
return Image.FromFile(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"无法加载图片: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public static class ImageFileHandler
|
||||
{
|
||||
private static readonly string[] SupportedExtensions =
|
||||
{
|
||||
".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff", ".tif"
|
||||
};
|
||||
|
||||
public static bool IsImageFile(string filePath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
return false;
|
||||
|
||||
string extension = Path.GetExtension(filePath).ToLower();
|
||||
return Array.Exists(SupportedExtensions, ext => ext == extension);
|
||||
}
|
||||
|
||||
public static Image LoadImage(string filePath)
|
||||
{
|
||||
if (!IsImageFile(filePath))
|
||||
throw new ArgumentException("不支持的图片格式");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
throw new FileNotFoundException("图片文件不存在", filePath);
|
||||
|
||||
try
|
||||
{
|
||||
return Image.FromFile(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"无法加载图片: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using KortAppZ.Tools.Viewer;
|
||||
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public class ImageViewerForm : Form
|
||||
{
|
||||
private Button? openButton;
|
||||
|
||||
public ImageViewerForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.openButton = new Button();
|
||||
//
|
||||
// openButton
|
||||
//
|
||||
this.openButton.Text = "打开图片";
|
||||
this.openButton.Size = new Size(120, 40);
|
||||
this.openButton.Font = new Font("Microsoft YaHei", 10);
|
||||
this.openButton.Anchor = AnchorStyles.None;
|
||||
this.openButton.Click += new EventHandler(OpenButton_Click);
|
||||
|
||||
// 初始位置
|
||||
CenterOpenButton();
|
||||
|
||||
// 窗体大小变化时重新居中按钮
|
||||
this.Resize += (s, e) => CenterOpenButton();
|
||||
|
||||
//
|
||||
// ImageViewerForm
|
||||
//
|
||||
this.Text = "图片查看器";
|
||||
this.ClientSize = new Size(400, 300);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.MinimumSize = new Size(300, 200);
|
||||
this.MaximizeBox = false;
|
||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
|
||||
this.Controls.Add(this.openButton);
|
||||
}
|
||||
|
||||
private void CenterOpenButton()
|
||||
{
|
||||
if (openButton != null)
|
||||
{
|
||||
openButton.Location = new Point(
|
||||
(this.ClientSize.Width - openButton.Width) / 2,
|
||||
(this.ClientSize.Height - openButton.Height) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff;*.tif|所有文件|*.*";
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string filePath = openFileDialog.FileName;
|
||||
ShowImage(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowImage(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ImageFileHandler.IsImageFile(filePath))
|
||||
{
|
||||
MessageBox.Show("不支持的图片格式", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
ImageDisplayForm displayForm = new ImageDisplayForm();
|
||||
displayForm.LoadImage(filePath);
|
||||
displayForm.Show();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"无法加载图片: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using KortAppZ.Tools.Viewer;
|
||||
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public class ImageViewerForm : Form
|
||||
{
|
||||
private Button? openButton;
|
||||
|
||||
public ImageViewerForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.openButton = new Button();
|
||||
//
|
||||
// openButton
|
||||
//
|
||||
this.openButton.Text = "打开图片";
|
||||
this.openButton.Size = new Size(120, 40);
|
||||
this.openButton.Font = new Font("Microsoft YaHei", 10);
|
||||
this.openButton.Anchor = AnchorStyles.None;
|
||||
this.openButton.Click += new EventHandler(OpenButton_Click);
|
||||
|
||||
// 初始位置
|
||||
CenterOpenButton();
|
||||
|
||||
// 窗体大小变化时重新居中按钮
|
||||
this.Resize += (s, e) => CenterOpenButton();
|
||||
|
||||
//
|
||||
// ImageViewerForm
|
||||
//
|
||||
this.Text = "图片查看器";
|
||||
this.ClientSize = new Size(400, 300);
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
this.MinimumSize = new Size(300, 200);
|
||||
this.MaximizeBox = false;
|
||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
|
||||
this.Controls.Add(this.openButton);
|
||||
}
|
||||
|
||||
private void CenterOpenButton()
|
||||
{
|
||||
if (openButton != null)
|
||||
{
|
||||
openButton.Location = new Point(
|
||||
(this.ClientSize.Width - openButton.Width) / 2,
|
||||
(this.ClientSize.Height - openButton.Height) / 2);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff;*.tif|所有文件|*.*";
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string filePath = openFileDialog.FileName;
|
||||
ShowImage(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowImage(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ImageFileHandler.IsImageFile(filePath))
|
||||
{
|
||||
MessageBox.Show("不支持的图片格式", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
ImageDisplayForm displayForm = new ImageDisplayForm();
|
||||
displayForm.LoadImage(filePath);
|
||||
displayForm.Show();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"无法加载图片: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using AppStore;
|
||||
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public class ImageViewerToolCard : ToolCard
|
||||
{
|
||||
public ImageViewerToolCard()
|
||||
{
|
||||
this.ToolName = "图片查看";
|
||||
|
||||
try
|
||||
{
|
||||
string iconPath = Path.Combine(Application.StartupPath, "img", "resource", "png", "ImageCompressor.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
this.ToolIcon = Image.FromFile(iconPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
|
||||
this.ToolCardClicked += (s, e) => {
|
||||
try
|
||||
{
|
||||
ImageViewerForm viewerForm = new ImageViewerForm();
|
||||
viewerForm.Show();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"打开图片查看器失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using AppStore;
|
||||
|
||||
namespace KortAppZ.Tools.Viewer
|
||||
{
|
||||
public class ImageViewerToolCard : ToolCard
|
||||
{
|
||||
public ImageViewerToolCard()
|
||||
{
|
||||
this.ToolName = "图片查看";
|
||||
|
||||
try
|
||||
{
|
||||
string iconPath = Path.Combine(Application.StartupPath, "img", "resource", "png", "ImageCompressor.png");
|
||||
if (File.Exists(iconPath))
|
||||
{
|
||||
this.ToolIcon = Image.FromFile(iconPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
this.ToolIcon = SystemIcons.Application.ToBitmap();
|
||||
}
|
||||
|
||||
this.ToolCardClicked += (s, e) => {
|
||||
try
|
||||
{
|
||||
ImageViewerForm viewerForm = new ImageViewerForm();
|
||||
viewerForm.Show();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"打开图片查看器失败: {ex.Message}", "错误",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
};
|
||||
|
||||
this.UpdateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user