# Read Only Text Frames in TX Text Control .NET for Windows Forms

> Text frames position content at fixed document locations such as recipient address blocks on a letter. This code sample creates a ProtectedTextFrame class that inherits from TextFrame and uses the TextFrameActivated event with keystroke interception to block user editing.

- **Author:** Bjoern Meyer
- **Published:** 2007-03-22
- **Modified:** 2026-03-05
- **Description:** Text frames position content at fixed document locations such as recipient address blocks on a letter. This code sample creates a ProtectedTextFrame class that inherits from TextFrame and uses the TextFrameActivated event with keystroke interception to block user editing.
- **2 min read** (397 words)
- **Tags:**
  - .NET
  - Sample
- **Web URL:** https://www.textcontrol.com/blog/2007/03/22/read-only-text-frames-in-tx-text-control-net-for-windows-forms/
- **LLMs URL:** https://www.textcontrol.com/blog/2007/03/22/read-only-text-frames-in-tx-text-control-net-for-windows-forms/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2007/03/22/read-only-text-frames-in-tx-text-control-net-for-windows-forms/llms-full.txt

---

Text frames are a very smart way to position text at a specific position in the document. They are commonly used for a recipient address details area on a letter or any other information that must be at a fixed position in a document.

TX Text Control offers properties to avoid the scaling and the movement of the frame:

[Moveable](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.framebase.moveable.property.htm "Moveable property")

[Sizeable](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.framebase.sizeable.property.htm "Sizeable property")

Sometimes, applications require that such text frames are not editable by the user. In this case, we can use the [TextFrameActivated](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.textcontrol.load.method.htm "TextFrameActivated event") event to set a flag that indicates that a text frame is currently active.

```
void TX_TextFrameActivated(object sender, TXTextControl.TextFrameEventArgs e)
{
    m_trapKeystrokes = true;
}
```

On the KeyPress event, we can trap the keystrokes, if the mentioned flag has been set to *true*.

```
void m_tx_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if (m_trapKeystrokes)
        e.Handled = true;
}
```

The [TextFrameDeactivated](https://docs.textcontrol.com/textcontrol/windows-forms/ref.txtextcontrol.textcontrol.textframedeactivated.event.htm "TextFrameDeactivated event") event is used to reset the global flag:

```
void m_tx_TextFrameDeactivated(object sender, TXTextControl.TextFrameEventArgs e)
{
    m_trapKeystrokes = false;
}
```

The following class is a sample how to inherit from the TextFrame class to create such protected text frames:

```
class ProtectedTextFrame : TXTextControl.TextFrame
{
    private bool                        m_protected;
    private TXTextControl.TextControl               m_tx;
    private bool                        m_trapKeystrokes = false;

    public ProtectedTextFrame(Size Size, bool Protected, TXTextControl.TextControl TX) : base(Size)
    {
        m_protected = Protected;
        m_tx = TX;

        if (m_protected)
        {
            m_tx.TextFrameActivated += new TXTextControl.TextFrameEventHandler(TX_TextFrameActivated);
            m_tx.TextFrameDeactivated += new TXTextControl.TextFrameEventHandler(m_tx_TextFrameDeactivated);
            m_tx.KeyPress += new System.Windows.Forms.KeyPressEventHandler(m_tx_KeyPress);
        }
    }

    void m_tx_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        if (m_trapKeystrokes)
            e.Handled = true;
    }

    void m_tx_TextFrameDeactivated(object sender, TXTextControl.TextFrameEventArgs e)
    {
        m_trapKeystrokes = false;
    }

    void TX_TextFrameActivated(object sender, TXTextControl.TextFrameEventArgs e)
    {
        m_trapKeystrokes = true;
    }

    public bool Protected
    {
        get { return m_protected; }
        set { m_protected = value; }
    }
}
```

This class can be instantiated like this:

```
ProtectedTextFrame newFrame = new ProtectedTextFrame(new Size(1000, 1000), true, textControl1);
newFrame.Protected = true;
textControl1.TextFrames.Add(newFrame, -1);
```

Feel free to contact me, if you want to discuss this approach or, if you have any questions.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Create a Table of Contents in Windows Forms using C#](https://www.textcontrol.com/blog/2023/01/23/create-toc-in-windows-forms/llms.txt)
- [Two Ways to Restart Numbered Lists in TX Text Control](https://www.textcontrol.com/blog/2021/11/03/two-ways-to-restart-numbered-lists/llms.txt)
- [Paste Special: The Easy Way to Implement](https://www.textcontrol.com/blog/2009/09/07/paste-special-the-easy-way-to-implement/llms.txt)
- [How to Remove All Section Breaks in a Document?](https://www.textcontrol.com/blog/2009/05/14/how-to-remove-all-section-breaks-in-a-document/llms.txt)
- [Batch Printing: How to Print Documents in One Print Job](https://www.textcontrol.com/blog/2009/03/20/batch-printing-how-to-print-documents-in-one-print-job/llms.txt)
- [Removing TextFields in a Loop](https://www.textcontrol.com/blog/2009/03/12/removing-textfields-in-a-loop/llms.txt)
- [Creating a Table of Contents (TOC) Using TX Text Control](https://www.textcontrol.com/blog/2009/02/02/creating-a-table-of-contents-toc-using-tx-text-control/llms.txt)
- [Rendering TX Text Control's Content to a DataGridViewCell](https://www.textcontrol.com/blog/2009/01/20/rendering-tx-text-controls-content-to-a-datagridviewcell/llms.txt)
- [Revised Sample: Converting Text to a Table](https://www.textcontrol.com/blog/2009/01/07/revised-sample-converting-text-to-a-table/llms.txt)
- [New Sample: Printing to Different Paper Trays](https://www.textcontrol.com/blog/2008/10/08/new-sample-printing-to-different-paper-trays/llms.txt)
- [Is the Current Input Position Currently Visible?](https://www.textcontrol.com/blog/2008/09/04/is-the-current-input-position-currently-visible/llms.txt)
- [New Sample: Implementing a 'paste Special' Dialog Box](https://www.textcontrol.com/blog/2008/07/10/new-sample-implementing-a-paste-special-dialog-box/llms.txt)
- [The ParagraphStyle and InlineStyle Constructor Unreveled](https://www.textcontrol.com/blog/2008/06/24/the-paragraphstyle-and-inlinestyle-constructor-unreveled/llms.txt)
- [Searching with C# Escape Sequences](https://www.textcontrol.com/blog/2008/05/29/searching-with-c-escape-sequences/llms.txt)
- [Removing Empty Tables](https://www.textcontrol.com/blog/2008/05/27/removing-empty-tables/llms.txt)
- [Manipulating the Selection Object](https://www.textcontrol.com/blog/2008/05/26/manipulating-the-selection-object/llms.txt)
- [Casting TextField Derivatives](https://www.textcontrol.com/blog/2008/05/23/casting-textfield-derivatives/llms.txt)
- [Resize Images to Fit into Page](https://www.textcontrol.com/blog/2008/05/08/resize-images-to-fit-into-page/llms.txt)
- [Printing into a PrintPreview Control](https://www.textcontrol.com/blog/2007/08/10/printing-into-a-printpreview-control/llms.txt)
- [Drag And Drop Images into TX Text Control .NET for Windows Forms](https://www.textcontrol.com/blog/2007/08/09/drag-and-drop-images-into-tx-text-control-net-for-windows-forms/llms.txt)
- [New Sample: Restarting a Numbered List](https://www.textcontrol.com/blog/2007/08/08/new-sample-restarting-a-numbered-list/llms.txt)
- [Is There a Table at the Current Mouse Position?](https://www.textcontrol.com/blog/2007/06/22/is-there-a-table-at-the-current-mouse-position/llms.txt)
- [Apply a Boxed Frame Style to Selected Cells](https://www.textcontrol.com/blog/2007/06/12/apply-a-boxed-frame-style-to-selected-cells/llms.txt)
- [Copy All Styles from One TextControl into Another](https://www.textcontrol.com/blog/2007/05/31/copy-all-styles-from-one-textcontrol-into-another/llms.txt)
- [Show Image Anchor Positions Using GDI+](https://www.textcontrol.com/blog/2007/04/25/show-image-anchor-positions-using-gdi/llms.txt)
