Displaying text without using labels?

  • Thread starter Thread starter Andrew Roxburgh
  • Start date Start date
A

Andrew Roxburgh

Hi,

I have an monitoring application that displays various
pieces of data, which are changing, within a form. The
data is displayed in different colours (i.e. they are not
all the same colour), and the various items are shown in
different positions on the form. It's a status panel
basically.

I'm using labels to represent each data item.

I don't want to use labels because:
(1) I'm using the .Net Compact Framework which only allows
around 100 controls before bombing out. I have multiple
panels showing quite a few labels.
(2) more importantly, it takes too long to draw on the
screen. This is a real-time monitoring application. With
data conversions, it takes around 300ms to draw about 20
floating-point data values on the screen (I'm using WinCE
on a Hitachi SH4 processor).

So is there another method? Harking back to heady BBC
BASIC days of the 1980s, this complex task was achievable
with the PRINTAT(x,y) statement! I need to display text at
specific positions on the form, without updating all the
data simultaneously, and I need to be able to display in
different colours. It should also paint quicker than a
label control.

Anyone got any ideas?

Thanks

Andy
 
Sure, override OnPaint for the Form and just paint the text where you want
it.

-Chris
 
If you're after a code snippet, this is what I use to put text on a picture box. I use a picture box so I can put a bitmap in the background.
After you've updated the text variable(s) just refresh the control. Not sure how fast this is but as you can see it's not much more complex than your old BBC Basic.


Private mstrMessage as String

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If mstrMessage <> "" Then
Dim f As Font
Dim b As Brush
Dim r As RectangleF

r = New RectangleF(5, 5, 200, 20)
f = New Font("Arial", 10, FontStyle.Bold)
b = New SolidBrush(Color.White)
e.Graphics.DrawString(mstrMessage, f, b, r)
End If
End Sub
 
What Chris said.

I would add that you should be aware that the overloads for
System.Drawing.DrawString on CF are quite limited compared to the full
framework. For example, there is no StringFormat object in the CF. I would
also incrementally test performance as you go to make sure you're happy.
 
Thanks for the help.

Is it much more complicated to do it on a page within the
TabControl? I guess it's the same principle?

Andy
 
Thanks for the code John - that's really helped for the static text.

However I could vastly improve things if I could draw the text without having to refresh the whole form every time - I'm updating around (on average) 10 times a second so if I repaint the whole form it flickers and is quite slow.

Anyone know a way to just refresh individual pieces of text?

Thanks

Andy


----- John Kirk wrote: -----

If you're after a code snippet, this is what I use to put text on a picture box. I use a picture box so I can put a bitmap in the background.
After you've updated the text variable(s) just refresh the control. Not sure how fast this is but as you can see it's not much more complex than your old BBC Basic.


Private mstrMessage as String

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
If mstrMessage <> "" Then
Dim f As Font
Dim b As Brush
Dim r As RectangleF

r = New RectangleF(5, 5, 200, 20)
f = New Font("Arial", 10, FontStyle.Bold)
b = New SolidBrush(Color.White)
e.Graphics.DrawString(mstrMessage, f, b, r)
End If
End Sub


Chris Tacke said:
Sure, override OnPaint for the Form and just paint the text where you want
it.
 
You could draw all the static stuff into a buffer bitmap once, then in
OnPaint blit that to another bitmap, draw you non-static text, then blit
that to the Graphics object. I've done this a lot and performance is pretty
good. The other option is to repaint and invalidate just sections of your
image.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Andrew Roxburgh said:
Thanks for the code John - that's really helped for the static text.

However I could vastly improve things if I could draw the text without
having to refresh the whole form every time - I'm updating around (on
average) 10 times a second so if I repaint the whole form it flickers and is
quite slow.
Anyone know a way to just refresh individual pieces of text?

Thanks

Andy


----- John Kirk wrote: -----

If you're after a code snippet, this is what I use to put text on a
picture box. I use a picture box so I can put a bitmap in the background.
After you've updated the text variable(s) just refresh the control.
Not sure how fast this is but as you can see it's not much more complex than
your old BBC Basic.
Private mstrMessage as String

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
 
Back
Top