Read Only Text Frames in TX Text Control .NET for Windows Forms
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 Sizeable Sometimes, applications require that such text frames are not editable by the user. In this case, we can use the TextFrameActivated event to set a flag that…

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:
Sometimes, applications require that such text frames are not editable by the user. In this case, we can use the TextFrameActivated 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 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.
Related Posts
Create a Table of Contents in Windows Forms using C#
This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.
Two Ways to Restart Numbered Lists in TX Text Control
In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…
Paste Special: The Easy Way to Implement
In an older sample, I showed how to implement a paste special functionality by accessing the clipboard directly using .NET functionality. In version 15.0, we implemented this functionality…
How to Remove All Section Breaks in a Document?
With version 14.0, we introduced document section breaks that allow you to have different page formats in the same document. Version 15.0 implements page columns that can be adjusted section-wise.…
Batch Printing: How to Print Documents in One Print Job
A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our…