473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Formatting TextBox display (non-fixed width fonts)

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?
Oct 8 '08 #1
12 4788
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:
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?
Oct 8 '08 #2
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.

Oct 8 '08 #3
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:
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.
Oct 8 '08 #4
On Oct 8, 8:08*pm, jp2msft <jp2m...@discussions.microsoft.comwrote:
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
Oct 8 '08 #5
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.

Oct 8 '08 #6
"AMercer" <AM*****@discussions.microsoft.comwrote in message
news:4F**********************************@microsof t.com...
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
Oct 8 '08 #7
Ken,

What is the difference with the sample from Onur, beside that it is in VB6
code, while the code from Onur is as far as I see in fact shorter?

Cor

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.comschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
"AMercer" <AM*****@discussions.microsoft.comwrote in message
news:4F**********************************@microsof t.com...
>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

Oct 9 '08 #8
On 9 Oct, 07:36, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nlwrote:
Ken,

What is the difference with the sample from Onur, beside that it is in VB6
code, while the code from Onur is as far as I see in fact shorter?

Cor
The difference is that Onur's code includes hardcoded values for the
lengths of the text (as he remarked at the end of his post). Ken's
code doesn't need hardcoded lengths so is more reusable. And BTW I
think it's similar length to Onur's if you count carefully (Ken
cleared the text to start with & also has to set individual font
properties in individual lines in VB6)
Oct 9 '08 #9
Hi mark,

Do I miss something, here the code I saw were I removed all comments.

Onur his code
\\\
With RichTextBox1
.AppendText("Visual Basic")
.Select(0, 12)
.SelectionFont = New Font("Arial", 12)
.AppendText(" is a good language")
.Select(12, 19)
.SelectionFont = New Font("Courier New", 12)
End With
///
Ken his code
\\\
With RichTextBox1
.Text = "" 'Clear everything for the test
.SelFontName = "Courier"
.SelFontSize = 14
.SelText = "This is Courier 14" & vbCrLf
.SelFontName = "Courier New"
.SelFontSize = 10
.SelBold = True
.SelColor = vbBlue
.SelText = "This is Verdana 10, in Bold Blue"
End With
////
The only difference I see is that Onur does it in one line and Ken in two.

Can you explain more to me what you mean?

Cor

Oct 9 '08 #10
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:5B**********************************@microsof t.com...
The only difference I see is that Onur does it in one line and Ken in two.

Can you explain more to me what you mean?

Cor
Despite the differences in the languages, my comments were based on the fact
his code either needs to calculate or hard-code the selection points.... as
in...
.Select(0, 12)
..
..
..
.Select(12, 19)
The font/color settings were just an attempt to show that, if you set them
*before* adding new text, there's no reason to know the selection points at
least that's the case with the VB6 control, which is an ActiveX wrapper for
riched32.dll. The 'one line versus two' wasn't the point of my comments.

I'm just wondering if the .Net control supports this functionality as
well.... I assume it does, but have been surprised before.

...but, we've already used more keystrokes talking about it than it would've
saved in a year, so.... <g>

--
Ken Halter
Part time groupie
Oct 9 '08 #11
On Oct 9, 8:13 pm, "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com>
wrote:
"Cor Ligthert[MVP]" <notmyfirstn...@planet.nlwrote in message

news:5B**********************************@microsof t.com...
The only difference I see is that Onur does it in one line and Ken in two.
Can you explain more to me what you mean?
Cor

Despite the differences in the languages, my comments were based on the fact
his code either needs to calculate or hard-code the selection points.... as
in...
.Select(0, 12)

.
.
.
.Select(12, 19)

The font/color settings were just an attempt to show that, if you set them
*before* adding new text, there's no reason to know the selection points at
least that's the case with the VB6 control, which is an ActiveX wrapper for
riched32.dll. The 'one line versus two' wasn't the point of my comments.

I'm just wondering if the .Net control supports this functionality as
well.... I assume it does, but have been surprised before.

..but, we've already used more keystrokes talking about it than it would've
saved in a year, so.... <g>

--
Ken Halter
Part time groupie
It doesn't matter that it's shorter or longer if it just works.
However, i revised my previous code to make 2 lines shorter
here(without comments) by omitting Select method, and the thing i want
to point out is that, in fact, you don't need to select any existing
text to format it with newer font type, just use "SelectionFont"
property just before the new text that you're appending. When you
specify a font type using SelectionFont property, you're ready to
append text using that font without needing to use Select method as
follows:

' That outputs same as previous version
' without using Select method

With RichTextBox1
'Append text using Arial font
.SelectionFont = New Font("Arial", 12)
.AppendText("Visual Basic")
' From now on, append text using
' different font style eg:Courier New
.SelectionFont = New Font("Courier New", 12)
.AppendText(" is a good language")
End With

So, with the code above, it's not required to use hard-coded selection
index points and length which outputs the same as my previous code
posted.

Hope it's better and flexible,

Onur Güzel
Oct 9 '08 #12
Ken,

This was and is still for me one of the things I find confusing in the newer
versions of VB

\\\
New Font("Courier New", 12)
///

Cor

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.comschreef in bericht
news:uL**************@TK2MSFTNGP02.phx.gbl...
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:5B**********************************@microsof t.com...
>The only difference I see is that Onur does it in one line and Ken in
two.

Can you explain more to me what you mean?

Cor

Despite the differences in the languages, my comments were based on the
fact his code either needs to calculate or hard-code the selection
points.... as in...
> .Select(0, 12)
.
.
.
> .Select(12, 19)

The font/color settings were just an attempt to show that, if you set them
*before* adding new text, there's no reason to know the selection points
at least that's the case with the VB6 control, which is an ActiveX wrapper
for riched32.dll. The 'one line versus two' wasn't the point of my
comments.

I'm just wondering if the .Net control supports this functionality as
well.... I assume it does, but have been surprised before.

..but, we've already used more keystrokes talking about it than it
would've saved in a year, so.... <g>

--
Ken Halter
Part time groupie

Oct 10 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Headless | last post by:
I've marked up song lyrics with the <pre> tag because it seems the most appropriate type of markup for the type of data. This results in inefficient use of horizontal space due to UA's default...
1
by: Carlo | last post by:
Hi How do I get textbox text to be formatted on the fly as entering. I have a textbox which will hold numerics larger than a million which I want to autoformat i.e FormatNumber, so that it makes...
5
by: Jack | last post by:
Hell I have a few text boxes on my form and I need in one to allow only numbers and on the other only letters how to enforce that you can't enter numbers in a letters textbox and... Jack
3
by: BrianDH | last post by:
Hi Is there a way to have the view/display width different from the width as it sits on the form? Thanks Brian
4
by: Greg | last post by:
Embarassingly simple this one :( The below html renders the drop down significantly shorter than the textbox. Which setting (border etc) is the correct way to get these 2 controls to appear the...
18
by: obrienkev | last post by:
Hi, I have a multiline TextBox. Text contained in the TextBox will be stored in a SQL Server Database. How do I format the textBox correctly for database entry? e.g. How do I ensure that new...
5
montzter
by: montzter | last post by:
Hi evryone, I'm having trouble in formatting the inputed data in the text box so that everytime user lost focus it will adjust its value to contain the format (#,####.##). ie user will input...
6
by: Andy B | last post by:
I need to take the value of a textbox and format it in a more readable date. How do you do this? I tried textbox.text.tostring("date format string") but the compiler doesnt like that idea... any...
3
by: dougancil | last post by:
I have a web page that will be supplying data to a sql query and I want my users to type in dates as mm/dd/yyyy but my sql query needs the dates as yyyy/dd/mm. How can I reformat the textbox.text to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.