程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#學習之簡單浏覽器

C#學習之簡單浏覽器

編輯:C#入門知識

\

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();
        }

    }
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved