Winforms: Multiline Label; Display QueryString In Label Control

I was asked to produce a tiny Winforms app which would generate an encoded checksum for a QueryString that is consumed by one of our Web Applications. Because the encoding is based on an MD5 Hash of various data elements this Winforms app will enable our Testers and partner organisations to generate that checksum automagically.

When it came to displaying the generated checksum I encountered a problem or two:

  • When using a TEXTBOX, the QueryString would always break on the leading “?” leading to an ugly output, the first line being a “?” by itself
  • Labels are single line creatures meaning the QueryString was truncated i.e. only displayed up to the length of the Label control: there is no line wrapping
  • The ampersands in the query string were not output to the screen when using a Label control

Multiline Label
To achieve a Multiline Label: Set the Maximum Width property of the label to the same value as the Width property; Set the Height property of the label to a value that will enable it to show multiple lines; set the AutoSize property of the label to True. Thanks to Riff on the MSDN Visual Basic Forum.

Displaying Ampersand In Label Control
The reason that a Winforms Label control cannot display Anpersand is that “&” is interpereted as part the Mnemonic shortcut to the Text Field associated with the Label. To get around it, replace “&” wih “&&” in the string before displaying it or set useMnemonic to False. More details here c/o Cody Gray on Stack Overflow

Instigating the above fixes for my Label caused the Query String to display the full QueryString ampersands without breaking on the leading “?”. BUT, the value CANNOT be cut ‘n’ pasted from the Label control for use in a browser, which made it about as useful as a plywood firetruck at a refinery explosion.

So I went back to using a readonly TEXTBOX. However, semi-good news, the break-on-leading-question-mark-problem only occurs on strings shorter than the label width. So, I gave the users an option to prepend a base URL to the QueryString which covers the obscenity for long QueryStrings as the “?” is no longer the leading character.

Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: