Groups | Blog | Home
all groups > dotnet drawing api > november 2003 >

dotnet drawing api : GDI+ and Text


Sueffel
11/30/2003 9:22:37 AM
I'm trying to find a solution to this problem that has plagued me for a
few months now.
Basically, I'm writing my own Telnet application, for starters, and I need
to print formatted text to the background of the form. BitBlt was the
preferred method, but it was frought with problems. My solution is to use
something along the lines of Texture brush and SolidBrushes. I'm also
choosing this method because I want to borrow a functionality from KDE, to
be able to put a background picture into the window.
The three issues I'm having is:
1) As we all know from Telnet apps using the ANSI method, a line may have
multiple formatting applied to different words or even different letters of
a word. So, I'm figuring I'm probably going to have to print this out
letter by letter.
2) I would like to have a scrollable buffer like the Multi-line Textbox, so
the user can scroll up and down and keep information for a few hundred
lines, or whatever they choose to keep.
3) When I print to the form, the form flashes. I believe this is due to
the fact that I'm unsing the OnPaint event, and when I setup the brushes, I
call Invalidate. I will post my code below, it's fairley short and works in
it's present form....

Dim textPath As GraphicsPath
Dim textRegion As Region
Dim backgroundBrush As TextureBrush
Dim forgroundBrush As SolidBrush
Dim OutputString As String
Private Sub Setup()
textPath = New GraphicsPath()
If TextBox1.Text = "" Then OutputString = "Welcome to my mind" Else :
OutputString = TextBox1.Text
Application.DoEvents()
textPath.AddString(OutputString, FontFamily.GenericSerif, 0, 75, New
Point(10, 50), _ New StringFormat())
textRegion = New Region(textPath)
backgroundBrush = New TextureBrush(New Bitmap _
("c:\WINNT\Coffee Bean.bmp"),WrapMode.Tile)
forgroundBrush = New SolidBrush(Color.Red)
Invalidate()
End Sub
Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
MyBase.OnPaintBackground(e)
Dim bgGraphics As Graphics = e.Graphics
bgGraphics.SetClip(textRegion, CombineMode.Exclude)
bgGraphics.FillRectangle(backgroundBrush, e.ClipRectangle)
bgGraphics.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Setup()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim fgGraphics As Graphics = e.Graphics
fgGraphics.FillRegion(forgroundBrush, textRegion)
fgGraphics.Dispose()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Setup()
End Sub
Private Sub Form1_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Resize
Setup()
End Sub

--
Thanks
Sueffel


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003

Sueffel
12/2/2003 2:33:20 PM
From what I'm reading there, it looks old-fashioned BitBlt is the answer,
but, if I could get a RichTextBox to do the same, I can hang with that. My
problem is, the formatting.....

Thanks
Sueffel
[quoted text, click to view]


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003

JHornick NO[at]SPAM online.microsoft.com
12/2/2003 6:00:40 PM
Hi,

GDI+'s text handling wasn't designed for this sort of work. If you need
to do multi-format text in a single line, you're better off with GDI. This
is explained in: http://support.microsoft.com/?id=307208 (despite its
title)
That article should be required reading for anyone doing text output in
GDI+ or System.Drawing. It explains the majority of the problems you'll
face.

To make your buffer scrollable, you could certainly double-buffer your
drawing through a memory bitmap.

When you update the form with Invalidate(), you're probably incurring a
background repaint which is causing the "flash". I don't recall the easiest
way to tell the form not to redraw its background. In Win32, it would be a
NULL background brush.

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.





[quoted text, click to view]
Sueffel
12/3/2003 11:43:59 AM

[quoted text, click to view]
<SNIP>
Well, how bout this....

I make a backbuffer by creating an in-memory bitmap. I format and print
all text to this bitmap, then, I select a rectangle of a certian size from
that bitmap, create new bitmap and make that my background of the
form....... That should also give me double-buffering, now I just need to
figure out how to do that, tie it into the scrollbars, and decide on hthe
best way to keep the buffer a certian size.

Lot's of stuff to think about, lot's of research to do...

Thanks
Sueffel


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003

AddThis Social Bookmark Button