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 ********