📄 mdiparent.cs
字号:
this.toolBarButton8,
this.toolBarButton10,
this.toolBarButton9});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(600, 25);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.ToolTipText = "打开";
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 2;
this.toolBarButton3.ToolTipText = "保存";
//
// toolBarButton6
//
this.toolBarButton6.ImageIndex = 4;
this.toolBarButton6.ToolTipText = "拷贝";
//
// toolBarButton7
//
this.toolBarButton7.ImageIndex = 5;
this.toolBarButton7.ToolTipText = "粘贴";
//
// toolBarButton8
//
this.toolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton10
//
this.toolBarButton10.ImageIndex = 7;
//
// toolBarButton9
//
this.toolBarButton9.ImageIndex = 6;
this.toolBarButton9.ToolTipText = "关于";
//
// imageList1
//
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Silver;
//
// mdiClient1
//
this.mdiClient1.Dock = System.Windows.Forms.DockStyle.Fill;
this.mdiClient1.Location = new System.Drawing.Point(0, 25);
this.mdiClient1.Name = "mdiClient1";
this.mdiClient1.TabIndex = 2;
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(600, 393);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.toolBar1,
this.mdiClient1});
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MDI Text Editor";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
MDIChild child=new MDIChild();
child.Text="Document "+ ++WindowCount;
child.MdiParent=this;
child.Show();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofDlg=new OpenFileDialog();
ofDlg.Filter="Rich Text Format(*.rtf)|*.rtf|All Files(*.*)|*.*";
ofDlg.FilterIndex=1;
ofDlg.DefaultExt="rtf";
ofDlg.AddExtension=true;
ofDlg.RestoreDirectory=true;
ofDlg.Multiselect=false;
if(ofDlg.ShowDialog()==DialogResult.OK)
{
MDIChild child=new MDIChild();
child.Text=ofDlg.FileName;
child.MdiParent=this;
child.richTextBox1.LoadFile(ofDlg.FileName);
child.Show();
}
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
if(menuItem7.Checked)
{
toolBar1.Dock=DockStyle.None;
toolBar1.Hide();
menuItem7.Checked=false;
}
else
{
toolBar1.Dock=DockStyle.Top;
toolBar1.Show();
menuItem7.Checked=true;
}
}
private void menuItem10_Click(object sender, System.EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
}
private void menuItem11_Click(object sender, System.EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
}
private void menuItem12_Click(object sender, System.EventArgs e)
{
this.LayoutMdi(MdiLayout.ArrangeIcons);
}
private void menuItem14_Click(object sender, System.EventArgs e)
{
MessageBox.Show("多文档文本演示0.1版。\n\n作者 追风","关于Mdi Text Edit",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button ==toolBarButton1)
menuItem2_Click(null,null);
else if(e.Button ==toolBarButton2)
menuItem3_Click(null,null);
else if(e.Button ==toolBarButton3)
{
if(ActiveMdiChild!=null)
{
SaveFileDialog sfDlg=new SaveFileDialog();
sfDlg.Filter="Rich text format files(*.rtf)|*.rtf|All files(*.*)|*.*";
sfDlg.FilterIndex=1;
sfDlg.DefaultExt="rtf";
sfDlg.AddExtension=true;
sfDlg.RestoreDirectory=true;
if(sfDlg.ShowDialog()==DialogResult.OK)
{
((MDIChild)ActiveMdiChild).richTextBox1.SaveFile(sfDlg.FileName);
ActiveMdiChild.Text=sfDlg.FileName;
}
}
}
else if(e.Button==toolBarButton5)
{
if(ActiveMdiChild!=null)
((MDIChild)ActiveMdiChild).richTextBox1.Cut();
}
else if(e.Button==toolBarButton6)
{
if(ActiveMdiChild!=null)
((MDIChild)ActiveMdiChild).richTextBox1.Copy();
}
else if(e.Button==toolBarButton7)
{
if(ActiveMdiChild!=null)
((MDIChild)ActiveMdiChild).richTextBox1.Paste();
}
else if(e.Button==toolBarButton9)
menuItem14_Click(null,null);
else if(e.Button==toolBarButton10)
{
if(ActiveMdiChild!=null)
{
PrintDialog printdialog=new PrintDialog();
printdialog.Document=printDocument1;
lineReader=new StringReader(((MDIChild)ActiveMdiChild).richTextBox1.Text);
if(printdialog.ShowDialog()==DialogResult.OK)
{
try
{
printDocument1.Print();
}
catch(Exception excep)
{
MessageBox.Show(excep.Message,"打印出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
printDocument1.PrintController.OnEndPrint(printDocument1,new System.Drawing.Printing.PrintEventArgs());
}
}
}
}
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics g=e.Graphics;
float linesPerPage=0;
float yPosition=0;
int count=0;
float leftMargin=e.MarginBounds.Left;
float topMargin=e.MarginBounds.Top;
string line=null;
Font printFont=((MDIChild)ActiveMdiChild).richTextBox1.Font;
SolidBrush myBrush=new SolidBrush(Color.Black);
linesPerPage=e.MarginBounds.Height/printFont.GetHeight(g);
while(count<linesPerPage && ((line=lineReader.ReadLine())!=null))
{
yPosition=topMargin+(count*printFont.GetHeight(g));
g.DrawString(line,printFont,myBrush,leftMargin,yPosition,new StringFormat());
count++;
}
if(line!=null)
e.HasMorePages=true;
else
e.HasMorePages=false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -