📄 zipfile.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace ZipFile
{
using Compression;
/// <summary>
/// ZipFile 的摘要说明。
/// </summary>
public class ZipFile : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabMain;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabUnzip;
private System.Windows.Forms.Label lblBlockSize;
private System.Windows.Forms.Label lblZipLevel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblZipFile;
private System.Windows.Forms.Button btnZip;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnUnzip;
private System.Windows.Forms.TextBox txtZipFileName;
private System.Windows.Forms.TextBox txtSourcePath;
private System.Windows.Forms.TextBox txtUnzipPath;
private System.Windows.Forms.TextBox txtZipFile;
private System.Windows.Forms.NumericUpDown numLevel;
private System.Windows.Forms.NumericUpDown numBlockSize;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ZipFile()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public static void Main()
{
Application.Run(new ZipFile());
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tabMain = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabUnzip = new System.Windows.Forms.TabPage();
this.lblBlockSize = new System.Windows.Forms.Label();
this.lblZipLevel = new System.Windows.Forms.Label();
this.txtZipFileName = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.lblZipFile = new System.Windows.Forms.Label();
this.numLevel = new System.Windows.Forms.NumericUpDown();
this.txtSourcePath = new System.Windows.Forms.TextBox();
this.btnZip = new System.Windows.Forms.Button();
this.txtUnzipPath = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtZipFile = new System.Windows.Forms.TextBox();
this.btnUnzip = new System.Windows.Forms.Button();
this.numBlockSize = new System.Windows.Forms.NumericUpDown();
this.tabMain.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabUnzip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numLevel)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numBlockSize)).BeginInit();
this.SuspendLayout();
//
// tabMain
//
this.tabMain.Controls.Add(this.tabPage1);
this.tabMain.Controls.Add(this.tabUnzip);
this.tabMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabMain.Location = new System.Drawing.Point(0, 0);
this.tabMain.Name = "tabMain";
this.tabMain.SelectedIndex = 0;
this.tabMain.Size = new System.Drawing.Size(292, 245);
this.tabMain.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.numBlockSize);
this.tabPage1.Controls.Add(this.lblBlockSize);
this.tabPage1.Controls.Add(this.lblZipLevel);
this.tabPage1.Controls.Add(this.txtZipFileName);
this.tabPage1.Controls.Add(this.label1);
this.tabPage1.Controls.Add(this.lblZipFile);
this.tabPage1.Controls.Add(this.numLevel);
this.tabPage1.Controls.Add(this.txtSourcePath);
this.tabPage1.Controls.Add(this.btnZip);
this.tabPage1.Location = new System.Drawing.Point(4, 21);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(284, 220);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "压缩";
//
// tabUnzip
//
this.tabUnzip.Controls.Add(this.btnUnzip);
this.tabUnzip.Controls.Add(this.txtUnzipPath);
this.tabUnzip.Controls.Add(this.label2);
this.tabUnzip.Controls.Add(this.label3);
this.tabUnzip.Controls.Add(this.txtZipFile);
this.tabUnzip.Location = new System.Drawing.Point(4, 21);
this.tabUnzip.Name = "tabUnzip";
this.tabUnzip.Size = new System.Drawing.Size(284, 220);
this.tabUnzip.TabIndex = 1;
this.tabUnzip.Text = "解压缩";
//
// lblBlockSize
//
this.lblBlockSize.Location = new System.Drawing.Point(8, 152);
this.lblBlockSize.Name = "lblBlockSize";
this.lblBlockSize.Size = new System.Drawing.Size(80, 18);
this.lblBlockSize.TabIndex = 17;
this.lblBlockSize.Text = "块大小:";
this.lblBlockSize.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblZipLevel
//
this.lblZipLevel.Location = new System.Drawing.Point(8, 120);
this.lblZipLevel.Name = "lblZipLevel";
this.lblZipLevel.Size = new System.Drawing.Size(80, 18);
this.lblZipLevel.TabIndex = 16;
this.lblZipLevel.Text = "压缩级别:";
this.lblZipLevel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtZipFileName
//
this.txtZipFileName.Location = new System.Drawing.Point(8, 84);
this.txtZipFileName.Name = "txtZipFileName";
this.txtZipFileName.Size = new System.Drawing.Size(265, 21);
this.txtZipFileName.TabIndex = 15;
this.txtZipFileName.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 18);
this.label1.TabIndex = 14;
this.label1.Text = "压缩后文件:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblZipFile
//
this.lblZipFile.Location = new System.Drawing.Point(8, 8);
this.lblZipFile.Name = "lblZipFile";
this.lblZipFile.Size = new System.Drawing.Size(80, 18);
this.lblZipFile.TabIndex = 12;
this.lblZipFile.Text = "被压缩文件:";
this.lblZipFile.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// numLevel
//
this.numLevel.Location = new System.Drawing.Point(104, 120);
this.numLevel.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.numLevel.Name = "numLevel";
this.numLevel.TabIndex = 11;
this.numLevel.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
//
// txtSourcePath
//
this.txtSourcePath.Location = new System.Drawing.Point(8, 28);
this.txtSourcePath.Name = "txtSourcePath";
this.txtSourcePath.Size = new System.Drawing.Size(267, 21);
this.txtSourcePath.TabIndex = 10;
this.txtSourcePath.Text = "";
//
// btnZip
//
this.btnZip.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnZip.Location = new System.Drawing.Point(200, 184);
this.btnZip.Name = "btnZip";
this.btnZip.Size = new System.Drawing.Size(75, 21);
this.btnZip.TabIndex = 9;
this.btnZip.Text = "开始压缩";
this.btnZip.Click += new System.EventHandler(this.btnZip_Click);
//
// txtUnzipPath
//
this.txtUnzipPath.Location = new System.Drawing.Point(9, 84);
this.txtUnzipPath.Name = "txtUnzipPath";
this.txtUnzipPath.Size = new System.Drawing.Size(265, 21);
this.txtUnzipPath.TabIndex = 19;
this.txtUnzipPath.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 18);
this.label2.TabIndex = 18;
this.label2.Text = "压缩后文件:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 8);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 18);
this.label3.TabIndex = 17;
this.label3.Text = "被压缩文件:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtZipFile
//
this.txtZipFile.Location = new System.Drawing.Point(8, 28);
this.txtZipFile.Name = "txtZipFile";
this.txtZipFile.Size = new System.Drawing.Size(267, 21);
this.txtZipFile.TabIndex = 16;
this.txtZipFile.Text = "";
//
// btnUnzip
//
this.btnUnzip.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnUnzip.Location = new System.Drawing.Point(200, 120);
this.btnUnzip.Name = "btnUnzip";
this.btnUnzip.Size = new System.Drawing.Size(75, 21);
this.btnUnzip.TabIndex = 20;
this.btnUnzip.Text = "开始解压缩";
this.btnUnzip.Click += new System.EventHandler(this.btnUnzip_Click);
//
// numBlockSize
//
this.numBlockSize.Increment = new System.Decimal(new int[] {
1024,
0,
0,
0});
this.numBlockSize.Location = new System.Drawing.Point(104, 152);
this.numBlockSize.Maximum = new System.Decimal(new int[] {
10240,
0,
0,
0});
this.numBlockSize.Minimum = new System.Decimal(new int[] {
1024,
0,
0,
0});
this.numBlockSize.Name = "numBlockSize";
this.numBlockSize.TabIndex = 18;
this.numBlockSize.Value = new System.Decimal(new int[] {
1024,
0,
0,
0});
//
// ZipFile
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 245);
this.Controls.Add(this.tabMain);
this.MaximizeBox = false;
this.Name = "ZipFile";
this.Text = "ZipFile";
this.tabMain.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabUnzip.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numLevel)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numBlockSize)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void btnZip_Click(object sender, System.EventArgs e)
{
Zip zipClass = new Zip((int)numLevel.Value, (int)numBlockSize.Value);
try
{
zipClass.ZipDirectory(this.txtSourcePath.Text, this.txtZipFileName.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
MessageBox.Show("压缩完成。");
}
private void btnUnzip_Click(object sender, System.EventArgs e)
{
Unzip unzipClass = new Unzip();
try
{
unzipClass.UnZipFile(this.txtZipFile.Text, txtUnzipPath.Text);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
MessageBox.Show("解压缩完成。");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -