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

📄 labeledcombobox.cs

📁 代码模版 codtemplate
💻 CS
字号:
using System;
using System.Text;
using System.Windows.Forms;

namespace CodeTemplate
{
	/// <summary>
	/// Summary description for LabeledComboBox.
	/// </summary>
	internal class LabeledComboBox : LabeledControlBase
	{
		public LabeledComboBox(TagControlType controlType, String valuesString):
			base(new ComboBox())
		{
			ComboBox cb = (ComboBox)this.Control;

			Int32 len = valuesString.Length;
			Int32 startPos = 0, endPos = 0;
			String val = null;

			while(startPos < len)
			{
				startPos = SkipWhitespaces(valuesString, startPos);
				endPos = startPos;

				if(valuesString[endPos] == '\"')	// Quoted String
				{ 
					startPos = ++endPos;
					while(endPos < len && valuesString[endPos] != '\"')
						++endPos;

					val = valuesString.Substring(startPos, endPos - startPos);			
					endPos = SkipWhitespaces(valuesString, endPos + 1);
				}

				else	// Unquoted String
				{
					while(endPos < len && valuesString[endPos] != ',')
						++endPos;

					val = valuesString.Substring(startPos, endPos - startPos);
				}

				cb.Items.Add(val);
				startPos = endPos + 1;
			}

			cb.DropDownStyle = (controlType == TagControlType.DropDownControl) ? ComboBoxStyle.DropDown : ComboBoxStyle.DropDownList;
			cb.SelectedIndexChanged += new System.EventHandler(m_control_SelectedIndexChanged);
		}

		private Int32 SkipWhitespaces(String s, Int32 pos)
		{
			while(pos < s.Length && Char.IsWhiteSpace(s, pos))
				++pos;

			return pos;
		}

		private void m_control_SelectedIndexChanged(Object sender, EventArgs e)
		{
			OnTagChanged(new TagChangedEventArgs(this.TagName, ((Control)sender).Text));
		}

		public override event TagChangedEventHandler TagChanged 
		{
			add 
			{ 
				base.TagChanged += value; 

				// Now that we have sombody responding to a TagChanged event, let's select the
				// default item.
				ComboBox cb = (ComboBox) this.Control;
				cb.SelectedIndex = 0;
			}

			remove { base.TagChanged -= value; }
		}
	}
}

⌨️ 快捷键说明

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