473,769 Members | 6,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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_Ke yDown(object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if ((e.KeyValue == 9) && (e.Shift))
{
if (richTextBox1.S electionLength != 0)
{
UnIndentSelecti on();
e.Handled = true;
};
e.Handled = true;
}
else if (e.KeyValue == 9)
{
if (richTextBox1.S electionLength != 0)
{
IndentSelection ();
e.Handled = true;
};
};
}
private void richTextBox1_Ke yUp(object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if (e.KeyValue == 9)
{
e.Handled = true;
};
}
[/CODE SNIPPET]
Nov 16 '05 #1
2 4975
Leon Friesema <leon@@frostbit s.nl> wrote in
news:23******** *************** *********@4ax.c om:
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_Ke yDown(object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if ((e.KeyValue == 9) && (e.Shift))
{
if (richTextBox1.S electionLength != 0)
{
UnIndentSelecti on();
e.Handled = true;
};
e.Handled = true;
}
else if (e.KeyValue == 9)
{
if (richTextBox1.S electionLength != 0)
{
IndentSelection ();
e.Handled = true;
};
};
}
private void richTextBox1_Ke yUp(object sender,
System.Windows. Forms.KeyEventA rgs 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
geinteresseerde n 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 wictRichtTextBo x.
/// </summary>
public class wictRichtTextBo x: System.Windows. Forms.RichTextB ox
{
protected override bool ProcessCmdKey(r ef 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.Selection Length != 0)
{

this.SelectionI ndent=this.Sele ctionIndent+10;
}
return true;
break;
case Keys.Shift | Keys.Tab:
if (this.Selection Length != 0)
{

this.SelectionI ndent=this.Sele ctionIndent-10;
}
return true;
break;
}
}

return base.ProcessCmd Key(ref msg,keyData);
}
}
}

[/Code snip]

--
---
Roland Wolters
http://www.habbiebabbi e.net
***** Please react via UseNet only ********
Nov 16 '05 #2
Leon Friesema <leon@@frostbit s.nl> wrote in
news:23******** *************** *********@4ax.c om:
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_Ke yDown(object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if ((e.KeyValue == 9) && (e.Shift))
{
if (richTextBox1.S electionLength != 0)
{
UnIndentSelecti on();
e.Handled = true;
};
e.Handled = true;
}
else if (e.KeyValue == 9)
{
if (richTextBox1.S electionLength != 0)
{
IndentSelection ();
e.Handled = true;
};
};
}
private void richTextBox1_Ke yUp(object sender,
System.Windows. Forms.KeyEventA rgs 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
geinteresseerde n 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 wictRichtTextBo x.
/// </summary>
public class wictRichtTextBo x: System.Windows. Forms.RichTextB ox
{
protected override bool ProcessCmdKey(r ef 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.Selection Length != 0)
{

this.SelectionI ndent=this.Sele ctionIndent+10;
}
return true;
break;
case Keys.Shift | Keys.Tab:
if (this.Selection Length != 0)
{

this.SelectionI ndent=this.Sele ctionIndent-10;
}
return true;
break;
}
}

return base.ProcessCmd Key(ref msg,keyData);
}
}
}

[/Code snip]

--
---
Roland Wolters
http://www.habbiebabbi e.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
318
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 user could not type anything else on the RichTextBox. How can I block the input from the keyboard? Thanks in advance, Emilia.
9
1829
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
3199
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 named RICHTEXTBOX." A check of the stack trace indicates the error is from the DLL that controls writing to the RTB. The form has not been closed and the line of code referenced is in a catch block that writes any error to this form's RTB (named...
0
1006
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 might consist of different fonts and / or styles (ie. SelectedFont will be 'null') This was pretty simple with the old RichTextBox ActiveX control in VB (RichTextBox.SelUnderline=true) but I get the impression that it won't be as simple to do...
7
10739
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 what I want, but with the RichTextBox, setting .Enabled=False turns the box grey, and I need it to stay on the BackGround color....labels won't do, as I need individual words to be different colors. Any Ideas? Scott
12
2186
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 O J O
0
1287
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 name, style, and color before every text so that way it will format it on the other end and display it in another richtextbox. right now im trying to send the .rtf property but i cant add it to the richtextbox...it just wont show anything and wont...
4
3152
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 = 0. here's one version i tried: String res = "Failed"; int selectionStart = rtbTestResult.TextLength; rtbTestResult.AppendText(res + Environment.NewLine);
8
2621
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 at least 500 milliseconds, then perform its work. The hilighting simply goes through a list of keywords, finding each instance in the RichTextBox, and selecting it in order to change its color. I figured out how to remember where the cursor is and...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.