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

📄 htmlviewpane.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
//  HtmlViewPane.cs
//  Copyright (c) 2000 Mike Krueger
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Drawing;
using System.Windows.Forms;
using AxSHDocVw;

using SharpDevelop.Gui.Edit;
using SharpDevelop.Gui.Window;
using SharpDevelop.Internal.Undo;
using System.Drawing.Printing;

namespace SharpDevelop.Gui.Components {
	
	public class BrowserPane : UserControl, ISdEditable
	{
		HtmlViewPane htmlview;
		ContentWindow window;
		
		public event EventHandler         Changed;
		
		public event EventHandler         FileTransaction;
		public event ProgressEventHandler FileTransactionProgress;
		public event EventHandler         FileTransactionComplete;
		
		
		public PrintDocument PrintDocument {
			get {
				return null;
			}
		}
		
		public ISdClipboardHandable ClipboardHandler {
			get {
				return null;
			}
		}
		
		public UndoStack UndoStack  {
			get {
				return null;
			}
		}
		
		public bool WriteProtected {
			get {
				return true;
			}
			set {
				
			}
		}
		
		public override void Dispose()
		{
			base.Dispose();
			htmlview.Dispose();
		}
		void TitleChange(object sender, AxSHDocVw.DWebBrowserEvents2_TitleChangeEvent e)
		{
			window.FileName = e.text;
		}
		
		public BrowserPane(ContentWindow window)
		{
			this.window = window;
			htmlview = new HtmlViewPane(window);
			htmlview.Dock = DockStyle.Fill;
			
			Dock = DockStyle.Fill;
			
			htmlview.AxWebBrowser1.TitleChange += new DWebBrowserEvents2_TitleChangeEventHandler(TitleChange);
			Controls.Add(htmlview);
			
//			Button button1 = new Button();
//			button1.Dock = DockStyle.Top;
//			button1.Text = "Refresh";
//			button1.Click += new EventHandler(RefreshEvent);
//			Controls.Add(button1);
			
		}
		
//		void RefreshEvent(object sender, EventArgs e)
//		{
//			LoadFile(filename);
//		}
		
		string filename;
		public void LoadFile(string filename)
		{
			this.filename = filename;
			htmlview.Navigate(filename);
			if (Changed != null)
				Changed(this, null);
		}
		
		public void SaveFile(string filename)
		{
			if (FileTransaction != null &&
				FileTransactionProgress != null &&
				FileTransactionComplete != null) 
				htmlview.Navigate(filename);
		}
		
		
	}
	
	public class HtmlViewPane : UserControl
	{
		ContentWindow window       = null;
		public AxWebBrowser AxWebBrowser1 = null;
		
		public override void Dispose()
		{
			base.Dispose();
			AxWebBrowser1.Dispose();
		}
		
		public HtmlViewPane(ContentWindow window)
		{
			this.window = window;
			Dock = DockStyle.Fill;
			Size = new Size(100, 100);
			
			AxWebBrowser1 = new AxSHDocVw.AxWebBrowser();
			AxWebBrowser1.Location = new Point(0, 0);
			AxWebBrowser1.Size     = new Size(100, 100); 
			AxWebBrowser1.Dock = DockStyle.Fill;
			
            AxWebBrowser1.HandleCreated += new EventHandler(this.AxWebBrowser1_Created);
			
			Controls.Add(AxWebBrowser1);
		}
		
		bool handlecreated = false;
		string navigateto = null;
		
		public void AxWebBrowser1_Created(object sender, EventArgs evArgs) 
		{
			handlecreated = true;
			if (navigateto != null)
				Navigate(navigateto);
			AxWebBrowser1.HandleCreated -= new EventHandler(this.AxWebBrowser1_Created);
		}
		
		
		public void Navigate(string name)
		{
			if (!handlecreated) {
				navigateto = name;
				return;
			}
			object arg1 = 0; 
			object arg2 = ""; 
			object arg3 = ""; 
			object arg4 = "";
			try {
				AxWebBrowser1.Navigate(name, ref arg1, ref arg2, ref arg3, ref arg4);
			} catch (Exception e) {
				Console.WriteLine(e.ToString());
			}
		}
		
		public void RefreshExplorer(object sender, EventArgs e)
		{
			Navigate(window.FileName);
		}
	}
}

⌨️ 快捷键说明

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