Source Viewer:  rtfcontrol.cs

Font Size:
Arrays.asmx  asmx2wsdl.cs  assyq.cs  hash.cs  ListTest.cs  ListTest.VB.vb  MyIpConfig.cs  Printer.cs  Printers.aspx  PrivateReflection2.cs  RegexVerifier.cs  rtfcontrol.cs  wakeup.cs 
AES-example  books  CustomTabControl  data  emacs  Embedded Resources  ftp  interop  itext  Java  js-unzip  misc  MQ  MSOffice  Mvc.HelloWorld  perl  streams  Tar  timer  web-services  WPF  xml  xml-serialization  xml1  zips 

// rtfcontrol.cs // // for demo-ing embedding of Windows Forms controls built in .NET, within IE // // Wed, 23 Apr 2003 10:32 // // based on code from: // http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=187 // // steps: // 1. build with: // csc /t:library rtfcontrol.cs // 2. upload to web server // 3. embed in a web page like so: // // <html> // <head> // <title>Test page - hosting Windows Forms controls in IE</title> // <link rel="stylesheet" href="style/basic.css"/> // </head> // <body> // <h3>Windows Forms Control hosted in IE</h3> // <center> // <object id="rtfcontrol" height="472" width="488" // classid="http://www.winisp.net/cheeso/dl/rtfcontrol.dll#devhood.rtfcontrol"> // </object> // </center> // </body> // </html> // // 4. invoke the web page // // if you modify the DLL and the upload it again, you may want to clear the download cache: // gacutil /cdl // This won't work if WindowsExplorer has the c:\windows\assembly\download folder open. // // see this article: // http://msdn.microsoft.com/msdnmag/issues/02/01/UserCtrl/default.aspx // // and this doc page: // http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemSecurityPermissionSetClassTopic.asp // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPermissionSetClassTopic.asp // http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemSecurityPermissionsSecurityPermissionAttributeClassTopic.asp using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; using System.Security.Permissions; namespace dinoch { /// <summary> /// Summary description for rtfcontrol. /// </summary> public class rtfcontrol : System.Windows.Forms.UserControl { private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button btnBold; private System.Windows.Forms.Button btnQuery; private System.Windows.Forms.Button btnItalic; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public rtfcontrol() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); myload(); } private void myload() { string s; System.Reflection.Assembly a= System.Reflection.Assembly.GetExecutingAssembly(); s= "(not found)"; try { s= a.CodeBase.ToString(); this.Append("Assembly info:\ncodebase: " + s); this.Append("\nName: "); this.Append(a.GetName().Name); this.Append("\nVersion: "); this.Append(a.GetName().Version.ToString()); this.Append("\nFullName: "); this.Append(a.FullName); this.Append("\nRuntimeVersion: "); this.Append(a.ImageRuntimeVersion); } catch (Exception e1) { s= "unknown.\n exception!\n" +e1; this.Append(s); } this.Append("\nNow checking for the location of the assembly...\n"); this.Append("This is a protected operation and *should* generate an exception.\n"); s= "(not found)"; try { s= a.Location.ToString(); } catch (Exception e2) { s= "unknown.\n cannot query assembly location. exception!\n" +e2; } this.Append("location: " + s); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if( components != null ) components.Dispose(); } base.Dispose( disposing ); } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.panel1 = new System.Windows.Forms.Panel(); this.btnItalic = new System.Windows.Forms.Button(); this.btnBold = new System.Windows.Forms.Button(); this.btnQuery = new System.Windows.Forms.Button(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // richTextBox1 // this.richTextBox1.BackColor = System.Drawing.Color.White; this.richTextBox1.Location = new System.Drawing.Point(2, 44); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(320, 200); this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = ""; // // panel1 // this.panel1.BackColor = System.Drawing.Color.LightGray; this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] { this.btnItalic, this.btnBold, this.btnQuery}); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(320, 32); this.panel1.TabIndex = 1; // // btnItalic // this.btnItalic.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.btnItalic.Location = new System.Drawing.Point(72, 8); this.btnItalic.Name = "btnItalic"; this.btnItalic.Size = new System.Drawing.Size(56, 24); this.btnItalic.TabIndex = 1; this.btnItalic.Text = "Italic"; this.btnItalic.Click += new System.EventHandler(this.btnItalic_Click); System.Windows.Forms.ToolTip tip1= new System.Windows.Forms.ToolTip(); tip1.AutoPopDelay= 3000; tip1.InitialDelay=1000; tip1.ReshowDelay= 500; tip1.SetToolTip(this.btnItalic, "Italicize the selected text"); // // btnBold // this.btnBold.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.btnBold.Location = new System.Drawing.Point(2, 8); this.btnBold.Name = "btnBold"; this.btnBold.Size = new System.Drawing.Size(56, 24); this.btnBold.TabIndex = 0; this.btnBold.Text = "Bold"; this.btnBold.Click += new System.EventHandler(this.btnBold_Click); System.Windows.Forms.ToolTip tip2= new System.Windows.Forms.ToolTip(); tip2.AutoPopDelay= 3000; tip2.InitialDelay=1000; tip2.ReshowDelay= 500; tip2.SetToolTip(this.btnBold, "Make the selected text BOLD"); // // btnQuery // this.btnQuery.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.btnQuery.Location = new System.Drawing.Point(142, 8); this.btnQuery.Name = "btnQuery"; this.btnQuery.Size = new System.Drawing.Size(66, 22); this.btnQuery.TabIndex = 0; this.btnQuery.Text = "Re-Query"; this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click); System.Windows.Forms.ToolTip tip3= new System.Windows.Forms.ToolTip(); tip3.AutoPopDelay= 3000; tip3.InitialDelay=1000; tip3.ReshowDelay= 500; tip3.SetToolTip(this.btnQuery, "Erase, and re-query"); // // rtfcontrol // this.BackColor = System.Drawing.Color.LightGray; this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panel1, this.richTextBox1}); this.Name = "rtfcontrol"; this.Resize += new System.EventHandler(this.usercontrol_Resize); this.Size = new System.Drawing.Size(420, 440); //this.richTextBox1.Size = new System.Drawing.Size(this.Size.Width - 4,this.Size.Height - 38); this.panel1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private void usercontrol_Resize(object sender, System.EventArgs e) { this.richTextBox1.Size = new System.Drawing.Size(this.Size.Width - 12,this.Size.Height - 38); } private void btnBold_Click(object sender, System.EventArgs e) { if (this.richTextBox1.SelectionFont.Bold) this.richTextBox1.SelectionFont = new Font(this.richTextBox1.SelectionFont, FontStyle.Regular); else this.richTextBox1.SelectionFont = new Font(this.richTextBox1.SelectionFont, FontStyle.Bold); } private void btnQuery_Click(object sender, System.EventArgs e) { this.richTextBox1.Select(0,this.richTextBox1.TextLength); this.richTextBox1.Text= ""; myload(); } private void btnItalic_Click(object sender, System.EventArgs e) { if (this.richTextBox1.SelectionFont.Italic) this.richTextBox1.SelectionFont = new Font(this.richTextBox1.SelectionFont, FontStyle.Regular); else this.richTextBox1.SelectionFont = new Font(this.richTextBox1.SelectionFont, FontStyle.Italic); } public void Prepend(string s) { this.richTextBox1.Text= s + this.richTextBox1.Text; } public void Append(string s) { this.richTextBox1.Text+= s; // move cursor to end: this.richTextBox1.Select(this.richTextBox1.TextLength, 0); } } }

The srcview page has been enjoyed 291584 times since 18 September 2003