📄 formj.cs
字号:
dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -34,5,
this.MdiContainer.Size.Width -34,18);
dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -34,18,
this.MdiContainer.Size.Width -46,18);
break ;
case WndMouseState.LButtonDownRightBtn :
if ((GetTabsState() & TabsState.OutLeft) == 0) break ;
dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -32,5,
this.MdiContainer.Size.Width -20,5);
dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -32,16,
this.MdiContainer.Size.Width -32,5);
dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -20,5,
this.MdiContainer.Size.Width -20,18);
dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -20,18,
this.MdiContainer.Size.Width -32,18);
break ;
case WndMouseState.LButtonDownX :
dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -18,5,
this.MdiContainer.Size.Width -5,5);
dc.DrawLine (Pens.Black, this.MdiContainer.Size.Width -18,16,
this.MdiContainer.Size.Width -18,5);
dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -5,5,
this.MdiContainer.Size.Width -5,18);
dc.DrawLine (Pens.White, this.MdiContainer.Size.Width -5,18,
this.MdiContainer.Size.Width -18,18);
break ;
}
// 画图当 "<" ">" 按钮生效时 的效果
// Point
Point[] pointLs =
{
new Point (MdiContainer.Size.Width -42, 12) ,
new Point (MdiContainer.Size.Width -37, 7) ,
new Point (MdiContainer.Size.Width -37, 16) ,
} ;
Point[] pointRs =
{
new Point (MdiContainer.Size.Width -23, 12) ,
new Point (MdiContainer.Size.Width -28, 7) ,
new Point (MdiContainer.Size.Width -28, 16) ,
} ;
// 画实心 ">"
if ((GetTabsState() & TabsState.OutRight) !=0)
dc.FillPolygon (this.TabBrush, pointLs) ;
// 画实心 "<"
if ((GetTabsState() & TabsState.OutLeft) !=0)
dc.FillPolygon (this.TabBrush, pointRs) ;
}
private void MdiContainer_SizeChanged(object sender, System.EventArgs e)
{
this.TextEditPane.Size = new Size (this.MdiContainer.Size.Width -22,
this.MdiContainer.Size.Height -30) ;
this.MdiTabOwner.Size = new Size (this.MdiContainer.Size.Width -76,22) ;
this.MdiContainer.Invalidate () ;
}
private void MdiContainer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// 状态机模型 实现按钮效果
if (e.Button == MouseButtons.Left)
{
if (this.MdiContainerMouseState == WndMouseState.MouseOnX)
{
this.MdiContainerMouseState = WndMouseState.LButtonDownX ;
}
else if (this.MdiContainerMouseState == WndMouseState.MouseOnLeftBtn)
{
this.MdiContainerMouseState = WndMouseState.LButtonDownLeftBtn ;
if ((GetTabsState() & TabsState.OutRight) != 0)
{
this.ehTimeTab_Tick = this.ehTimeTab_Tick_L ;
this.TimeTab.Tick += this.ehTimeTab_Tick ;
this.TimeTab.Enabled = true ;
}
}
else if (this.MdiContainerMouseState == WndMouseState.MouseOnRightBtn)
{
this.MdiContainerMouseState = WndMouseState.LButtonDownRightBtn ;
if ((GetTabsState() & TabsState.OutLeft) != 0)
{
this.ehTimeTab_Tick = this.ehTimeTab_Tick_R ;
this.TimeTab.Tick += this.ehTimeTab_Tick ;
this.TimeTab.Enabled = true ;
}
}
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
this.Update () ;
}
}
private void MdiContainer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// 一个状态机模型 实现按钮效果
if (e.Button == MouseButtons.Left)
{
switch (MouseIsOnLeftOrRightOrX (e.X, e.Y))
{
case WndMouseState.None :
if (this.MdiContainerMouseState != WndMouseState.None)
{
this.MdiContainerMouseState = WndMouseState.None ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
case WndMouseState.MouseOnLeftBtn :
if (this.MdiContainerMouseState != WndMouseState.LButtonDownLeftBtn)
{
this.MdiContainerMouseState = WndMouseState.LButtonDownLeftBtn ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
case WndMouseState.MouseOnRightBtn :
if (this.MdiContainerMouseState != WndMouseState.LButtonDownRightBtn)
{
this.MdiContainerMouseState = WndMouseState.LButtonDownRightBtn ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
case WndMouseState.MouseOnX :
if (this.MdiContainerMouseState!= WndMouseState.LButtonDownX)
{
this.MdiContainerMouseState = WndMouseState.LButtonDownX ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
}
}
else if (e.Button == MouseButtons.None)
{
switch (MouseIsOnLeftOrRightOrX (e.X, e.Y))
{
case WndMouseState.None :
if (this.MdiContainerMouseState != WndMouseState.None)
{
this.MdiContainerMouseState = WndMouseState.None ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
case WndMouseState.MouseOnLeftBtn :
if (this.MdiContainerMouseState != WndMouseState.MouseOnLeftBtn)
{
this.MdiContainerMouseState = WndMouseState.MouseOnLeftBtn ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
case WndMouseState.MouseOnRightBtn :
if (this.MdiContainerMouseState != WndMouseState.MouseOnRightBtn)
{
this.MdiContainerMouseState = WndMouseState.MouseOnRightBtn ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
case WndMouseState.MouseOnX :
if (this.MdiContainerMouseState!= WndMouseState.MouseOnX)
{
this.MdiContainerMouseState = WndMouseState.MouseOnX ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
break ;
}
}
}
private void MdiContainer_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
switch (MdiContainerMouseState)
{
// 单击 X
// 关闭当前文档
case WndMouseState.LButtonDownX :
TabsMenuClose_Click(sender, e) ;
break ;
case WndMouseState.LButtonDownLeftBtn :
case WndMouseState.LButtonDownRightBtn :
this.TimeTab.Enabled = false ;
this.TimeTab.Tick -= this.ehTimeTab_Tick ;
break ;
}
this.MdiContainerMouseState = WndMouseState.None ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
this.TextEditPane.Focus () ;
}
private void MdiTabs_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Graphics dc = this.CreateGraphics();
int nTabX = 10 ;
string[] arrTitles = MdiDocManager.GetTabsTitle () ;
for (int i = 0 ; i < arrTitles.Length ; i++)
{
// 叠加标题文本的长度 为了搜索被单击的TAB
if (i == MdiDocManager.CurTab)
nTabX += (int)(dc.MeasureString (arrTitles[i], CurTabFont).Width) + 10 ;
else
nTabX += (int)(dc.MeasureString (arrTitles[i], TabFont).Width) + 10 ;
// 与 e.X 比较 找到了被单击 的TAB 了
if (nTabX > e.X )
{
// 如果 被单击的TAB 就是当前 TAB
// 则什么也不做
if (i == MdiDocManager.CurTab)
break ;
// 否则
// 中文本变化将其保存到 MdiDocManager 中
this.MdiDocManager.TextTakeIn (this.TextEditPane.Lines) ;
// 被单击的TAB 设置为 当前TAB 并重画TABS 窗口
MdiDocManager.CurTab = i ;
this.MdiTabs.Invalidate () ;
// 设置 TabChange 标志 在MouseUp时更新 TextBox 的内容
TabChange = true ;
break ;
}
}
dc.Dispose () ;
if (e.Button == MouseButtons.Right)
{
// 在出现菜单前 调用 MouseUp 更新 TextBox 的内容
MdiTabs_MouseUp(sender, e) ;
// 为了不要更新 2 次设置标志 为假
TabChange = false ;
}
}
private void MdiTabs_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (this.TabChange)
{
this.TextPaneShowNewText () ;
TabChange = false ;
}
}
private void MdiTabs_SizeChanged(object sender, System.EventArgs e)
{
if (this.MdiTabs.Size.Width - MdiTabs.Location.X > this.MdiTabOwner.Size.Width)
{
this.MdiTabs.Location = new Point (this.MdiTabOwner.Size.Width
- MdiTabs.Size.Width , 0) ;
this.MdiContainer.Invalidate (
new Rectangle (this.MdiContainer.Size.Width - 50,0,50,20)) ;
}
}
private void MdiTabs_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics dc = e.Graphics ;
int nTabLen = 10 ;
string[] arrTitles = null ;
if (MdiDocManager.IsEmpty () ) return ;
// Draw a white line on botton
dc.DrawLine (Pens.White, 0, MdiTabs.Size.Height -1, MdiTabs.Size.Width, MdiTabs.Size.Height -1) ;
// Draw Tabs's text.
arrTitles = MdiDocManager.GetTabsTitle () ;
int i ; // for loop.
for (i = 0 ; i < MdiDocManager.CurTab ; i ++)
{
dc.DrawString (arrTitles[i], TabFont, TabBrush, nTabLen, 7) ;
nTabLen += (int)(dc.MeasureString (arrTitles[i], TabFont).Width) + 10 ;
dc.DrawLine (this.FramePen, nTabLen-5, 6, nTabLen-5, 20) ;
}
// Draw CurTab's Text
// Tab effect
Rectangle rect = new Rectangle (nTabLen-5, 4,
(int)(dc.MeasureString (arrTitles[i], CurTabFont).Width) + 10, 18) ;
dc.FillRectangle (this.CurTabBrush, rect) ;
dc.DrawLine (Pens.Black, rect.X + rect.Width - 1 , rect.Y ,
rect.X + rect.Width - 1, rect.Y + rect.Height - 1) ;
dc.DrawLine (Pens.White, rect.X, rect.Y, rect.X , rect.Y + rect.Height - 1) ;
dc.DrawLine (Pens.White, rect.X, rect.Y, rect.X + rect.Width - 1 , rect.Y ) ;
//
dc.DrawString (arrTitles[i], CurTabFont, Brushes.Black, nTabLen, 7) ;
nTabLen += rect.Width ;
i ++ ;
// Draw other Tab.
for (; i < arrTitles.Length ; i ++)
{
dc.DrawString (arrTitles[i], TabFont, TabBrush, nTabLen, 7) ;
nTabLen += (int)(dc.MeasureString (arrTitles[i], TabFont).Width) + 10 ;
dc.DrawLine (this.FramePen, nTabLen-5, 6, nTabLen-5, 20) ;
}
// Reset pane's size.
this.MdiTabs.Size = new Size (nTabLen, MdiTabs.Size.Height) ;
}
private void MdiTabOwner_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics dc = e.Graphics ;
dc.DrawLine (Pens.White, 0, MdiTabOwner.Size.Height-1 , MdiTabOwner.Size.Width, MdiTabOwner.Size.Height-1 ) ;
}
private void MdiTabOwner_SizeChanged(object sender, System.EventArgs e)
{
if (MdiTabs.Location.X != 0)
{
if (MdiTabs.Size.Width + MdiTabs.Location.X < MdiTabOwner.Size.Width)
{
MdiTabs.Location = new Point (MdiTabOwner.Size.Width - MdiTabs.Size.Width, 0) ;
if (MdiTabs.Location.X > 0)
{
MdiTabs.Location = new Point (0, 0) ;
}
}
}
}
private void TextEditPane_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
private void TextEditPane_Enter(object sender, System.EventArgs e)
{
GenericPane_Leave (sender, e) ;
}
private void TextEditPane_TextChanged(object sender, System.EventArgs e)
{
if (this.MdiDocManager.SetCurTabChangedFlag ())
{
this.MdiTabs.Invalidate () ;
}
}
private void DocTree_DoubleClick(object sender, System.EventArgs e)
{
// 如果有新文件要打开...
if (((FileTreeNode)this.DocTree.SelectedNode).NoteStyle == TreeNodeStyle.File)
{
this.OpenFileFromDocTree () ;
}
}
private void DocTree_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (DocTree.GetNodeAt(e.X, e.Y) != null)
{
this.DocTree.SelectedNode = DocTree.GetNodeAt(e.X, e.Y) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -