Main Page | Report this Page
 
   
.NET DotNet Forum Index  »  VB.NET Forum (Visual Basic .NET)  »  Formatting TextBox display (non-fixed width fonts)...
Page 1 of 1    
Author Message
jp2msft...
Posted: Wed Oct 08, 2008 9:25 am
Guest
I want to plant an Easter Egg in our software.

We have a TextBox that is multiline and used to display all sorts of
messages on the screen for our operators based on database queries and such.

The Easter Egg I want to create would send a dump of the data for a
particular part number to the screen when a certain secret combination of
characters is pressed. If it works out well, I can actually impliment it on
our production floor.

I can read in the data and split it up in the fields it needs to be in, but
the TextBox's font is Arial, and not very good at displaying tablular data.

If I change the font to something fixed like Courier, the change will be
very obvious.

Does anyone know of a technique that I could use to make sure each field
that I want to display in the MultiLine TextBox only takes up set amount of
space?

SubString came to mind at first, but padding a field with spaces would not
get my next field to the correct position.

Tabs seem nice, but how can I tell exactly how much space a vbTab is going
to consume? What if text runs over?
kimiraikkonen...
Posted: Wed Oct 08, 2008 9:25 am
Guest
On Oct 8, 8:08 pm, jp2msft <jp2m... at (no spam) discussions.microsoft.com> wrote:
Quote:
I'm currently on a mission to find out how to include mixed fonts in a RTB,
but if you'd care to help, that would be fantastic!

Say my RTB contains several lines of existing text in Arial font, and I want
to append some new text to it in Courier New. How would that be done? Is it
similar to formatting HTML (i.e. <font name='courier new'>New Text</font>) or
...?


Related to this question, i can show a tiny snippet that is used to
make RichTextBox have multiple text with multiple font styles using
its Select method:

'----------------------------------------------------------------------
With RichTextBox1
.AppendText("Visual Basic")
.Select(0, 12)
.SelectionFont = New Font("Arial", 12)

' From now on, append text using
' different font style eg:Courier New
.AppendText(" is a good language")
.Select(12, 19)
.SelectionFont = New Font("Courier New", 12)
End With
'--------------------------------------------------------------------

Remeber you need to pass proper StartIndex and Length parameters of
Select method while using it.

Hope it gives some idea,

Onur Güzel
jp2msft...
Posted: Wed Oct 08, 2008 11:24 am
Guest
I think I found a work-around: I can use a RichTextBox instead of a standard
TextBox.

If anyone has a better solution, I'm still here.

"jp2msft" wrote:

Quote:
I want to plant an Easter Egg in our software.

We have a TextBox that is multiline and used to display all sorts of
messages on the screen for our operators based on database queries and such.

The Easter Egg I want to create would send a dump of the data for a
particular part number to the screen when a certain secret combination of
characters is pressed. If it works out well, I can actually impliment it on
our production floor.

I can read in the data and split it up in the fields it needs to be in, but
the TextBox's font is Arial, and not very good at displaying tablular data.

If I change the font to something fixed like Courier, the change will be
very obvious.

Does anyone know of a technique that I could use to make sure each field
that I want to display in the MultiLine TextBox only takes up set amount of
space?

SubString came to mind at first, but padding a field with spaces would not
get my next field to the correct position.

Tabs seem nice, but how can I tell exactly how much space a vbTab is going
to consume? What if text runs over?
AMercer...
Posted: Wed Oct 08, 2008 11:39 am
Guest
Quote:
I think I found a work-around: I can use a RichTextBox instead of a standard
TextBox.

You beat me to the punch - an RTB is a good solution. You can set the RTB's
DefaultFont property to an Arial font, and you can insert your tabular data
in a monospace font (like Courier New). You will also be able to add
highlighting (eg color) and so forth as new needs arise. I suggest you make
your app work as it does now with an RTB replacing the textbox, and that
should not take too long since RTB and TextBox both inherit TextBoxBase.
jp2msft...
Posted: Wed Oct 08, 2008 12:08 pm
Guest
I'm currently on a mission to find out how to include mixed fonts in a RTB,
but if you'd care to help, that would be fantastic!

Say my RTB contains several lines of existing text in Arial font, and I want
to append some new text to it in Courier New. How would that be done? Is it
similar to formatting HTML (i.e. <font name='courier new'>New Text</font>) or
....?

This could open up a new venu for my application!

Can a RTB create/display a table?

If you know of a nice online source for this, that's all I need! :)

"AMercer" wrote:

Quote:
I think I found a work-around: I can use a RichTextBox instead of a standard
TextBox.

You beat me to the punch - an RTB is a good solution. You can set the RTB's
DefaultFont property to an Arial font, and you can insert your tabular data
in a monospace font (like Courier New). You will also be able to add
highlighting (eg color) and so forth as new needs arise. I suggest you make
your app work as it does now with an RTB replacing the textbox, and that
should not take too long since RTB and TextBox both inherit TextBoxBase.
AMercer...
Posted: Wed Oct 08, 2008 2:57 pm
Guest
kimiraikkonen has it right. The general idea is to use the RTB tricks
associated with selection. Once some text written into the RTB and is also
selected, you can change many of its characteristics including font,
alignment, indent, color, etc.
Ken Halter...
Posted: Wed Oct 08, 2008 3:59 pm
Guest
"AMercer" <AMercer at (no spam) discussions.microsoft.com> wrote in message
news:4F5D149C-1EF9-4E41-ACE6-D9AAD407D2C3 at (no spam) microsoft.com...
Quote:
kimiraikkonen has it right. The general idea is to use the RTB tricks
associated with selection. Once some text written into the RTB and is
also
selected, you can change many of its characteristics including font,
alignment, indent, color, etc.

But... does it /have/ to be that way? The original VB6 RTB supported syntax
like this (just tried it in VB6, and it works as expected)

'========
Private Sub Command1_Click()

With RichTextBox1
.Text = "" 'Clear everything for the test

'Preset the font and size.
'This effects all text added to the control /after/ this line.
'But, only if SelText is used to append the text.
.SelFontName = "Courier"
.SelFontSize = 14
'
.SelText = "This is Courier 14" & vbCrLf
'
'New font/size/color - effects all text added after this line.
.SelFontName = "Verdana"
.SelFontSize = 10
.SelBold = True
.SelColor = vbBlue
'
.SelText = "This is Verdana 10, in Bold Blue"
End With

End Sub

'========

So... while similar to the code posted, it doesn't require pre-selecting
(or, re-selecting, which ever way you want to look at it) the text to be
manipulated. When the font/color/size/etc is set at the end of the control's
buffer, it assumes all new text will take on those characteristics.

Of course, pre-selecting/re-selecting is also supported... just trying to
save a little work for someone, that's all....
--
Ken Halter
Part time groupie
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Thu Jan 08, 2009 6:39 am