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

📄 formj.cs

📁 这是用C#编的一个简单的电子日记本软件
💻 CS
📖 第 1 页 / 共 5 页
字号:
				int i = 0 ;
				foreach (TextInFile tf in Files)
				{
					formS.LBFlieName.Items.Add (Path.GetFileName (tf.FileName)) ;
					formS.LBFlieName.SelectedIndex = i ++ ;
				}
				switch (formS.ShowDialog (this))
				{
					case DialogResult.Yes : 
						for (i = 0 ; i < formS.LBFlieName.SelectedIndices.Count  ; i ++)
						{
							((TextInFile)Files[formS.LBFlieName.SelectedIndices[i]]).Save () ;
						}
						break ;
					case DialogResult.No :
						break ;
					case DialogResult.Cancel :
						e.Cancel = true ;
						break ;
				}
				formS.Dispose () ;
			}
			if (!e.Cancel)
			{
				// Serialize  TextEditPane
				this.SerializeTexePaneAtt () ;
			}
		}


		private void JChannel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Graphics dc = e.Graphics ; 
			dc.DrawImageUnscaled (this.ImgGongJu, 0,0) ;
		}
  
		private void JChannel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			// 如果按下鼠标在工具箱图片上 
			// 并且 工具箱窗口正隐藏
			// 则 计时器开始 滚动窗口
			if (e.Y < 80 && this.GenericPane.Location.X <= GenericPane.Size.Width - 20
				&& this.GenericPaneState != WndState.Docking)
			{
				this.GenericPaneState = WndState.Outing ;
				this.TrundleTimer.Enabled = true ;
			}
		}


		private void GenericPane_SizeChanged(object sender, System.EventArgs e)
		{
			if (this.GenericPaneState == WndState.Docking)
				this.DocTree.Size = new Size (GenericPane.Size.Width - 2, GenericPane.Size.Height -25) ;
			else 
				this.DocTree.Size = new Size (GenericPane.Size.Width - 4, GenericPane.Size.Height -25) ;
			this.GenericPane.Invalidate () ;
		}

		private void GenericPane_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Graphics dc = e.Graphics ;
			if (this.GenericPaneState != WndState.Docking)
			{
				dc.DrawLine (this.FramePen, GenericPane.Size.Width - 2, 0, 
					GenericPane.Size.Width - 2, GenericPane.Size.Height) ;
				dc.DrawLine (this.BlackPen, GenericPane.Size.Width - 1, 0, 
					GenericPane.Size.Width - 1, GenericPane.Size.Height) ;
				if (this.DocTree.Focused)
				{
					dc.FillRectangle (Brushes.Blue, 2, 2, this.GenericPane.Size.Width -6, 18) ;	
					dc.DrawImageUnscaled (this.ImgNailFocusOut, this.GenericPane.Size.Width -46, 2) ;
					// 标题
					dc.DrawString ("MY TEXT", this.TabFont, Brushes.White, 5, 5) ;
				}
				else 
				{	
					dc.DrawImageUnscaled (this.ImgNailUnFocusOut, this.GenericPane.Size.Width -46, 2) ;
					dc.DrawRectangle (this.FramePen, 2, 2, this.GenericPane.Size.Width -6, 18) ;
					// 标题
					dc.DrawString ("MY TEXT", this.TabFont, Brushes.Black, 5, 5) ;
				}
			}
			else  // Docking 
			{
				if (this.DocTree.Focused)
				{
					dc.FillRectangle (Brushes.Blue, 2, 2, this.GenericPane.Size.Width -3, 18) ;	
					dc.DrawImageUnscaled (this.ImgNailFocusIn, this.GenericPane.Size.Width -47, 2) ;
					// 标题
					dc.DrawString ("MY TEXT", this.TabFont, Brushes.White, 5, 5) ;
				}
				else 
				{	
					dc.DrawImageUnscaled (this.ImgNailUnFocusIn, this.GenericPane.Size.Width -47, 2) ;
					dc.DrawRectangle (this.FramePen, 2, 2, this.GenericPane.Size.Width -3, 18) ;
					// 标题
					dc.DrawString ("MY TEXT", this.TabFont, Brushes.Black, 5, 5) ;
				}
			}
	
			// 实现按钮阴影效果
			switch (this.GenericPaneMouseState)
			{
				case WndMouseState.MouseOnX :
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -10,5,
						this.GenericPane.Size.Width -22,5);
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -22,16,
						this.GenericPane.Size.Width -22,5);
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -9,5,
						this.GenericPane.Size.Width -9,18);
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -9,18,
						this.GenericPane.Size.Width -22,18);
					break ;
				case WndMouseState.MouseOnNail :
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -30,5,
						this.GenericPane.Size.Width -42,5);
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -42,16,
						this.GenericPane.Size.Width -42,5);
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -29,5,
						this.GenericPane.Size.Width -29,18);
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -29,18,
						this.GenericPane.Size.Width -42,18);
					break ;

				case WndMouseState.LButtonDownX :
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -10,5,
						this.GenericPane.Size.Width -22,5);
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -22,16,
						this.GenericPane.Size.Width -22,5);
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -9,5,
						this.GenericPane.Size.Width -9,18);
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -9,18,
						this.GenericPane.Size.Width -22,18);

					break ;
				case WndMouseState.LButtonDownNail :
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -30,5,
						this.GenericPane.Size.Width -42,5);
					dc.DrawLine (Pens.Black, this.GenericPane.Size.Width -42,16,
						this.GenericPane.Size.Width -42,5);
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -29,5,
						this.GenericPane.Size.Width -29,18);
					dc.DrawLine (Pens.White, this.GenericPane.Size.Width -29,18,
						this.GenericPane.Size.Width -42,18);
					break;

			}
			
		}

		private void GenericPane_Leave(object sender, System.EventArgs e)
		{
			if (this.GenericPaneState != WndState.Docking) 
			{
				this.GenericPaneState = WndState.Ining ;
				this.TrundleTimer.Enabled = true ;
			}
			this.GenericPane.Invalidate () ;
			this.GenericPane.Update () ;		
		}

		private void GenericPane_Enter(object sender, System.EventArgs e)
		{
			this.GenericPane.Invalidate () ;
			this.GenericPane.Update () ;
		}

		private void GenericPane_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (this.GenericPaneMouseState == WndMouseState.LButtonDownNail)
			{
				if (this.GenericPaneState != WndState.Docking) 
				{
					// set Controls's state
					this.GenericPaneState = WndState.Docking ;
					this.JChannel.Visible = false ;
					this.GenericPane.Dock = DockStyle.Left ;
					this.MdiContainer .Dock = DockStyle.Fill ;
				
					// Set controls's order in the set.
					this.Controls.Remove (this.GenericPane) ;
					this.Controls.Add (this.JWndSpliter) ;
					this.Controls.Add (this.GenericPane) ;
					this.DocTree.Size = new Size (GenericPane.Size.Width - 2, GenericPane.Size.Height -25) ;
					//
					this.GenericPane.Invalidate () ;
				}
				else // Docking
				{
					// Resume controls's state
					this.GenericPaneState = WndState.Ining ;
					this.MdiContainer .Dock = DockStyle.None ;
					this.GenericPane.Dock = DockStyle.None ;
					this.GenericPane.Location = new Point (20, 0) ;

					// Reset the controls's order
					// 很笨的方法 控制 控件 Z 方向上的次序(即哪个控件窗口在上哪个在下)
					this.Controls.Remove (this.JWndSpliter) ;
					this.Controls.Remove (this.MdiContainer) ;
					this.Controls.Add(this.MdiContainer);
					this.JChannel.Visible = true ;
					this.DocTree.Size = new Size (GenericPane.Size.Width - 4, GenericPane.Size.Height -25) ;
					this.MdiContainer.Size = new Size (this.ClientSize.Width - 20, this.ClientSize.Height) ; 
					this.GenericPane.Size = new Size (GenericPane.Size.Width, this.ClientSize.Height) ;

					// Prepare scroll.
					this.TextEditPane.Focus () ;
					this.GenericPane.Invalidate () ;
					this.TrundleTimer.Enabled = true ;
				}
				this.GenericPaneMouseState = 0 ;
			}
		}

		private void GenericPane_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left)
			{ 
				if (this.GenericPaneMouseState == WndMouseState.MouseOnX) 
				{
					this.GenericPaneMouseState = WndMouseState.LButtonDownX ;
				}
				else if (this.GenericPaneMouseState == WndMouseState.MouseOnNail) 
				{
					this.GenericPaneMouseState = WndMouseState.LButtonDownNail;
				}
				this.GenericPane.Invalidate () ;
				this.Update () ;
			}
			this.DocTree.Focus () ;
		}

		private void GenericPane_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			// 状态机
			if (e.Button == MouseButtons.Left)
			{
				switch (MouseIsOnNailOrX (e.X, e.Y))
				{
					case WndMouseState.None :
						if (this.GenericPaneMouseState != WndMouseState.None)
						{
							this.GenericPaneMouseState = WndMouseState.None ;
							this.GenericPane.Invalidate () ;
						}
						break ;
					case WndMouseState.MouseOnNail :
						if (this.GenericPaneMouseState != WndMouseState.LButtonDownNail)
						{
							this.GenericPaneMouseState = WndMouseState.LButtonDownNail ;
							this.GenericPane.Invalidate () ;
						}
						break ;
					case WndMouseState.MouseOnX :
						if (this.GenericPaneMouseState != WndMouseState.LButtonDownX)
						{
							this.GenericPaneMouseState = WndMouseState.LButtonDownX ;
							this.GenericPane.Invalidate () ;
						}
						break ;
				}
			}
			else if (e.Button == MouseButtons.None)
			{
				switch (MouseIsOnNailOrX (e.X, e.Y))
				{
					case WndMouseState.None :
						if (this.GenericPaneMouseState != WndMouseState.None)
						{
							this.GenericPaneMouseState = WndMouseState.None ;
							this.GenericPane.Invalidate () ;
						}
						break ;
					case WndMouseState.MouseOnNail :
						if (this.GenericPaneMouseState != WndMouseState.MouseOnNail)
						{
							this.GenericPaneMouseState = WndMouseState.MouseOnNail ;
							this.GenericPane.Invalidate () ;
						}
						break ;
					case WndMouseState.MouseOnX :
						if (this.GenericPaneMouseState != WndMouseState.MouseOnX)
						{
							this.GenericPaneMouseState = WndMouseState.MouseOnX ;
							this.GenericPane.Invalidate () ;
						}
						break ;
				}
			}
		}


		private void MdiDocManager_FirstTimeOpenFileMsg (object sender, EventArgs e)
		{
			this.MdiContainer.Visible = true ;
		}

		private void MdiDocManager_AllClosedMsg(object sender, EventArgs e)
		{
			this.MdiContainer.Visible = false ;
			this.Invalidate () ;
		}


		private void MdiContainer_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
			Graphics dc = e.Graphics ;
			// Drow Frame
			dc.DrawRectangle (this.FramePen, 1, 0, 
				this.MdiContainer.Size.Width -2, 
				this.MdiContainer.Size.Height -1) ;
			dc.DrawRectangle (this.FramePen, 3, 25,
				this.MdiContainer.Size.Width -6, 
				this.MdiContainer.Size.Height -28) ;
			dc.FillRectangle (new SolidBrush (this.TextEditPane.BackColor), 4, 26,
				this.MdiContainer.Size.Width -8, 
				this.MdiContainer.Size.Height -30) ;
			// Show pic "X"
			dc.DrawImageUnscaled (this.ImgX, this.MdiContainer.Size.Width -76, 2) ;

			// Drow butten effect
			switch (this.MdiContainerMouseState)
			{
				case WndMouseState.MouseOnLeftBtn :
					if ((this.GetTabsState() & TabsState.OutRight) == 0) break ;
					dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -46,5,
						this.MdiContainer.Size.Width -34,5);
					dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -46,16,
						this.MdiContainer.Size.Width -46,5);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -34,5,
						this.MdiContainer.Size.Width -34,18);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -34,18,
						this.MdiContainer.Size.Width -46,18);
					break ;
				case WndMouseState.MouseOnRightBtn :
					if ((GetTabsState() & TabsState.OutLeft) == 0) break ;
					dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -32,5,
						this.MdiContainer.Size.Width -20,5);
					dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -32,16,
						this.MdiContainer.Size.Width -32,5);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -20,5,
						this.MdiContainer.Size.Width -20,18);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -20,18,
						this.MdiContainer.Size.Width -32,18);
					break ;
				case WndMouseState.MouseOnX :
					dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -18,5,
						this.MdiContainer.Size.Width -5,5);
					dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -18,16,
						this.MdiContainer.Size.Width -18,5);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -5,5,
						this.MdiContainer.Size.Width -5,18);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -5,18,
						this.MdiContainer.Size.Width -18,18);
					break ;
				case WndMouseState.LButtonDownLeftBtn :
					if ((GetTabsState() & TabsState.OutRight) == 0) break ;
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -46,5,
						this.MdiContainer.Size.Width -34,5);
					dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -46,16,
						this.MdiContainer.Size.Width -46,5);

⌨️ 快捷键说明

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