Label.Text = "B&H"

  • Thread starter Thread starter Peter Morris [Droopy eyes software]
  • Start date Start date
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.
 
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.
 
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);
 
Hi

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

Thanks for your help as usual guys!

Pete
 
For CF2, you would be better off using the tag, rather than the label text.
Not an option in CF1 though.
 
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".
 
Back
Top