Question

I'm making a custom control (that's what I do, I'm a theme designer) and I'm having trouble with something. The control I'm making is a custom RichTextBox control. Since I want a custom border (rounded edges) arround the RichTextBox, I simply have a control with custom borders, and a child control which is actually a normal RichTextBox. With the BorderStyle set to none, it looks like this:

My rich textbox control

Now, of course, the parentcontrol needs to have all the properties a normal RichTextbox has. I manually did all the properties for a regular textbox, but a RichTextBox has far more properties and I was asking myself, is there any way to "forward" all properties of the child control to the main control?

Maybe I'm explaining it a bit oddly. Basically, when you change the main control's "Text" property the RichTextBox's Text property should change too. This means I have to write a custom event for every Property a RichTextBox has, isn't there a way to do this for every property automatically?

Thanks in advance,

Mavamaarten.

Was it helpful?

Solution

Turns out there is no way to do this.

OTHER TIPS

Note: I answered this before the posted had the WinForms tag in their question. (I actually added it based on his reply here.) Still, if you're using WPF, this is how you'd do it...

The easiest thing to do is to replace the ControlTemplate with your internal implementation. In other words, you're replacing the 'visual' portions of the RichTextBox control but you're still a RichTextBox control.

For instance, this is how I replaced the visuals of a TextBox to completely strip away all the chrome and leave it with nothing more but a simple border. But it was still a full TextBox with all properties, etc.

Again, look up Control Templating. You may also want to search for 'Lookless Controls'.

<Style TargetType="{x:Type glc:EditableTextBlock2}" BasedOn="{StaticResource {x:Type TextBox}}">

    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="MinWidth" Value="20" />

    <Setter Property="Template">
        <Setter.Value>

            <ControlTemplate TargetType="{x:Type glc:EditableTextBlock2}">

                <Border Name="Bd"
                    SnapsToDevicePixels="True"
                    BorderThickness="1"
                    BorderBrush="{TemplateBinding Border.BorderBrush}"
                    Background="{TemplateBinding Border.Background}" >

                    <ScrollViewer Name="PART_ContentHost"
                        SnapsToDevicePixels="True"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

                </Border>

            </ControlTemplate>

        </Setter.Value>
    </Setter>

</Style>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top