No DrawMode for button?

M

Martin H.

Hello,

I have this problem:

I want to split the text for a button into 4 quadrants so that I can
define forecolor, font and text for each quadrant. That would look like
this:


Dim B1 As VirtKeyboardKey

B1.Text = "" (ist immer leer)

B1.Quadrant1Text = "ABC"
B1.Quadrant1Font = New Font("Arial",6)
B1.Quadrant1ForeColor = Color.Red

B1.Quadrant2Text="DEF"
B1.Quadrant2Font=New Font("Times New Roman",8)
B1.Quadrant2ForeColor = Color.Green

Quadrants 3 and 4 are handled in the same way.

I created my own class for this, which inherits from button class.

In the paint event I "paint" my values (text, font, forecolor) onto the
button. The problem now is that the buttons don't have a DrawMode
property and so after "painting" my values onto the button it is
overwritten with the empty string of the text property. How can I
prevent that? I use VB2005 Express edition.

Thanks a lot for any suggestion.

Best regards,

Martin
 
R

rowe_newsgroups

Hello,

I have this problem:

I want to split the text for a button into 4 quadrants so that I can
define forecolor, font and text for each quadrant. That would look like
this:

Dim B1 As VirtKeyboardKey

B1.Text = "" (ist immer leer)

B1.Quadrant1Text = "ABC"
B1.Quadrant1Font = New Font("Arial",6)
B1.Quadrant1ForeColor = Color.Red

B1.Quadrant2Text="DEF"
B1.Quadrant2Font=New Font("Times New Roman",8)
B1.Quadrant2ForeColor = Color.Green

Quadrants 3 and 4 are handled in the same way.

I created my own class for this, which inherits from button class.

In the paint event I "paint" my values (text, font, forecolor) onto the
button. The problem now is that the buttons don't have a DrawMode
property and so after "painting" my values onto the button it is
overwritten with the empty string of the text property. How can I
prevent that? I use VB2005 Express edition.

Thanks a lot for any suggestion.

Best regards,

Martin

Could you post a small but complete working sample of the problem (one
I could copy and paste into VS and debug from there)? I am having a
bit of a hard time imagining what you are trying to describe.

Thanks,

Seth Rowe
 
A

Armin Zingler

Martin H. said:
Hello,

I have this problem:

I want to split the text for a button into 4 quadrants so that I can
define forecolor, font and text for each quadrant. That would look
like this:


Dim B1 As VirtKeyboardKey

B1.Text = "" (ist immer leer)

B1.Quadrant1Text = "ABC"
B1.Quadrant1Font = New Font("Arial",6)
B1.Quadrant1ForeColor = Color.Red

B1.Quadrant2Text="DEF"
B1.Quadrant2Font=New Font("Times New Roman",8)
B1.Quadrant2ForeColor = Color.Green

Quadrants 3 and 4 are handled in the same way.

I created my own class for this, which inherits from button class.

In the paint event I "paint" my values (text, font, forecolor) onto
the button. The problem now is that the buttons don't have a
DrawMode property and so after "painting" my values onto the button
it is overwritten with the empty string of the text property. How
can I prevent that? I use VB2005 Express edition.

Thanks a lot for any suggestion.

I can not reproduce the problem. Nothing is overwritten by an empty String.

This is my quick test:

Public Class Class1
Inherits Button

Dim f As New Font("Arial", 14)

Protected Overrides Sub OnPaint( _
ByVal pevent As System.Windows.Forms.PaintEventArgs)
Dim s As SizeF

MyBase.OnPaint(pevent)
s = pevent.Graphics.MeasureString("TEST4", f)

With pevent.Graphics
.DrawString("TEST1", f, Brushes.Black, 0, 0)
.DrawString("TEST2", f, Brushes.Black, Me.Width - s.Width, 0)
.DrawString("TEST3", f, Brushes.Black, Me.Width - s.Width,
Me.Height - s.Height)
.DrawString("TEST4", f, Brushes.Black, 0, Me.Height - s.Height)
End With

End Sub

End Class


The text appears in the 4 corners and it is visible. The Button's Text
property is displayed additionally, but if I set it to "", it does not
overwrite anything.


Armin
 
M

Martin H.

Thanks Armin,

That helps a lot. I did not use the OnPaint, but the Paint event...

Thanks again!

Best regards,

Martin
 
A

Armin Zingler

Martin H. said:
Thanks Armin,

That helps a lot. I did not use the OnPaint, but the Paint event...

If I use the Paint event, it still works.


Armin
 

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

Similar Threads


Top