Control of TextBox paint

Muvlo

Newcomer
Joined
Jan 5, 2003
Messages
3
Hi. :)

I'm trying to create a special TextBox that gives me control over the appearance of text in that box per character.

This needs to be a completely visual effect. The program should see it as normal text.

I've seen several tutorials with about changing the border of a TextBox or something like that, which seems pretty close to what I want. Unfortunatly, I was never able to get any of these to work. :-\

I'd appreciate any help you can give me. :)

-Muvlo
 
You can try using a RichTextBox control. By setting the SelectionStart
property to the position of the character you want to alter, and set
SelectionLength to 1, then you can use the other Selection properties
to modify the fonts and colors. The Text property will still return the
normal text.

Look in the Code Library for an example of a RoundedTextBox by
Bucky. You can set the rounding to 0 and still change the border color,
leaving you with a colored, square textbox. You have to modify
Bucky's control to support the RichTextBox (not very hard at all) if
you want both char-by-char control AND colored border. I believe
that all you have to do is Inherit the RichTextBox instead of the
normal TextBox.
 
A RichTextBox is a good idea, but what if the user wanted to undo something? Unless there is a way to control undo, they'd have to go back through a lot of little changes to formating.

-Muvlo
 
In case someone finds this code useful, here is what I've ended up doing:

Code:
Imports System.Windows.Forms
Imports System.Drawing

Public Class CodeBox
    Inherits TextBox

    Public Sub New()
        MyBase.New()

        Me.SetStyle(ControlStyles.UserPaint, True)
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = e.Graphics
        'Insert whatever graphics code is needed...
    End Sub
End Class

This class is compiled as a class library, and it can then be used as a control. :)

-Muvlo
 
Back
Top