Add text bullets to a C# form - c#

I am creating a form in C# and need to display text on the form. I need some of the text to show up in a bulleted, unordered list. Is it possible to do this while using a label? Or a rich text box? I am not using ASP.NET and this is for a desktop app.
My message should look like this:
To continue please selected one of the actions below:
Click ButtonA to do this action.
Click ButtonB to do this action.
Thanks!

Just to add as a suggestion to the OP, I have found that using a StringBuilder to construct multi-line messages helps me keep the formatting straight:
StringBuilder messageBuilder = new StringBuilder(200);
messageBuilder.Append("To continue, please select one of the actions below:");
messageBuilder.Append(Environment.NewLine);
messageBuilder.Append(Environment.NewLine);
messageBuilder.Append("\t\u2022 Click Button A to do this action.");
messageBuilder.Append(Environment.NewLine);
messageBuilder.Append("\t\u2022 Click Button B to do this action.");
MessageBox.Show(messageBuilder.ToString());

You can use ASCII or UniCode characters, and reformat your string to replace a marker character with the formatting character.
Say you defined your string like so:
var myMessage = "To continue please selected one of the actions below: * Click ButtonA to do this action. * Click ButtonB to do this action."
you could do a Regex.Replace that looked for asterisks and converted to bullets:
var formattedString = Regex.Replace(myMessage, "\*", "\r\n \u2022");
Since the string was defined on one line, we also put in a newline ("\r\n").

If you'll take a look at the Character Map (Start > Programs > Accessories > System Tools > Character Map), you can locate the keystroke "code" for most characters.
For Arial Text, the "Middle Dot" keystroke combination is:
Alt+0183
To place this in your text using Visual Studio, hold down the Alt key while typing in "0183" on the Numeric Keypad (not the keys over the alpha pad).
This should give you "·" in your text.
That's as close as I have come.
Note that other special characters (degrees - Alt+0176 °, copyright - Alt+0169 ©, and many others) can be included with this technique.

Yes you can use text below:
const string text = #"To continue please selected one of the actions below:
. Click ButtonA to do this action.
. Click ButtonB to do this action.";
label1.Text = text;
You can use special characters for the bullet as well such as *.

You could use a WebBrowser control. I.E.:
WebBrowser webBrowser1 = new WebBrowser();
webBrowser1.DocumentText 1 = "<li>Click ButtonA ...</li><li>Click ButtonB ...</li>"

Related

How to lock a text box to a specific amount of characters

I'm making a little password generator and I want it to lock the output text box to 10 characters, so that when the user clicks the password genenerate button it does not just continue with an endless line of randomly generated passwords.
How can I do this?
There's a control on the text box in Visual Studio.
If you click the button and they go into properties there should be something called "max length". Set that to however long you want it.
You can use Substring() function to cut the extra characters in your generated password.
For an instance
string GeneratedPassword = "1234567891345678";
textBox1.Text = GeneratedPassword.Substring(0,10);
Also the textBox1.MaxLength = 10 will not give you the desired result. It will only limit input of the character manually in the textbox. It will not limit input of characters programmatically.

how to write x2 (x-square) in xaml

I am creating a calculator app and i want to display x2 in button content, in XAML.
I have tried the <sup> tag but it's giving an error.
You can set button text to x² - "x\u00b2"
You just want the text (Content) of the button to have x² written?? Then you simply want superscript character 2.
Then you can just copy and paste the text above ;)
here is the list of unicode characters-
http://www.fileformat.info/info/unicode/category/No/list.htm
That should work:
<Button Content="x²"/>

How to make string bold in code behind

Is there a way to make a string bolder in code behind using C# .NET?
I tried:
string TypeofDay = "<span style='font-weight: bold'>Type Of Day</span> ";
txtbox.Text = TypeofDay + ": " + "Delivery Day"
I am concatenating TypeofDay(bold) and "Delivery Day" to display in a textbox.
You can't make some bits bold and some bits not bold, in an <asp:TextBox>.
You can't make text bolder by enclosing text value in tags. You must change attribute of a control that displays that text for example by setting its CSS class or changing code-behind property:
txbSendMessageBody.Font.Bold = true;
PS. I am concatenating few bold strings and some other strings to display in a textbox.
A HTML text box does not support this. ASP.NET (usually) generates HTML; if HTML does not support this, you cannot solve it from the server side.
A bit hacky alternative can be to use Unicode bold characters
http://qaz.wtf/u/convert.cgi?text=Type+Of+Day
txtbox.Text = "𝗧𝘆𝗽𝗲 𝗢𝗳 𝗗𝗮𝘆: 𝖣𝖾𝗅𝗂𝗏𝖾𝗋𝗒 𝖣𝖺𝗒"
You could layer a div on top of the textbox. Since the text formatting would change anyway once the user started typing, you can just hide the div once focus is given to the div, thus showing the text box. If nothing is entered and focus is lost, show the div again.
TextBox, no, however you could use a label.
myLabel.text = "<b>bold text</b> normal text <u>underlined text</u> <span style='font-size:Large; color:Red'>Big red text</span>";

C# Button Text Unicode characters

C# doesn't want to put Unicode characters on buttons. If I put \u2129 in the Text attribute of the button, the button displays the \u2129, not the Unicode character, (example - I chose 2129 because I could see it in the font currently active on the machine).
I saw this question before, link text, but the question isn't really answered, just got around. I am working on applications which are going all over the world, and don't want to install all the fonts, more then "don't want", there are that many that I doubt the machine I am working on has sufficient disk space. Our overseas sales agents supply the Unicode character "numbers". Is there another way forward with this?
As an aside, (curiosity), why does it not work?
The issue is:
C# will let you put Unicode in, like button1.Text = "Hello \u2129";, no problem
but the Visual Studio Forms designer will not recognize '\u2129' as anything special. By design.
So just paste in the '℩' in the Properties Window or use code.
Change the "Font" of the button to the "Font" (From google:Arial Unicode MS) which supports "u2129". It may help you
have you tried entering the characters manually? also, have you tried using a literal string with #"blahblahblah" ?
I was trying to include copyright symbol (\u00a9) in the form title. Using escape characters or changing fonts didn't work for me. I simply copy-pasted the symbol from text editor.

Which control to use for quick text input (inputbox)?

I need a quick text input dialog box (MessageBox with a single text box in it). Is there any control available or should I use a form?
I just want user to enter some ID. And in other occasion I want 2 texboxes for username and password.
Microsoft.VisualBasic.dll has an InputBox method which you can use from C# to get a single string.
For example (Add a reference to Microsoft.VisualBasic.dll first)
using Microsoft.VisualBasic;
string response = Interaction.InputBox("Enter a string:", "MyApp", "DefaultString", 0, 0);
Othewise, you'll have to make your own form.
simple one is inputbox

Categories

Resources