开发者

System.Windows.Forms.ErrorProvider - displaying "&" character

开发者 https://www.devze.com 2023-04-05 19:39 出处:网络
I\'m trying to set an error message which contains an ampersand via an ErrorProvider. First attempt went like this :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消