⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 A group of programs which describes the use of different encoding systems
💻 CS
📖 第 1 页 / 共 3 页
字号:
			this.processingLabel.Name = "processingLabel";
			this.processingLabel.Size = new System.Drawing.Size( 184, 23 );
			this.processingLabel.TabIndex = 0;
			this.processingLabel.Text = "Processing please wait...";
			// 
			// pictureBox
			// 
			this.pictureBox.BackColor = System.Drawing.Color.Black;
			this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox.Image = ( ( System.Drawing.Image )( resources.GetObject( "pictureBox.Image" ) ) );
			this.pictureBox.Location = new System.Drawing.Point( 80, 8 );
			this.pictureBox.Name = "pictureBox";
			this.pictureBox.Size = new System.Drawing.Size( 32, 34 );
			this.pictureBox.TabIndex = 0;
			this.pictureBox.TabStop = false;
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size( 8, 19 );
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ClientSize = new System.Drawing.Size( 632, 404 );
			this.Controls.Add( this.panel );
			this.Controls.Add( this.inputTextBox );
			this.Font = new System.Drawing.Font( "Georgia", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte )( 0 ) ) );
			this.Icon = ( ( System.Drawing.Icon )( resources.GetObject( "$this.Icon" ) ) );
			this.Menu = this.mainMenu;
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.FormClosing += new System.Windows.Forms.FormClosingEventHandler( this.mainForm_FormClosing );
			this.Load += new System.EventHandler( this.mainForm_Load );
			this.panel.ResumeLayout( false );
			( ( System.ComponentModel.ISupportInitialize )( this.pictureBox ) ).EndInit();
			this.ResumeLayout( false );
			this.PerformLayout();

		}
		
		[STAThread]
		public static void Main( string[] args )
		{
			Application.EnableVisualStyles();
			if( args.Length > 0 )
			{ Application.Run( new MainForm( args[ 0 ] ) ); }
			else
			{ Application.Run( new MainForm() ); }
		}
		
		private void FinishedProcess()
		{
			panel.Visible = false;
			fileMenuItem.Enabled = true;
			editMenuItem.Enabled = true;
			formatMenuItem.Enabled = true;
			encryptionMenuItem.Enabled = true;
			helpMenuItem.Enabled = true;
			Application.DoEvents();
		}

		public static void SetBitStrength( int bitStrength )
		{ currentBitStrength = bitStrength; }

		private void UpdateText( string inputText )
		{ inputTextBox.Text = inputText; }
		
		private string GetFileName( string fileName )
		{
			string[] fileParts = fileName.Split( "\\".ToCharArray() );
			return fileParts[ fileParts.Length - 1 ];
		}

		private void SetText( string text )
		{
			this.inputTextBox.TextChanged -= new System.EventHandler( this.inputTextBox_TextChanged );
			inputTextBox.Text = text;
			this.inputTextBox.TextChanged += new System.EventHandler( this.inputTextBox_TextChanged );
		}

		private Settings GetSettings()
		{
			Settings settings = null;
			if( File.Exists( "Settings.bin" ) )
			{
				StreamReader streamReader = new StreamReader( "Settings.bin" );
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				settings = (Settings) binaryFormatter.Deserialize( streamReader.BaseStream );
				streamReader.Close();
			}
			return settings;
		}
		
		private void SaveSettings( string settingChanged )
		{
			Settings settings = new Settings();
			if( File.Exists( "Settings.bin" ) )
			{
				StreamReader streamReader = new StreamReader( "Settings.bin" );
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				settings = (Settings) binaryFormatter.Deserialize( streamReader.BaseStream );
				streamReader.Close();
				switch( settingChanged )
				{
					case "LOCATION":
					{
						settings.Location = this.Location;
						break;
					}
					case "SIZE":
					{
						settings.Width = this.Width;
						settings.Height = this .Height;
						break;
					}
					case "FONT":
					{
						settings.Font = inputTextBox.Font;
						break;
					}
					case "WRAPPING":
					{
						settings.Wrapping = inputTextBox.WordWrap;
						break;
					}
				}
				StreamWriter streamWriter = new StreamWriter( "Settings.bin", false );
				binaryFormatter.Serialize( streamWriter.BaseStream, settings );
				streamWriter.Close();
			}
			else
			{
				settings.Location = this.Location;
				settings.Width = this.Width;
				settings.Height = this .Height;
				settings.Font = inputTextBox.Font;
				settings.Wrapping = inputTextBox.WordWrap;
				StreamWriter streamWriter = new StreamWriter( "Settings.bin", false );
				BinaryFormatter binaryFormatter = new BinaryFormatter();
				binaryFormatter.Serialize( streamWriter.BaseStream, settings );
				streamWriter.Close();
			}
		}

		private string openFile( string title, string filterString )
		{
			openFileDialog.FileName = "";
			openFileDialog.Title = title;
			openFileDialog.Filter = filterString;
			if( openFileDialog.ShowDialog() == DialogResult.OK )
			{
				if( File.Exists( openFileDialog.FileName ) )
				{
					StreamReader streamReader = new StreamReader( openFileDialog.FileName, true );
					string fileString = streamReader.ReadToEnd();
					streamReader.Close();
					if( fileString.Length >= inputTextBox.MaxLength )
					{
						MessageBox.Show( "ERROR: \nThe file you are trying to open is too big for the text editor to display properly.\nPlease open a smaller document!\nOperation Aborted!" );
						return null;
					}
					if( fileString != null )
					{
						this.Text = GetFileName( openFileDialog.FileName ) + " - RSACryptoPad";
						currentFileName = openFileDialog.FileName;
					}
					return fileString;
				}
			}
			return null;
		}

		private bool saveFile()
		{
			saveFileDialog.Title = "Save As";
			saveFileDialog.FileName = "*.txt";
			saveFileDialog.Filter = "Text Document( *.txt )|*.txt|All Files|*.*";
			if( saveFileDialog.ShowDialog() == DialogResult.OK )
			{
				try
				{
					StreamWriter streamWriter = new StreamWriter( saveFileDialog.FileName, false );
					streamWriter.Write( inputTextBox.Text );
					streamWriter.Close();
					this.Text = GetFileName( saveFileDialog.FileName ) + " - RSACryptoPad";
					currentFileName = saveFileDialog.FileName;
					return true;
				}
				catch( Exception Ex )
				{
					Console.WriteLine( Ex.Message );
					return false;
				}
			}
			return false;
		}

		private bool saveFile( string title, string filterString, string outputString )
		{
			saveFileDialog.Title = title;
			saveFileDialog.Filter = filterString;
			saveFileDialog.FileName = "";
			if( saveFileDialog.ShowDialog() == DialogResult.OK )
			{
				try
				{
					StreamWriter streamWriter = new StreamWriter( saveFileDialog.FileName, false );
					if( outputString != null )
					{ streamWriter.Write( outputString ); }
					streamWriter.Close();
					return true;
				}
				catch( Exception Ex )
				{
					Console.WriteLine( Ex.Message );
					return false;
				}
			}
			return false;
		}
		
		private void mainForm_Load( object sender, EventArgs e )
		{
			if( File.Exists( "Settings.bin" ) )
			{
				Settings settings = GetSettings();
				this.Location = settings.Location;
				this.Width = settings.Width;
				this.Height = settings.Height;
				inputTextBox.Font = settings.Font;
				inputTextBox.WordWrap = settings.Wrapping;
				wordWrapMenuItem.Checked = ( settings.Wrapping == true ) ? true : false;
			}
			this.Text = GetFileName( currentFileName ) + " - RSACryptoPad";
			inputTextBox.Focus();
			this.Resize += new System.EventHandler( this.mainForm_Resize );
			this.Move += new System.EventHandler( this.MainForm_Move );
			inputTextBox.Height = this.Size.Height - 53;
			inputTextBox.Width = this.Size.Width - 7;
		}

		private void mainForm_Resize( object sender, EventArgs e )
		{
			inputTextBox.Height = this.Size.Height - 53;
			inputTextBox.Width = this.Size.Width - 7;
			SaveSettings( "SIZE" );
		}

		private void MainForm_Move( object sender, EventArgs e )
		{ SaveSettings( "LOCATION" ); }

		private void mainForm_FormClosing( object sender, FormClosingEventArgs e )
		{
			this.Resize -= new EventHandler( this.mainForm_Resize );
			this.Move -= new EventHandler( this.MainForm_Move );
			if( !cleanForm )
			{
				string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine + Environment.NewLine + "Do you want to save the changes?";
				switch( MessageBox.Show( dialogText, "RSACryptoPad", MessageBoxButtons.YesNoCancel ) )
				{
					case DialogResult.Yes:
						{
							if( !saveFile() ) { e.Cancel = true; }
							break;
						}
					case DialogResult.Cancel:
						{
							e.Cancel = true;
							break;
						}
				}
			}
		}

		private void inputTextBox_TextChanged( object sender, EventArgs e )
		{
			if( currentFileName.Equals( "Untitled" ) )
			{ cleanForm = ( !inputTextBox.Text.Equals( "" ) ) ? false : true; }
			else
			{ cleanForm = false; }			
		}
		
		private void inputTextBox_DragEnter( object sender, DragEventArgs e )
		{ e.Effect = DragDropEffects.All; }
		
		private void inputTextBox_DragDrop( object sender, DragEventArgs e )
		{
			bool clean = false;
			if( !cleanForm )
			{
				string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine + Environment.NewLine + "Do you want to save the changes?";
				switch( MessageBox.Show( dialogText, "RSACryptoPad", MessageBoxButtons.YesNoCancel ) )
				{
					case DialogResult.Yes:
						{
							if( saveFile() ) { clean = true; }
							break;
						}
					case DialogResult.No:
						{
							clean = true;
							break;
						}
				}
			}
			else
			{ clean = true; }
			if( clean )
			{
				if( e.Data.GetDataPresent( DataFormats.FileDrop, true ) == true )
				{
					string[] fileNames = ( string[] )e.Data.GetData( DataFormats.FileDrop, true );
					StreamReader streamReader = new StreamReader( fileNames[ 0 ], true );
					string fileContents = streamReader.ReadToEnd();
					streamReader.Close();
					currentFileName = fileNames[ 0 ];
					this.Text = GetFileName( fileNames[ 0 ] ) + " - RSACryptoPad";
					SetText( fileContents );
					cleanForm = true;
				}
			}
		}
		
		private void newFileMenuItem_Click( object sender, EventArgs e )
		{
			if( !cleanForm )
			{
				string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine + Environment.NewLine + "Do you want to save the changes?";
				switch( MessageBox.Show( dialogText, "RSACryptoPad", MessageBoxButtons.YesNoCancel ) )
				{
					case DialogResult.Yes:
						{
							if( saveFile() )
							{
								SetText( "" );
								currentFileName = "Untitled";
								this.Text = "Untitled - RSACryptoPad";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -