How to suppress Ctrl+i key combination in a RichTextbox?

P

papalarge

I've noticed that Ctrl+i creates a Tab, whereas I'd like to make it
italicize instead. My code is as follows

Private Sub txtPrivate_KeyDown(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.KeyEventArgs) Handles txtPrivate.KeyDown
'IF CTRL WAS PRESSED
If e.Control Then
'IF "I" WAS PRESSED TOO
If e.KeyCode = Keys.i Then
If Not txtPrivate.SelectionFont Is Nothing Then
'MAKE SELECTED TEXT ITALIC
If txtPrivate.SelectionFont.Italic Then newFontStyle =
FontStyle.Regular Else newFontStyle = FontStyle.Italic
End If
end if
end if
End Sub

How can I suppress the default event that happens when creating a tab
character, so that my italic will take place only?
 
P

Patrick Steele

How can I suppress the default event that happens when creating a tab
character, so that my italic will take place only?

Try letting windows know you handled the keypress by setting e.Handled
to True.
 
N

Newbie Coder

It don't work Patrick because I tried that when finding a solution around 1
week ago. I even tried overriding WndProc too, but without success.
 
P

Patrick Steele

It don't work Patrick because I tried that when finding a solution around 1
week ago. I even tried overriding WndProc too, but without success.

Are you using .NET 2.0? There's a new property called
"SuppressKeyPress" that I just tested with your code and it works fine.
It prevents the RichTectBox from setting the CTRL+I.
 
N

Newbie Coder

No, I am using .NET Framework 1.1 where it doesn't work

I recently formatted my development machine because after VS 2005 SP 1
installed it slowed my machine down & all VS 1.1 projects took 30 secs to
load not 1-2 secs as they should. Now is 100% better

I had Visual Studio 6 Enterprise, Visual Studio.NET 2003 Enterprise
Architect & then VS.NET 2005 Professional. Now just VS.NET 2003 Enterprice
Architect
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top