473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

[C#] Block (Un)Indenting in RichTextBox.

Hiyall!

I have a RichTextBox inside a UserControl which should be able to
indent a block off text (or UnIndent for that matter) like the
SourceEditor of VS2003 or WinWord does.
All controls on the form (except for the RichTextBox) have
TabStop=False and I have a KeyDown event handler which calls the
IndentSelection function. No problem with the indenting (I've watched
when stepping through the code) except.. The e.Handled does not seem
to have any effect. I already created a new KeyUp event handler which
only states: e.Handled = true when a Tab-Key is pressed, but no luck..
Does anybody have any idea where this last TAB comes from? I already
tried the IsInput??? functions, but they have no effect whatsoever...
I'm lost here..

Thanks in advance, greetings,
L.
[CODE SNIPPET]
private void richTextBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyValue == 9) && (e.Shift))
{
if (richTextBox1.SelectionLength != 0)
{
UnIndentSelection();
e.Handled = true;
};
e.Handled = true;
}
else if (e.KeyValue == 9)
{
if (richTextBox1.SelectionLength != 0)
{
IndentSelection();
e.Handled = true;
};
};
}
private void richTextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == 9)
{
e.Handled = true;
};
}
[/CODE SNIPPET]
Nov 16 '05 #1
2 4949
Leon Friesema <leon@@frostbits.nl> wrote in
news:23********************************@4ax.com:
Hiyall!

I have a RichTextBox inside a UserControl which should be able to
indent a block off text (or UnIndent for that matter) like the
SourceEditor of VS2003 or WinWord does.
All controls on the form (except for the RichTextBox) have
TabStop=False and I have a KeyDown event handler which calls the
IndentSelection function. No problem with the indenting (I've watched
when stepping through the code) except.. The e.Handled does not seem
to have any effect. I already created a new KeyUp event handler which
only states: e.Handled = true when a Tab-Key is pressed, but no luck..
Does anybody have any idea where this last TAB comes from? I already
tried the IsInput??? functions, but they have no effect whatsoever...
I'm lost here..

Thanks in advance, greetings,
L.
[CODE SNIPPET]
private void richTextBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyValue == 9) && (e.Shift))
{
if (richTextBox1.SelectionLength != 0)
{
UnIndentSelection();
e.Handled = true;
};
e.Handled = true;
}
else if (e.KeyValue == 9)
{
if (richTextBox1.SelectionLength != 0)
{
IndentSelection();
e.Handled = true;
};
};
}
private void richTextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == 9)
{
e.Handled = true;
};
}
[/CODE SNIPPET]

Ai ai ai wat een crosspost makker! En dan nog hier in het engels ook!
Tssk tssk

Anyway, ik had de oplossing al gemaild, maar voor andere
geinteresseerden hier nog maar eens:

Je zoekt op de verkeerde plaats. Je kunt die tab helemaal niet vangen in
je form, op een keydown event. Je moet daarvoor de method ProcessCmdKey
van het control zelf overriden. Om dat te doen make je gewoon een
inherit class op basis van de richtextbox. (zie snip). Binnen de
ProcessCmdKey ga je vervolgens met je tab key aan de gang. Dit is
overigens ook de plek om andere systeemtoetsen te vangen voordat het OS
met je meedenkt

Enfin vervolgens hoef je in je form helemaal niets meer te doen, geen
toetsen afvangen of wat dan ook Doordat je met een true uit de
ProcessCmdKey springt is het alsof er niets gedrukt is verder.
[Code snip]
using System;
using System.Windows.Forms;

namespace RitchTextBox
{
/// <summary>
/// Summary description for wictRichtTextBox.
/// </summary>
public class wictRichtTextBox: System.Windows.Forms.RichTextBox
{
protected override bool ProcessCmdKey(ref Message msg, Keys
keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg ==
WM_SYSKEYDOWN))
{
switch(keyData)
{
case Keys.Tab:
if (this.SelectionLength != 0)
{

this.SelectionIndent=this.SelectionIndent+10;
}
return true;
break;
case Keys.Shift | Keys.Tab:
if (this.SelectionLength != 0)
{

this.SelectionIndent=this.SelectionIndent-10;
}
return true;
break;
}
}

return base.ProcessCmdKey(ref msg,keyData);
}
}
}

[/Code snip]

--
---
Roland Wolters
http://www.habbiebabbie.net
***** Please react via UseNet only ********
Nov 16 '05 #2
Leon Friesema <leon@@frostbits.nl> wrote in
news:23********************************@4ax.com:
Hiyall!

I have a RichTextBox inside a UserControl which should be able to
indent a block off text (or UnIndent for that matter) like the
SourceEditor of VS2003 or WinWord does.
All controls on the form (except for the RichTextBox) have
TabStop=False and I have a KeyDown event handler which calls the
IndentSelection function. No problem with the indenting (I've watched
when stepping through the code) except.. The e.Handled does not seem
to have any effect. I already created a new KeyUp event handler which
only states: e.Handled = true when a Tab-Key is pressed, but no luck..
Does anybody have any idea where this last TAB comes from? I already
tried the IsInput??? functions, but they have no effect whatsoever...
I'm lost here..

Thanks in advance, greetings,
L.
[CODE SNIPPET]
private void richTextBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyValue == 9) && (e.Shift))
{
if (richTextBox1.SelectionLength != 0)
{
UnIndentSelection();
e.Handled = true;
};
e.Handled = true;
}
else if (e.KeyValue == 9)
{
if (richTextBox1.SelectionLength != 0)
{
IndentSelection();
e.Handled = true;
};
};
}
private void richTextBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyValue == 9)
{
e.Handled = true;
};
}
[/CODE SNIPPET]

Ai ai ai wat een crosspost makker! En dan nog hier in het engels ook!
Tssk tssk

Anyway, ik had de oplossing al gemaild, maar voor andere
geinteresseerden hier nog maar eens:

Je zoekt op de verkeerde plaats. Je kunt die tab helemaal niet vangen in
je form, op een keydown event. Je moet daarvoor de method ProcessCmdKey
van het control zelf overriden. Om dat te doen make je gewoon een
inherit class op basis van de richtextbox. (zie snip). Binnen de
ProcessCmdKey ga je vervolgens met je tab key aan de gang. Dit is
overigens ook de plek om andere systeemtoetsen te vangen voordat het OS
met je meedenkt

Enfin vervolgens hoef je in je form helemaal niets meer te doen, geen
toetsen afvangen of wat dan ook Doordat je met een true uit de
ProcessCmdKey springt is het alsof er niets gedrukt is verder.
[Code snip]
using System;
using System.Windows.Forms;

namespace RitchTextBox
{
/// <summary>
/// Summary description for wictRichtTextBox.
/// </summary>
public class wictRichtTextBox: System.Windows.Forms.RichTextBox
{
protected override bool ProcessCmdKey(ref Message msg, Keys
keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;

if ((msg.Msg == WM_KEYDOWN) || (msg.Msg ==
WM_SYSKEYDOWN))
{
switch(keyData)
{
case Keys.Tab:
if (this.SelectionLength != 0)
{

this.SelectionIndent=this.SelectionIndent+10;
}
return true;
break;
case Keys.Shift | Keys.Tab:
if (this.SelectionLength != 0)
{

this.SelectionIndent=this.SelectionIndent-10;
}
return true;
break;
}
}

return base.ProcessCmdKey(ref msg,keyData);
}
}
}

[/Code snip]

--
---
Roland Wolters
http://www.habbiebabbie.net
***** Please react via UseNet only ********
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Emilia | last post by:
Hello, I am using a RichTextBox as a command line. When the user types the command “execute” on the RichTextBox, the program will perform a task. Until this is over I would like that the...
9
by: bob | last post by:
What tool do most of you people use to indent your code? Doing so by hand is a bit tedious, I think.
2
by: KenH | last post by:
I am getting an unhandled system exception while writing to a RichTextBox. The process may run for a few hours or days before the error is generated The message is "Cannot access a disposed object...
0
by: Barguast | last post by:
I've just started messing around with the new .NET 2.0 RichTextBox control and I've got a question. How would I, for example, underline the selected block of text bearing in mind that the selection...
7
by: Scott | last post by:
I need to have a RichTextBox that displays various text (in color), but the user cannot highlight or edit the text in anyway, With a regular textbox, I can set .Enabled=False and that does exactly...
12
by: M O J O | last post by:
Hi, If I inside a thread creates a RichTextBox and only use this inside the thread, will there be any thread problems? I need to convert between Text and RTF inside a thread. Thanks!! M...
0
by: iwdu15 | last post by:
hi, im creating an instant messenger using TCP sockets, and everythings been fine until now. i want to be able to send rich text, but im hitting a wall here. what i want to do is send the font...
4
by: tsahiasher | last post by:
hi, i'm trying to use the RichTextBoxSelectionColor property, but in any combination of command order i try, the text color is not changed. the only time it worked was when i set SelectionStart =...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have created a Control that extends RichTextBox to do syntax-hilighting. My strategy is to have a timer that restarts every time a user types a key so that it can wait until the user pauses for...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.