Reproducing "&"

  • Thread starter Thread starter Michel Vanderbeke
  • Start date Start date
M

Michel Vanderbeke

Hello,

Can you please help me?
To produce a "&"-sign on the screen, I use "&&". Otherwise I get an
underscore on the screen.
However, when a text is in a database, and I use the same field to reproduce
reports, the name in the report is written also with "&&".

So I want to have it both ways: on screen as well as on paper a single "&"
where a single "&" must be.
How can I achieve this?

Many thanks for your help,

Michel
 
Michel said:
Can you please help me?
To produce a "&"-sign on the screen, I use "&&". Otherwise I get an
underscore on the screen.

Do you mean when it appears in a menu? The ampersand is used in menus to
indicate that the next character is the keyboard shortcut for that menu
item.

Could you use the word "and" instead?

Andrew
 
Michel,

Probably you are from the BeNeLux and then from Flemish Belgium like your
name is Vanderbeke and you use as a kind of anonymous name Flupke. Can you
first tell us why the & gives an underscore on the screen. We would probably
use the same settings but I have never noticed that.

Cor
 
Can you please help me?
To produce a "&"-sign on the screen, I use "&&". Otherwise I get an
underscore on the screen.
However, when a text is in a database, and I use the same field to
reproduce reports, the name in the report is written also with "&&".

So I want to have it both ways: on screen as well as on paper a single "&"
where a single "&" must be.
How can I achieve this?

You have to handle it manually. Access keys are automatically recognized by
the system when you're dealing with windows (in menus, dialog controls,
etc.) but for custom purposes you're on your own.
 
You have to handle it manually. Access keys are automatically recognized by
the system when you're dealing with windows (in menus, dialog controls,
etc.) but for custom purposes you're on your own.

Set the UseMnemonic property to False.
 
Set the UseMnemonic property to False.

He didn't say he was using .NET but even if he is, that property only
applies to buttons and labels (not menu items for instance). How would it
help anyway.
 
He didn't say he was using .NET but even if he is, that property only
applies to buttons and labels (not menu items for instance). How would it
help anyway.

Well, yes, you are correct, although I might mention that it was
crossposted to the dotnet languages vb forum (from which I am
reading). On a button, UseMnemonic disables the automatic "hot-key"
that windows does and will present the & symbol without modification.
I had not realized the menu items would not have the same property, I
suppose I don't use them often enough.
 
He didn't say he was using .NET but even if he is, that property only
applies to buttons and labels (not menu items for instance). How would it
help anyway.
Well, yes, you are correct, although I might mention that it was
crossposted to the dotnet languages vb forum (from which I am
reading).

I missed that.
On a button, UseMnemonic disables the automatic "hot-key"
that windows does and will present the & symbol without modification.
I had not realized the menu items would not have the same property, I
suppose I don't use them often enough.

It really depends on his needs. If he requires an access key in the same
string then he might wind up with this in his DB for example:

"Process && &Exit"

That beccomes "Process & Exit" when the user see it (with the ''E'
underlined). If he now dumps it to a report however then its his
responsibility to peform this magic himself. Of course he can always store
it as ""Process & Exit" instead and track the access key another way
(storing the offset of 'E' in a separate field for instance - when
displaying it on screen, he would then replace all single occurences of "&"
with "&&" and insert the access key "&" at the given offset - if he's
localizing it though then he'd have to store the offset for each language).
 
Michel said:
Hello,

Can you please help me?
To produce a "&"-sign on the screen, I use "&&". Otherwise I get an
underscore on the screen.
However, when a text is in a database, and I use the same field to reproduce
reports, the name in the report is written also with "&&".

So I want to have it both ways: on screen as well as on paper a single "&"
where a single "&" must be.
How can I achieve this?

Many thanks for your help,

Michel

Strings often need different escaping depending on where it's used, for
example url encoding and html encoding.

In your case you need to escape the & character when you put the string
in a control by replacing it with &&.

You should store the text in the original form in the database, i.e.
with the single & characters, and do the replacement when you put the
text in the controls:

someControl.Text = textFromDatabase.Replace("&", "&&")
 
Strings often need different escaping depending on where it's used,
for example url encoding and html encoding.

In your case you need to escape the & character when you put the
string in a control by replacing it with &&.

You should store the text in the original form in the database, i.e.
with the single & characters, and do the replacement when you put the
text in the controls:

someControl.Text = textFromDatabase.Replace("&", "&&")

And depending on where this is being drawn, in Win32 there's the NOPREFIX
flag. THis applies to static text controls (SS_NOPREFIX) or DrawText
(DT_NOPREFIX).

Dave Connet
 
David Connet said:
And depending on where this is being drawn, in Win32 there's the NOPREFIX
flag. THis applies to static text controls (SS_NOPREFIX) or DrawText
(DT_NOPREFIX).

This option is even available in .NET's 'TextRenderer.DrawText' if
'TextFormaFlags.NoPrefix' is specified.
 
Back
Top