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

📄 texteditorpanel.cs

📁 C#实现DHTML编辑器功能!
💻 CS
字号:
// DINAMIC XML Editor
//
// Copyright (c) 2002-2003 Dusan Hlavaty
// mailto: duddo@atlas.cz
//
// This software is licensed under the terms of
// GNU General Public license
//
using System;
using System.Windows.Forms;
using System.Drawing;

using Crownwood.Magic.Docking;
 
using XML_editor.MyForms;
using XML_editor.Common;

namespace XML_editor.DockingPanels
{
	/// <summary>
	/// Dokovaci panel obsahujuci vlastnosti aktualneho editora a
	/// dovoluje ich menit 'za pochodu'.
	/// </summary>
	public class TextEditorPanel : Crownwood.Magic.Docking.Content
	{

//		TODO: ReadOnly

		/// <summary>
		/// odkaz na hlavny formular aplikacie
		/// </summary>
		private MainForm mainForm = null;

		private XML_editor.MyComponents.AxGroupBox groupBox = new XML_editor.MyComponents.AxGroupBox(280);
		private System.Windows.Forms.CheckBox checkBox_EOL = new System.Windows.Forms.CheckBox();
		private System.Windows.Forms.CheckBox checkBox_spaces = new System.Windows.Forms.CheckBox();
		private System.Windows.Forms.CheckBox checkBox_tabs = new System.Windows.Forms.CheckBox();
		private System.Windows.Forms.CheckBox checkBox_invalidLines = new System.Windows.Forms.CheckBox();
		private System.Windows.Forms.CheckBox checkBox_rightMargin = new System.Windows.Forms.CheckBox();
		private System.Windows.Forms.CheckBox checkBox_lineNumbers = new System.Windows.Forms.CheckBox();
		private System.Windows.Forms.NumericUpDown upDownRightMargin = new System.Windows.Forms.NumericUpDown();


		/// <summary>
		/// true = ze sa nebudu 'vyhadzovat' eventy pre stlacenie checkboxov, tlacitiel, ...
		/// </summary>
		private bool doNotFireEvents = false;

		// -------------------------------------------------------------------------
		/// <summary>
		/// odkaz na hlavny formular aplikacie
		/// </summary>
		public MainForm MainForm
		{
			get 
			{
				return this.mainForm;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Inicializuje dokovaci panel obsahujuci vlastnosti aktualneho editora.
		/// </summary>
		/// <param name="mainForm">odkaz na hlavny formular aplikacie - <see cref="MainForm"/></param>
		/// <param name="manager">odkaz na <see cref="DockingManager"/>, ku ktoremu bude tento panel patrit</param>
		public TextEditorPanel(MainForm mainForm, DockingManager manager)
			                    : base(manager)
		{
			this.mainForm = mainForm;
			this.FullTitle = this.Title = "Text Editor";
 			
			System.Windows.Forms.ImageList i = new System.Windows.Forms.ImageList();
			i.Images.Add( IconProvider.LoadBitmap(this, "XML_editor.Icons.Properties.png") );
			this.ImageList = i;
			this.ImageIndex = 0;

			System.Windows.Forms.Label label1 = new System.Windows.Forms.Label();
			System.Windows.Forms.Label label2 = new System.Windows.Forms.Label();
			System.Windows.Forms.Label label3 = new System.Windows.Forms.Label();

			// 
			// groupBox
			// 
			this.groupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
																																					  label1,
																																						this.checkBox_tabs,
																																						this.checkBox_spaces,
																																						this.checkBox_EOL,
																																						this.checkBox_invalidLines,
																																						label2, checkBox_lineNumbers, checkBox_rightMargin, this.upDownRightMargin, label3});
			this.groupBox.Name = "groupBox";
			this.groupBox.Size = new System.Drawing.Size(208, 256);
			this.groupBox.TabIndex = 1;
			this.groupBox.TabStop = false;

			// 
			// label1
			// 
			label1.AutoSize = true;
			label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(238)));
			label1.Location = new System.Drawing.Point(8, 16);
			label1.Name = "label1";
			label1.Size = new System.Drawing.Size(43, 13);
			label1.TabIndex = 3;
			label1.Text = "Special chars";

			// 
			// checkBox_EOL
			// 
			this.checkBox_EOL.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.checkBox_EOL.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox_EOL.Location = new System.Drawing.Point(16, 32);
			this.checkBox_EOL.Name = "checkBox_EOL";
			this.checkBox_EOL.Size = new System.Drawing.Size(176, 32);
			this.checkBox_EOL.TabIndex = 0;
			this.checkBox_EOL.Text = "Show End Of Line";
			this.checkBox_EOL.CheckedChanged += new System.EventHandler(this.checkBox_EOL_CheckedChanged);
			// 
			// checkBox_spaces
			// 
			this.checkBox_spaces.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.checkBox_spaces.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox_spaces.Location = new System.Drawing.Point(16, 64);
			this.checkBox_spaces.Name = "checkBox_spaces";
			this.checkBox_spaces.Size = new System.Drawing.Size(176, 32);
			this.checkBox_spaces.TabIndex = 1;
			this.checkBox_spaces.Text = "Show Spaces";
			this.checkBox_spaces.CheckedChanged += new System.EventHandler(this.checkBox_spaces_CheckedChanged);
			// 
			// checkBox_tabs
			// 
			this.checkBox_tabs.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.checkBox_tabs.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox_tabs.Location = new System.Drawing.Point(16, 96);
			this.checkBox_tabs.Name = "checkBox_tabs";
			this.checkBox_tabs.Size = new System.Drawing.Size(176, 32);
			this.checkBox_tabs.TabIndex = 2;
			this.checkBox_tabs.Text = "Show Tabs";
			this.checkBox_tabs.CheckedChanged += new System.EventHandler(this.checkBox_tabs_CheckedChanged);

			// 
			// checkBox_invalidLines
			// 
			this.checkBox_invalidLines.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.checkBox_invalidLines.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox_invalidLines.Location = new System.Drawing.Point(16, 128);
			this.checkBox_invalidLines.Name = "checkBox_invalidLines";
			this.checkBox_invalidLines.Size = new System.Drawing.Size(176, 32);
			this.checkBox_invalidLines.TabIndex = 3;
			this.checkBox_invalidLines.Text = "Show Invalid Lines";
			this.checkBox_invalidLines.CheckedChanged += new System.EventHandler(this.checkBox_invalidLines_CheckedChanged);

			// 
			// label2
			// 
			label2.AutoSize = true;
			label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(238)));
			label2.Location = new System.Drawing.Point(8, 160);
			label2.Name = "label2";
			label2.Size = new System.Drawing.Size(43, 13);
			label2.TabIndex = 3;
			label2.Text = "Apearance";

			// 
			// checkBox_lineNumbers
			// 
			this.checkBox_lineNumbers.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.checkBox_lineNumbers.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox_lineNumbers.Location = new System.Drawing.Point(16, 172);
			this.checkBox_lineNumbers.Name = "checkBox_rightMargin";
			this.checkBox_lineNumbers.Size = new System.Drawing.Size(176, 32);
			this.checkBox_lineNumbers.TabIndex = 3;
			this.checkBox_lineNumbers.Text = "Show Line Numbers";
			this.checkBox_lineNumbers.CheckedChanged += new System.EventHandler(this.checkBox_lineNumbers_CheckedChanged);

			// 
			// checkBox_rightMargin
			// 
			this.checkBox_rightMargin.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.checkBox_rightMargin.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.checkBox_rightMargin.Location = new System.Drawing.Point(16, 204);
			this.checkBox_rightMargin.Name = "checkBox_rightMargin";
			this.checkBox_rightMargin.Size = new System.Drawing.Size(176, 32);
			this.checkBox_rightMargin.TabIndex = 3;
			this.checkBox_rightMargin.Text = "Show Right Margin";
			this.checkBox_rightMargin.CheckedChanged += new System.EventHandler(this.checkBox_rightMargin_CheckedChanged);

			// 
			// label3
			// 
			label3.AutoSize = true;
			label3.Location = new System.Drawing.Point(30, 242);
			label3.Text = "Margin:";

			// 
			// upDownRightMargin
			// 
			this.upDownRightMargin.Location = new System.Drawing.Point(72, 238);
			this.upDownRightMargin.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.upDownRightMargin.Maximum = 200;
			this.upDownRightMargin.Minimum = 1;
			this.upDownRightMargin.Size = new System.Drawing.Size(50, 20);
			this.upDownRightMargin.Value = 80;
			this.upDownRightMargin.ValueChanged += new System.EventHandler(this.upDownRightMargin_ValueChanged);

			this.Control = this.groupBox;
		
			this.ActualTextAreaControlChanged(null, null);

			this.MainForm.ActualTextAreaControlChanged += new System.EventHandler(this.ActualTextAreaControlChanged);

		}
	
		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa, PO zmene aktualneho <see cref="MainForm.ActualTextAreaControl"/>
		/// - teda ked uzivatel prepne na inu zalozku.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ActualTextAreaControlChanged(object sender, System.EventArgs e)
		{
			if (this.MainForm.ActualTextAreaControl == null) 
			{
				this.groupBox.Enabled = false;
			} 
			else 
			{
				this.doNotFireEvents = true;
				this.checkBox_EOL.Checked = this.MainForm.ActualTextAreaControl.ShowEOLMarkers;
				this.checkBox_invalidLines.Checked = this.MainForm.ActualTextAreaControl.ShowInvalidLines;
				this.checkBox_spaces.Checked = this.MainForm.ActualTextAreaControl.ShowSpaces;
				this.checkBox_tabs.Checked = this.MainForm.ActualTextAreaControl.ShowTabs;
				this.checkBox_rightMargin.Checked = this.MainForm.ActualTextAreaControl.ShowRightMargin;
				this.checkBox_lineNumbers.Checked = this.MainForm.ActualTextAreaControl.ShowLineNumbers;
				this.upDownRightMargin.Enabled = this.checkBox_rightMargin.Checked;
				this.upDownRightMargin.Value = (decimal)this.MainForm.ActualTextAreaControl.RightMarginRow;
				this.groupBox.Enabled = true;
				this.doNotFireEvents = false;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene zaskrtnutia 'checkBox_EOL'
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void checkBox_EOL_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}
			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.ShowEOLMarkers = this.checkBox_EOL.Checked;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene zaskrtnutia 'checkBox_spaces'
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void checkBox_spaces_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}
			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.ShowSpaces = this.checkBox_spaces.Checked;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene zaskrtnutia 'checkBox_tabs'
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void checkBox_tabs_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}
			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.ShowTabs = this.checkBox_tabs.Checked;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene zaskrtnutia 'checkBox_invalidLines'
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void checkBox_invalidLines_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}
			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.ShowInvalidLines = this.checkBox_invalidLines.Checked;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene zaskrtnutia 'checkBox_rightMargin'
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void checkBox_rightMargin_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}
			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.ShowRightMargin = this.checkBox_rightMargin.Checked;
				this.upDownRightMargin.Enabled = this.checkBox_rightMargin.Checked;
			}
		}
		
		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene zaskrtnutia 'checkBox_lineNumbers'
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void checkBox_lineNumbers_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}
			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.ShowLineNumbers = this.checkBox_lineNumbers.Checked;
			}
		}

		// -------------------------------------------------------------------------
		/// <summary>
		/// Vyvola sa po zmene praveho okraja
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void upDownRightMargin_ValueChanged(object sender, System.EventArgs e)
		{
			if (this.doNotFireEvents == true) 
			{
				return;
			}

			if (this.MainForm.ActualTextAreaControl != null) 
			{
				this.MainForm.ActualTextAreaControl.RightMarginRow = (int)this.upDownRightMargin.Value;
			}		
		}


	} // public class TextEditorPanel : ...
} // namespace XML_editor.DockingPanels

⌨️ 快捷键说明

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