You can change the text alignment in the RichTextBox control when you set the ReadOnly property to true (814311)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# 2005, Express Edition
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
Beta Information This article discusses a Beta release of a Microsoft
product. The information in this article is provided as-is and is subject to
change without notice.
No formal product support is available from
Microsoft for this Beta product. For information about how to obtain support
for a Beta release, see the documentation that is included with the Beta
product files, or check the Web location from which you downloaded the release.
SYMPTOMS You set the ReadOnly property to True in the RichTextBox control. You
can still change the text alignment in the RichTextBox to
Right, Left, Justify, and
Middle by using the RichEdit functional shortcut keys such as CTRL+R, CTRL+L, CTRL+J, and
CTRL+E, respectively.CAUSEWhen you set the ReadOnly Property to True, you cannot change the
RichTextBox text. However, you can copy the text. The shortcut keys for
copying, alignment, and other procedures are derived from the RichEdit functionality. By default, these shortcuts are
permitted.WORKAROUNDTo work around this problem, add the following code to the KeyDown event of the RichText Box. This code ignores the keys that you
press (such as CTRL+E, CTRL+L, CTRL+R, and CTRL+J). Visual Basic or Visual Basic 2005 Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
If RichTextBox1.ReadOnly = True Then
If (e.KeyValue = Keys.Control Or e.KeyValue = Keys.E _
Or e.KeyValue = Keys.J Or e.KeyValue = Keys.L _
Or e.KeyValue = Keys.R) Then
'Set handled = true
e.Handled = True
End If
End If
End Sub Visual C# or Visual C# 2005 private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// If Readonly Property is Set to True then only disable the keys
if (richTextBox1.ReadOnly == true)
{
if (e.KeyValue == (int)Keys.Control ||
e.KeyValue == (int)Keys.E ||
e.KeyValue == (int)Keys.J ||
e.KeyValue == (int)Keys.L ||
e.KeyValue == (int)Keys.R)
{
// Set handled = true
e.Handled = true;
}
}
} STATUS This
behavior is by design.
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005applies kbvs2005swept kbWindowsForms kbprb kbEditCtrl kbRichEdit kbCtrl kbControl KB814311 kbAudDeveloper |
---|
|