RTF content in Context Menu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aneesh Pulukkul [http://dotnet-revolutions.blogspo

    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
    ToolStripContro lHost 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()
    {
    InitializeCompo nent();

    m_cmenu.Items.A dd(new ToolStripMenuIt em("Edit"));
    m_cmenu.Items.A dd(new ToolStripSepara tor());

    MyRichTextBox m_richTextBox = new MyRichTextBox() ;
    m_richTextBox.B orderStyle =
    System.Windows. Forms.BorderSty le.None;
    m_richTextBox.D ock = System.Windows. Forms.DockStyle .Fill;
    m_richTextBox.R eadOnly = true;
    m_richTextBox.S crollBars =
    System.Windows. Forms.RichTextB oxScrollBars.No ne;

    ToolHost textItem = new ToolHost(m_rich TextBox);
    //Assign sample RTF content.
    m_richTextBox.R tf = @"{\rtf1\fbidis \ansi
    \ansicpg1252\de ff0\deflang1033 {\fonttbl{\f0\f swiss\fprq2\fch arset0
    Arial;}{\f1\fni l\fcharset0 Microsoft Sans Serif;}}
    \viewkind4\uc1\ pard\ltrpar\sa2 00\sl276\slmult 1\f0\fs28 This is\fs22
    \i some\i0 \ul Rich\ulnone \b text\b0\par
    \pard\ltrpar\f1 \fs17\par }";

    m_cmenu.Items.A dd(textItem);
    this.ContextMen uStrip = m_cmenu;//Assign contextmenu for
    Form

    }
Working...