views:

41

answers:

1

Hello!

My task is to make a control, that behaves itself like RichTextBox, but contains a graphical net. The only task, this net is solving, is to be visible.

It should be solution in overriding OnPaint method, but it doesn't.

This code:

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
    base.OnPaint(e);
    ...//drawing a line
}

gives me RichTextBox without of text

This code:

protected override void WndProc(ref System.Windows.Forms.Message m)
{
    base.WndProc(ref m);
        if (m.Msg == 15)
        {
            Graphics g = this.CreateGraphics();
            g.DrawLine(new Pen(Color.White, 1), new Point(0, 0), new Point(400, 400));
        }
}

sometimes draws extra lines

Actually since these two ways don't work, I don't know what to try. Waiting for your advices :)

BR Dmitry

P.S. I’ve heard a lot about great opportunities of WPF, but I’m not really common with this technology and don’t know what to start with.

P.P.S. Sorry for my English, it’s not my natural language.

+1  A: 

If by net you mean some sort of grid lines, take a look at the following to get you started:

<RichTextBox>
    <RichTextBox.Document>
        <FlowDocument>
            <Paragraph Foreground="Red">
                <Run>Sample Text...</Run>
            </Paragraph>
        </FlowDocument>
    </RichTextBox.Document>
    <RichTextBox.Background>
        <VisualBrush TileMode="Tile" Viewport="0,0,20,20" ViewportUnits="Absolute" Viewbox="0,0,20,20" ViewboxUnits="Absolute">
            <VisualBrush.Visual>
                <Rectangle Stroke="LightGray" StrokeThickness="1" Fill="Transparent" Width="100" Height="100" />
            </VisualBrush.Visual>
        </VisualBrush>
    </RichTextBox.Background>
</RichTextBox>
wpfwannabe
Oh, great! Looks pretty good:)