实例介绍
【实例简介】
【实例截图】
【核心代码】
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Khendys.Controls;
namespace RtfInsert
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class RtfInsert : System.Windows.Forms.Form
{
private Khendys.Controls.ExRichTextBox rtBox_Main;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.Panel panel1;
private MenuItem menuItem1;
private IContainer components;
public RtfInsert()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <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 Windows Form 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.components = new System.ComponentModel.Container();
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.panel1 = new System.Windows.Forms.Panel();
this.rtBox_Main = new Khendys.Controls.ExRichTextBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3});
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem8,
this.menuItem9});
this.menuItem2.Text = "Insert";
//
// menuItem8
//
this.menuItem8.Index = 0;
this.menuItem8.Text = "Image";
this.menuItem8.Click = new System.EventHandler(this.menuItem8_Click);
//
// menuItem9
//
this.menuItem9.Index = 1;
this.menuItem9.Text = "Plain Text";
this.menuItem9.Click = new System.EventHandler(this.menuItem9_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem10,
this.menuItem1});
this.menuItem3.Text = "About";
//
// menuItem10
//
this.menuItem10.Index = 0;
this.menuItem10.Text = "ExRichTextBox";
this.menuItem10.Click = new System.EventHandler(this.menuItem10_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "";
//
// panel1
//
this.panel1.Controls.Add(this.rtBox_Main);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Padding = new System.Windows.Forms.Padding(12);
this.panel1.Size = new System.Drawing.Size(728, 351);
this.panel1.TabIndex = 1;
//
// rtBox_Main
//
this.rtBox_Main.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.rtBox_Main.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtBox_Main.HiglightColor = Khendys.Controls.RtfColor.White;
this.rtBox_Main.Location = new System.Drawing.Point(12, 12);
this.rtBox_Main.Name = "rtBox_Main";
this.rtBox_Main.Size = new System.Drawing.Size(704, 327);
this.rtBox_Main.TabIndex = 0;
this.rtBox_Main.Text = "";
this.rtBox_Main.TextColor = Khendys.Controls.RtfColor.Black;
//
// RtfInsert
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(728, 351);
this.Controls.Add(this.panel1);
this.Menu = this.mainMenu1;
this.Name = "RtfInsert";
this.Text = "RTF Images";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new RtfInsert());
}
/// <summary>
/// InsertImage_Click
///
/// Allow the user to insert image files.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem8_Click(object sender, System.EventArgs e)
{
OpenFileDialog _dialog = new OpenFileDialog();
_dialog.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|"
"Windows Bitmap(*.bmp)|*.bmp|"
"Windows Icon(*.ico)|*.ico|"
"Graphics Interchange Format (*.gif)|(*.gif)|"
"JPEG File Interchange Format (*.jpg)|*.jpg;*.jpeg|"
"Portable Network Graphics (*.png)|*.png|"
"Tag Image File Format (*.tif)|*.tif;*.tiff";
if (DialogResult.OK == _dialog.ShowDialog(this))
{
try
{
// If file is an icon
if (_dialog.FileName.ToUpper().EndsWith(".ICO"))
{
// Create a new icon, get it's handle, and create a bitmap from
// its handle
rtBox_Main.InsertImage(Bitmap.FromHicon((new Icon(_dialog.FileName)).Handle));
}
else
{
// Create a bitmap from the filename
rtBox_Main.InsertImage(Image.FromFile(_dialog.FileName));
}
}
catch (Exception _e)
{
MessageBox.Show("The file could not be opened:\n\n" _e.Message, "File Open Error");
}
}
}
/// <summary>
/// InsertPlainText_Click
///
/// Inserts the text the user enters in the dialog.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem9_Click(object sender, System.EventArgs e)
{
PlainTextDialog _dialog = new PlainTextDialog();
if (DialogResult.OK == _dialog.ShowDialog())
{
// Insert text with a little formatting
rtBox_Main.InsertTextAsRtf(_dialog.PlainText, new Font(this.Font, FontStyle.Bold | FontStyle.Underline),
RtfColor.Blue, RtfColor.Yellow);
}
}
/// <summary>
/// About_Click
///
/// Print some text and images
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem10_Click(object sender, System.EventArgs e)
{
string[] _about = new string[10];
Font[] _fonts = new Font[3];
rtBox_Main.Rtf = "";
_fonts[0] = new Font(FontFamily.GenericSerif, 16f);
_fonts[1] = new Font(FontFamily.GenericSansSerif, 12f);
_fonts[2] = new Font(FontFamily.GenericMonospace, 8f);
_about[0] = "This text and images are ";
_about[1] = "being inserted on the\n";
_about[2] = "Click ";
_about[3] = "event of this menu item.\n\n";
_about[4] = "Sorry I cleared the document, ";
_about[5] = " but just click ";
_about[6] = "undo ";
_about[7] = "and you'll be ok. ";
_about[8] = "\n\nHa Ha! No undo.\n\n";
_about[9] = "Khendys was here ...";
rtBox_Main.InsertTextAsRtf(_about[0], _fonts[0]);
rtBox_Main.InsertTextAsRtf(_about[1], new Font(_fonts[1], FontStyle.Strikeout));
rtBox_Main.InsertTextAsRtf(_about[2], new Font(_fonts[0], FontStyle.Bold | FontStyle.Italic), RtfColor.Olive, RtfColor.Aqua);
rtBox_Main.InsertTextAsRtf(_about[3], new Font(_fonts[1], FontStyle.Italic), RtfColor.Gray);
rtBox_Main.InsertTextAsRtf(_about[4], new Font(_fonts[2], FontStyle.Bold), RtfColor.Red, RtfColor.Yellow);
rtBox_Main.InsertImage(new Bitmap(typeof(RtfInsert), "Smilies.AngrySmile.png"));
rtBox_Main.InsertTextAsRtf(_about[5], _fonts[0]);
rtBox_Main.InsertTextAsRtf(_about[6], _fonts[0], RtfColor.Blue, RtfColor.Aqua);
rtBox_Main.InsertTextAsRtf(_about[7], _fonts[1]);
rtBox_Main.InsertImage(new Bitmap(typeof(RtfInsert), "Smilies.CrySmile.png"));
rtBox_Main.InsertTextAsRtf(_about[8], new Font(_fonts[2], FontStyle.Bold | FontStyle.Italic), RtfColor.Red, RtfColor.Aqua);
rtBox_Main.InsertTextAsRtf(_about[9], new Font(_fonts[1], FontStyle.Italic | FontStyle.Bold | FontStyle.Underline), RtfColor.Black, RtfColor.Red);
rtBox_Main.InsertImage(new Bitmap(typeof(RtfInsert), "Smilies.Beer.png"));
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论