📄 mainform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace RSACryptoPad
{
public class MainForm : Form
{
private FontDialog fontDialog;
private IContainer components;
private Label processingLabel;
private MenuItem aboutMenuItem;
private MenuItem copyMenuItem;
private MenuItem cutMenuItem;
private MenuItem decryptMenuItem;
private MenuItem deleteMenuItem;
private MenuItem editMenuItem;
private MenuItem encryptionMenuItem;
private MenuItem encryptMenuItem;
private MenuItem exitMenuItem;
private MenuItem fileMenuItem;
private MenuItem fontMenuItem;
private MenuItem formatMenuItem;
private MenuItem generateKeyPairMenuItem;
private MenuItem helpMenuItem;
private MenuItem newFileMenuItem;
private MenuItem openFileMenuItem;
private MenuItem pasteMenuItem;
private MenuItem saveAsFileMenuItem;
private MenuItem saveMenuItem;
private MenuItem selectAllmenuItem;
private MenuItem separator1;
private MenuItem separator2;
private MenuItem separator3;
private MenuItem undoMenuItem;
private MenuItem wordWrapMenuItem;
private MainMenu mainMenu;
private OpenFileDialog openFileDialog;
private Panel panel;
private PictureBox pictureBox;
private SaveFileDialog saveFileDialog;
private TextBox inputTextBox;
public static int currentBitStrength = 0;
private bool cleanForm = true;
private string currentFileName = "Untitled";
public delegate void FinishedProcessDelegate();
public delegate void UpdateBitStrengthDelegate( int bitStrength );
public delegate void UpdateTextDelegate( string inputText );
public MainForm()
{ InitializeComponent(); }
public MainForm( string fileName )
{
InitializeComponent();
if( File.Exists( fileName ) )
{
currentFileName = fileName;
StreamReader streamReader = new StreamReader( fileName, true );
SetText( streamReader.ReadToEnd() );
streamReader.Close();
this.Text = GetFileName( fileName ) + " - RSACryptoPad";
cleanForm = true;
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
{ components.Dispose(); }
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager( typeof( MainForm ) );
this.mainMenu = new System.Windows.Forms.MainMenu( this.components );
this.fileMenuItem = new System.Windows.Forms.MenuItem();
this.newFileMenuItem = new System.Windows.Forms.MenuItem();
this.openFileMenuItem = new System.Windows.Forms.MenuItem();
this.saveMenuItem = new System.Windows.Forms.MenuItem();
this.saveAsFileMenuItem = new System.Windows.Forms.MenuItem();
this.separator1 = new System.Windows.Forms.MenuItem();
this.exitMenuItem = new System.Windows.Forms.MenuItem();
this.editMenuItem = new System.Windows.Forms.MenuItem();
this.undoMenuItem = new System.Windows.Forms.MenuItem();
this.separator2 = new System.Windows.Forms.MenuItem();
this.cutMenuItem = new System.Windows.Forms.MenuItem();
this.copyMenuItem = new System.Windows.Forms.MenuItem();
this.pasteMenuItem = new System.Windows.Forms.MenuItem();
this.deleteMenuItem = new System.Windows.Forms.MenuItem();
this.separator3 = new System.Windows.Forms.MenuItem();
this.selectAllmenuItem = new System.Windows.Forms.MenuItem();
this.formatMenuItem = new System.Windows.Forms.MenuItem();
this.wordWrapMenuItem = new System.Windows.Forms.MenuItem();
this.fontMenuItem = new System.Windows.Forms.MenuItem();
this.encryptionMenuItem = new System.Windows.Forms.MenuItem();
this.encryptMenuItem = new System.Windows.Forms.MenuItem();
this.decryptMenuItem = new System.Windows.Forms.MenuItem();
this.generateKeyPairMenuItem = new System.Windows.Forms.MenuItem();
this.helpMenuItem = new System.Windows.Forms.MenuItem();
this.aboutMenuItem = new System.Windows.Forms.MenuItem();
this.inputTextBox = new System.Windows.Forms.TextBox();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.fontDialog = new System.Windows.Forms.FontDialog();
this.panel = new System.Windows.Forms.Panel();
this.processingLabel = new System.Windows.Forms.Label();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.panel.SuspendLayout();
( ( System.ComponentModel.ISupportInitialize )( this.pictureBox ) ).BeginInit();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.fileMenuItem, this.editMenuItem, this.formatMenuItem, this.encryptionMenuItem, this.helpMenuItem} );
//
// fileMenuItem
//
this.fileMenuItem.Index = 0;
this.fileMenuItem.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.newFileMenuItem, this.openFileMenuItem, this.saveMenuItem, this.saveAsFileMenuItem, this.separator1, this.exitMenuItem} );
this.fileMenuItem.Text = "File";
//
// newFileMenuItem
//
this.newFileMenuItem.Index = 0;
this.newFileMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.newFileMenuItem.Text = "New";
this.newFileMenuItem.Click += new System.EventHandler( this.newFileMenuItem_Click );
//
// openFileMenuItem
//
this.openFileMenuItem.Index = 1;
this.openFileMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.openFileMenuItem.Text = "Open...";
this.openFileMenuItem.Click += new System.EventHandler( this.openFileMenuItem_Click );
//
// saveMenuItem
//
this.saveMenuItem.Index = 2;
this.saveMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.saveMenuItem.Text = "Save...";
this.saveMenuItem.Click += new System.EventHandler( this.saveMenuItem_Click );
//
// saveAsFileMenuItem
//
this.saveAsFileMenuItem.Index = 3;
this.saveAsFileMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.saveAsFileMenuItem.Text = "Save As... ";
this.saveAsFileMenuItem.Click += new System.EventHandler( this.saveAsFileMenuItem_Click );
//
// separator1
//
this.separator1.Index = 4;
this.separator1.Text = "-";
//
// exitMenuItem
//
this.exitMenuItem.Index = 5;
this.exitMenuItem.Text = "Exit ";
this.exitMenuItem.Click += new System.EventHandler( this.exitMenuItem_Click );
//
// editMenuItem
//
this.editMenuItem.Index = 1;
this.editMenuItem.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.undoMenuItem, this.separator2, this.cutMenuItem, this.copyMenuItem, this.pasteMenuItem, this.deleteMenuItem, this.separator3, this.selectAllmenuItem} );
this.editMenuItem.Text = "Edit";
//
// undoMenuItem
//
this.undoMenuItem.Index = 0;
this.undoMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
this.undoMenuItem.Text = "Undo";
this.undoMenuItem.Click += new System.EventHandler( this.undoMenuItem_Click );
//
// separator2
//
this.separator2.Index = 1;
this.separator2.Text = "-";
//
// cutMenuItem
//
this.cutMenuItem.Index = 2;
this.cutMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.cutMenuItem.Text = "Cut";
this.cutMenuItem.Click += new System.EventHandler( this.cutMenuItem_Click );
//
// copyMenuItem
//
this.copyMenuItem.Index = 3;
this.copyMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.copyMenuItem.Text = "Copy";
this.copyMenuItem.Click += new System.EventHandler( this.copyMenuItem_Click );
//
// pasteMenuItem
//
this.pasteMenuItem.Index = 4;
this.pasteMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
this.pasteMenuItem.Text = "Paste";
this.pasteMenuItem.Click += new System.EventHandler( this.pasteMenuItem_Click );
//
// deleteMenuItem
//
this.deleteMenuItem.Index = 5;
this.deleteMenuItem.Shortcut = System.Windows.Forms.Shortcut.Del;
this.deleteMenuItem.Text = "Delete";
this.deleteMenuItem.Click += new System.EventHandler( this.deleteMenuItem_Click );
//
// separator3
//
this.separator3.Index = 6;
this.separator3.Text = "-";
//
// selectAllmenuItem
//
this.selectAllmenuItem.Index = 7;
this.selectAllmenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.selectAllmenuItem.Text = "Select All";
this.selectAllmenuItem.Click += new System.EventHandler( this.selectAllmenuItem_Click );
//
// formatMenuItem
//
this.formatMenuItem.Index = 2;
this.formatMenuItem.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.wordWrapMenuItem, this.fontMenuItem} );
this.formatMenuItem.Text = "Format";
//
// wordWrapMenuItem
//
this.wordWrapMenuItem.Checked = true;
this.wordWrapMenuItem.Index = 0;
this.wordWrapMenuItem.RadioCheck = true;
this.wordWrapMenuItem.Text = "Word Wrap";
this.wordWrapMenuItem.Click += new System.EventHandler( this.wordWrapMenuItem_Click );
//
// fontMenuItem
//
this.fontMenuItem.Index = 1;
this.fontMenuItem.Text = "Font...";
this.fontMenuItem.Click += new System.EventHandler( this.fontMenuItem_Click );
//
// encryptionMenuItem
//
this.encryptionMenuItem.Index = 3;
this.encryptionMenuItem.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.encryptMenuItem, this.decryptMenuItem, this.generateKeyPairMenuItem} );
this.encryptionMenuItem.Text = "Encryption";
//
// encryptMenuItem
//
this.encryptMenuItem.Index = 0;
this.encryptMenuItem.Text = "Encrypt...";
this.encryptMenuItem.Click += new System.EventHandler( this.encryptMenuItem_Click );
//
// decryptMenuItem
//
this.decryptMenuItem.Index = 1;
this.decryptMenuItem.Text = "Decrypt...";
this.decryptMenuItem.Click += new System.EventHandler( this.decryptMenuItem_Click );
//
// generateKeyPairMenuItem
//
this.generateKeyPairMenuItem.Index = 2;
this.generateKeyPairMenuItem.Text = "Generate Key Pair...";
this.generateKeyPairMenuItem.Click += new System.EventHandler( this.generateKeyPairMenuItem_Click );
//
// helpMenuItem
//
this.helpMenuItem.Index = 4;
this.helpMenuItem.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.aboutMenuItem} );
this.helpMenuItem.Text = "Help";
//
// aboutMenuItem
//
this.aboutMenuItem.Index = 0;
this.aboutMenuItem.Text = "About RSACryptoPad";
this.aboutMenuItem.Click += new System.EventHandler( this.aboutMenuItem_Click );
//
// inputTextBox
//
this.inputTextBox.AcceptsReturn = true;
this.inputTextBox.AcceptsTab = true;
this.inputTextBox.AllowDrop = true;
this.inputTextBox.BackColor = System.Drawing.Color.Black;
this.inputTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.inputTextBox.Font = new System.Drawing.Font( "Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) );
this.inputTextBox.ForeColor = System.Drawing.Color.LightGreen;
this.inputTextBox.Location = new System.Drawing.Point( 0, 0 );
this.inputTextBox.Multiline = true;
this.inputTextBox.Name = "inputTextBox";
this.inputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.inputTextBox.Size = new System.Drawing.Size( 634, 427 );
this.inputTextBox.TabIndex = 1;
this.inputTextBox.TabStop = false;
this.inputTextBox.DragDrop += new System.Windows.Forms.DragEventHandler( this.inputTextBox_DragDrop );
this.inputTextBox.DragEnter += new System.Windows.Forms.DragEventHandler( this.inputTextBox_DragEnter );
this.inputTextBox.TextChanged += new System.EventHandler( this.inputTextBox_TextChanged );
//
// fontDialog
//
this.fontDialog.Font = new System.Drawing.Font( "Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) );
this.fontDialog.FontMustExist = true;
this.fontDialog.ShowEffects = false;
//
// panel
//
this.panel.BackColor = System.Drawing.Color.Black;
this.panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel.Controls.Add( this.processingLabel );
this.panel.Controls.Add( this.pictureBox );
this.panel.ForeColor = System.Drawing.Color.Lime;
this.panel.Location = new System.Drawing.Point( -1, 411 );
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size( 200, 82 );
this.panel.TabIndex = 0;
this.panel.Visible = false;
//
// processingLabel
//
this.processingLabel.Location = new System.Drawing.Point( 8, 48 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -