using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace demo8 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) { Form2 fm2 = new Form2(); fm2.MdiParent = this; //一定記得把this所在的窗體IsMdiContainer設置為true //a.MdiParent=this 當前窗體是窗體a的父窗體;a.MdiParent=this.MdiParent 窗體a和當前窗體的父窗體是同一個窗體 fm2.Show(); } private void 垂直平鋪VToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.TileVertical);//垂直平鋪 } private void 層疊ToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.Cascade);//層疊 } private void hToolStripMenuItem_Click(object sender, EventArgs e) { LayoutMdi(MdiLayout.TileHorizontal);//水平平鋪 } private void lToolStripMenuItem_Click(object sender, EventArgs e) { foreach (Form childForm in MdiChildren) { childForm.Close(); } //關閉子窗體 } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace demo8 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) //打開網頁 { try { string str = textBox1.Text.Trim(); webBrowser1.Navigate(new Uri("http://" + str)); this.Text = str; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } private void button2_Click(object sender, EventArgs e) //刷新 { webBrowser1.Refresh(); } private void button3_Click(object sender, EventArgs e) //上一頁 { webBrowser1.GoBack(); } private void button4_Click(object sender, EventArgs e)//下一頁 { webBrowser1.GoForward(); } } }