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

📄 optionsform.cs

📁 自己写的多窗口文本编辑器
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.cbFontName.RightToLeftChanged += new System.EventHandler(this.OptionsForm_Load);
			// 
			// lbFont
			// 
			this.lbFont.Location = new System.Drawing.Point(16, 16);
			this.lbFont.Name = "lbFont";
			this.lbFont.TabIndex = 0;
			this.lbFont.Text = "字体名称(&F)";
			this.lbFont.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// btnOk
			// 
			this.btnOk.BackColor = System.Drawing.Color.LightSteelBlue;
			this.btnOk.DialogResult = System.Windows.Forms.DialogResult.Yes;
			this.btnOk.ForeColor = System.Drawing.Color.DarkGreen;
			this.btnOk.Location = new System.Drawing.Point(152, 208);
			this.btnOk.Name = "btnOk";
			this.btnOk.Size = new System.Drawing.Size(64, 24);
			this.btnOk.TabIndex = 0;
			this.btnOk.Text = "确定(&O)";
			// 
			// btnCancel
			// 
			this.btnCancel.BackColor = System.Drawing.Color.LightSteelBlue;
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.ForeColor = System.Drawing.Color.DarkGreen;
			this.btnCancel.Location = new System.Drawing.Point(240, 208);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(56, 24);
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "取消(&C)";
			// 
			// btnApp
			// 
			this.btnApp.BackColor = System.Drawing.Color.LightSteelBlue;
			this.btnApp.ForeColor = System.Drawing.Color.DarkGreen;
			this.btnApp.Location = new System.Drawing.Point(320, 208);
			this.btnApp.Name = "btnApp";
			this.btnApp.Size = new System.Drawing.Size(64, 24);
			this.btnApp.TabIndex = 2;
			this.btnApp.Text = "应用(&A)";
			// 
			// errorProvider
			// 
			this.errorProvider.ContainerControl = this;
			// 
			// OptionsForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.ForestGreen;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(424, 270);
			this.Controls.Add(this.tabControl1);
			this.ForeColor = System.Drawing.Color.Purple;
			this.Name = "OptionsForm";
			this.Text = "选项";
			this.Load += new System.EventHandler(this.OptionsForm_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

	
		private void cbFontName_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			FontStyle fs=FontStyle.Regular ;
			if(chkBold.Checked )
				fs|=FontStyle.Bold ;
			if(chkItalic.Checked)
				fs|=FontStyle.Italic;
			if(chkUnderline.Checked)
				fs|=FontStyle.Underline ;
			if(chkStrikeout.Checked )
				fs|=FontStyle.Strikeout;
			//fs^=FontStyle.Regular ;
		
			//float fSize;
			//GraphicsUnit fUnit;
			//ParseFontSize (out fSize,out fUnit);
			Font nFont;
			
			float fSize;
			GraphicsUnit fUnit;
			ParseFontSize(out fSize, out fUnit);

			try
			{
				nFont = new Font(cbFontName.Text,fSize,fs,fUnit);
			}
			catch
			{
				try
				{
					chkItalic.Checked = true;
					fs |= FontStyle.Italic;
					nFont = new Font(cbFontName.Text, fSize, fs, fUnit);
				}
				catch
				{
					chkItalic.Checked = false;
					chkBold.Checked = true;
					fs ^= FontStyle.Italic;
					fs |= FontStyle.Bold;
					nFont = new Font(cbFontName.Text, fSize, fs, fUnit);
				}
			}

			PreView.Font = nFont;
			if (cbForeColor.Text!=null && cbForeColor.Text!="")
				PreView.ForeColor = Color.FromKnownColor((KnownColor)System.Enum.Parse(typeof(System.Drawing.KnownColor),cbForeColor.Text,true));
		

			
			
			
		}
		private void OptionsForm_Load(object sender, System.EventArgs e)
		{
			System.Drawing .Text .InstalledFontCollection fc= new System.Drawing.Text.InstalledFontCollection ();
			foreach(FontFamily ff in fc.Families )
			 {
		        cbFontName.Items.Add(ff.Name);
				cbFontName.SelectedItem =this.Font.Name ;
			 }
			string[] cn= System.Enum.GetNames(typeof(System.Drawing .KnownColor));
			cbForeColor.Items .AddRange (cn);
			cbForeColor.SelectedItem ="Black";
			PreView.ForeColor =Color.FromKnownColor(KnownColor.Red );
		

		}

		private void cbForeColor_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(cbForeColor.SelectedIndex>=0)
			PreView.ForeColor =Color.FromKnownColor((KnownColor)System.Enum.Parse (typeof(KnownColor),cbForeColor.Text ,true));

		
		}

	
		private bool ParseFontSize()
		{
			float f;
			GraphicsUnit u;
			return ParseFontSize(out f, out u);
		}

		private void tabPage1_Click(object sender, System.EventArgs e)
		{
		
		}

		private void cbFontSize_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}

		private void cbFontSize_TextChanged(object sender, System.EventArgs e)
		{
			if(ParseFontSize())
			{
				cbFontName_SelectedIndexChanged(null,null);
				errorProvider.SetError(cbFontSize,"");
			}
			else
				errorProvider.SetError(cbFontSize,"格式: 数值 单位(pt,px,in,mm)");
		
		}


	
		private bool ParseFontSize(out float Size, out GraphicsUnit Unit)
		{
			string n = "";
			string u = "";
			int i=0;
			Size = 12;
			Unit = GraphicsUnit.Point;
			if (cbFontSize.Text.Trim()=="")
			{
				cbFontSize.Text = "12 pt";
				cbFontSize.SelectAll();
				return true;
			}
			for(; i<cbFontSize.Text.Length; i++)
			{
				if (cbFontSize.Text[i]=='.' || cbFontSize.Text[i]>='0' && cbFontSize.Text[i]<='9')
					n += cbFontSize.Text[i];
				else
					break;
			}
			if (n.Length<cbFontSize.Text.Length)
				u = cbFontSize.Text.Substring(n.Length).Trim().ToLower();
			bool err = false;
			try
			{
				Size = float.Parse(n);
				if (Size==0)
					Size = 9;
			}
			catch
			{
				err = true;
			}
			if (!err)
			{
				switch(u)
				{
					case "":
					case "p":
					case "m":
					case "i":
					case "px":
						Unit = GraphicsUnit.Pixel;
						break;
					case "pt":
						Unit = GraphicsUnit.Point;
						break;
					case "mm":
						Unit = GraphicsUnit.Millimeter;
						break;
					case "in":
						Unit = GraphicsUnit.Inch;
						break;
					default:
						err = true;
						break;
				}
			}
			return !err;
		}

	

		
	}


}

⌨️ 快捷键说明

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