Label.Text = "B&H"

  • Thread starter Peter Morris [Droopy eyes software]
  • Start date
P

Peter Morris [Droopy eyes software]

Can I somehow tell the label that the & is not a shortcut?
 
P

Peter Morris [Droopy eyes software]

You can use two ampersands "B&&H".

No other way? I'd rather not change the value because it is a name property
on a Customer object. I don't want to have to return B&&H just for the sake
of displaying it, although I could do it in my GUI.
 
E

Eric

why not before each reading and writing of the value in it's name property
use:

string.replace("&","&&") on way and string.replace("&&","&") the other way.
 
T

Tim Wilson

There is another way. You can update the style bits for the control.

[System.Runtime.InteropServices.DllImport("coredll")]
private static extern IntPtr GetCapture();

[System.Runtime.InteropServices.DllImport("coredll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[System.Runtime.InteropServices.DllImport("coredll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
dwNewLong);

private const int GWL_STYLE = -16;
private const int SS_NOPREFIX = 0x00000080;

private void UpdateLabelStyle(Label ctrl)
{
IntPtr hWnd;
int style;

// If targeting CF 2.0 use the Handle property.
// hWnd = ctrl.Handle;
// If targeting CF 1.0 use the three lines below.
ctrl.Capture = true;
hWnd = GetCapture();
ctrl.Capture = false;

style = GetWindowLong(hWnd, GWL_STYLE);
SetWindowLong(hWnd, GWL_STYLE, (style | SS_NOPREFIX));

ctrl.Refresh();
}

And just make the following call for each Label that should be modified.

UpdateLabelStyle(this.label1);
 
P

Peter Morris [Droopy eyes software]

Hi

I decided to use the Replace() method in my GUI.

Thanks for your help as usual guys!

Pete
 
P

Philip Sheard

For CF2, you would be better off using the tag, rather than the label text.
Not an option in CF1 though.
 
P

Philip Sheard

Yes, that is right, the tag. The Tag property of the Label control. Set the
tag to "B&H", and the text to "B&&H".
 

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