I'm trying to set an error message which contains an ampersand via an ErrorProvider. First attempt went like this :
errorProvider.SetError(someControl, "You have not accepted the Terms & Conditions");
This does not display the a开发者_如何学编程mpersand character. Googling suggested the following :
errorProvider.SetError(someControl, "You have not accepted the Terms &&& Conditions");
It works (i.e. displays one ampersand), but I would like to understand why it works. Any ideas ?
EDIT : for the System.Windows.Forms.Label control, there is a property called : UseMnemonic which can be set to False. Does ErrorProvider have anything like this ?
“&” is a special character in forms that is meant to underline the following character. So if you use it like:
myButton.Text = "&Close";
it will underline the 'C' character which will also become a hotkey. If you don't want that to happen, you use double ampersand like '&&' in your text.
精彩评论