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

📄 htmlform.cs

📁 微软的行业应用解决方案示例
💻 CS
字号:
using System;
using System.IO;
using System.Windows.Forms;
using HardwareDistributor.Business;
using HardwareDistributor.Properties;

namespace HardwareDistributor.UI
{
	public partial class HtmlForm : Form
    {
        #region Members
		        
		private string _title;
		private string _header;
		private string _message;
		private string _detail;
		private bool _clicked = false;

        #endregion

        #region Constructors

        public HtmlForm(string title, string header, string message, string detail)
		{		
			InitializeComponent();

			// We are removing both the Control Box and the Minimize Box, so that we don't
			// have to handle these in our code. This is not necessary in Windows Mobile Standard,
			// but we are writing this code so that it works on all platforms without any changes
			// or any recompiling.
			this.ControlBox = false;
			this.MinimizeBox = false;

			_title = title;
			_header = header;
			_message = message;
			_detail = detail;
        }

        #endregion

        #region Event handlers

        /// <summary>
		/// Timer has fired
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void formTimer_Tick(object sender, EventArgs e)
		{			
			// We only want this dialog up for a max of 5 seconds, so if the dialog is not already 
			// closing, then close the dialog because the timer has gone off
			if (!_clicked)
			{
				_clicked = true;
				this.Close();				
			}
		}

		/// <summary>
		/// Dismiss soft key clicked
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void menuItemDismiss_Click(object sender, EventArgs e)
		{
			// if the dialog is not already closing, close it now
			if (!_clicked)
			{
				_clicked = true;
				this.Close();
			}
		}

		/// <summary>
		/// Custom Handling for the back key
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void HtmlForm_KeyDown(object sender, KeyEventArgs e)
		{						
			if ((e.KeyCode == System.Windows.Forms.Keys.Back))
			{
				// Back

				// if the back key is hit, and the dialog is not already closing, close it now
				if (!_clicked)
				{
					_clicked = true;
					this.Close();
				}
			}
		}

		/// <summary>
		/// HTML Form Loaded
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void HtmlForm_Load(object sender, EventArgs e)
		{
			try
			{
				// These are the constant strings that we will be using to populate the html in the form
				const string startTags = "<HTML>";
				const string endTags = "</HTML>";
				const string bodyStartTag = "<BODY>";
				const string bodyEndTag = "</BODY>";
				const string endParagraphTag = "</p>";
				const string headHtml = "<head><title>{0}</title></head>";
				const string banner = "<font color='blue'><b>{0}</b></font><hr><p><br>";
				const string div = "<br><b>Details: </b><br>{0}";

				// We will write the html out to a string and then load that string using the HTML control				
				StringWriter myWriter = new StringWriter();

				// Writing the HTML out to the file
				myWriter.Write(startTags);
				myWriter.Write(headHtml, _title);
				myWriter.Write(bodyStartTag);
				myWriter.Write(banner, _header);
				myWriter.Write(_message);
				myWriter.Write(endParagraphTag);

				if (!string.IsNullOrEmpty(_detail))
				{
					myWriter.Write(div, _detail);
				}
				myWriter.Write(bodyEndTag);
				myWriter.Write(endTags);				

				// Point the webBrowser control to the HTML file				
				webBrowser.DocumentText = myWriter.ToString();
			}
			catch (Exception ex)
			{
				Business.Services.LogErrors(ex);
				MessageBox.Show(Resources.HelpNotificationError, Resources.SystemError);
			}
        }

        #endregion
    }
}

⌨️ 快捷键说明

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