471,330 Members | 1,012 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

RTF content in Context Menu

I have a requirement- need to display RTF content in context menu. I
am able to host a rich textbox in a contextmenu strip using
ToolStripControlHost class. But assigning some RTF content to the
containing rich textbox control does not display in actual RTF
format- it just dislpays as plain text. Here's the code am using:
//Custom richtextbox to handle bg color in readonly mode
public class MyRichTextBox : RichTextBox
{
public MyRichTextBox()
{
}

public new bool ReadOnly
{
get
{
return base.ReadOnly;
}
set
{
if (value == true)
{
this.BackColor = Color.White;
}

base.ReadOnly = value;
}
}

}

----------------------------------------------------------------
public Form1()
{
InitializeComponent();

m_cmenu.Items.Add(new ToolStripMenuItem("Edit"));
m_cmenu.Items.Add(new ToolStripSeparator());

MyRichTextBox m_richTextBox = new MyRichTextBox();
m_richTextBox.BorderStyle =
System.Windows.Forms.BorderStyle.None;
m_richTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
m_richTextBox.ReadOnly = true;
m_richTextBox.ScrollBars =
System.Windows.Forms.RichTextBoxScrollBars.None;

ToolHost textItem = new ToolHost(m_richTextBox);
//Assign sample RTF content.
m_richTextBox.Rtf = @"{\rtf1\fbidis\ansi
\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss \fprq2\fcharset0
Arial;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\ltrpar\sa200\sl276\slmult1\f0\ fs28 This is\fs22
\i some\i0 \ul Rich\ulnone \b text\b0\par
\pard\ltrpar\f1\fs17\par }";

m_cmenu.Items.Add(textItem);
this.ContextMenuStrip = m_cmenu;//Assign contextmenu for
Form

}
Jun 27 '08 #1
0 1120

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Mohit Gupta | last post: by
5 posts views Thread by Dean L. Howen | last post: by
8 posts views Thread by Dennis C. Drumm | last post: by
reply views Thread by VP | last post: by
5 posts views Thread by lgbjr | last post: by
1 post views Thread by goRide | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.