Help with Tabcontrol / creategraphics / threads

A

Andy Roxburgh

I have run out of labels in my VB.NET NETCF application,
it only accepts about 100. I asked on here if there was
another way of drawing text on the screen, and John kirk
gave me this code snippet, which draws text on refresh:
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

which does the job nicely, but now I want to draw text
that's continually changing, i.e. it doesn't wait for the
form to be refreshed. I've been told to use
Me.CreateGraphics to get a graphics object, eg...

Dim g As Graphics = Me.CreateGraphics()

which is fine when the display area is just a form, but I
am now using a TabControl, and I need to draw the text on
to a TabPage. (called in this case TabPage_Road). Is it
simple to do that?

And just to complicate things further...

The application is now multithreaded and the updating is
being done from a worker thread. Does this introduce other
issues?

oh and while I'm on a roll.. one more thing...
I've got a memory leak which I suspect is coming from the
multithreading code. Any advice on tracking down these
monsters?

I'm not a hardened VB.NET expert as you may have gathered;
C and VB6 were my specialities!

Thanks

Andy
 
A

Andy Roxburgh

I should have mentioned...
TabControl_Road.CreateGraphics causes the application to
crash with a 'Notsupported Exception'. I think this is
because it's been called from a worker thread. Is there a
special way to update the GUI from a worker thread? Can
anyone give me some advice?

Andy
 
A

Andy Roxburgh

Thanks Tim - I haven't looked at the FAQ for a while,
didn't see that! How frustrating. The application is now
repainting the text correctly to the form though, from a
worker thread, but it's obscured by the tab control.
Anyone know how I could make the tab pages transparent?

Andy
 
T

Tim Wilson

Can you give some more information about your overall application and what
you are trying to accomplish with the text updating and the TabControl.
Maybe if we know more about what you're trying to do it will be easier to
make suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top