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

📄 selection.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
//  Selection.cs
//  Copyright (C) 2001 Mike Krueger
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Drawing;

namespace SharpDevelop.Gui.Edit.Text {
	
	/// <summary>
	/// This class handles the selection of a textbuffer.
	/// </summary>
	public class Selection
	{
		Point  selectionstart = new Point(0, 0);
		Point  selectionend   = new Point(0, 0);
		
		public event EventHandler SelectionChanged;
		
		public Point SelectionStart {
			get {
				return selectionstart;
			}
			set {
				selectionstart = value;
//				OnSelectionChanged();
			}
		}
		
		public Point SelectionEnd {
			get {
				return selectionend;
			}
			set {
				selectionend = value;
				OnSelectionChanged();
			}
		}
		
		public Point RealStart {
			get {
				if (selectionstart.Y < selectionend.Y || (selectionstart.Y == selectionend.Y && selectionstart.X < selectionend.X)) 
					return selectionstart;
				return selectionend;
			}
		}
		
		public Point RealEnd {
			get {
				if (selectionstart.Y < selectionend.Y || (selectionstart.Y == selectionend.Y && selectionstart.X < selectionend.X)) 
					return selectionend;
				return selectionstart;
			}
		}
		
		void OnSelectionChanged()
		{
			if (SelectionChanged != null)
				SelectionChanged(this, null);
		}
		
		public bool HasSomethingSelected {
			get {
				return selectionstart != selectionend;
			}
			set {
				if (!value) {
					selectionstart = selectionend = new Point(0, 0);
					OnSelectionChanged();
				}
			}
		}
		
		public Selection()
		{
		}
		
		public void SetSelectionEnd(Point oldPos, Point pos)
		{
			if (!HasSomethingSelected)
				SelectionStart = oldPos;
			
			SelectionEnd = pos;
		}
		
		public void SetNoSelection()
		{
			if (HasSomethingSelected)
				SelectionEnd = SelectionStart;
		}
	}
	
}

⌨️ 快捷键说明

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