karan k
karan k

Reputation: 967

Ultrabutton not displaying unicode character in text property while running application

I'm trying to display the text property of a UltraButton to this unicode character- ▼ . I've tried to copy this from the Character Map and also tried something like-

button1.Text = "\u2129"

The problem is both of them show the arrows in the designer mode in VS, but when I run the application, it shows an unrecognised symbol. I've gone through this link and this link, but the arrows only show up in the designer view, not while running the application. Why is this happening. Also, I've set the Font name to 'Arial Unicode MS'

Buttons in Designer View

Buttons while running application

Upvotes: 1

Views: 929

Answers (1)

c31983
c31983

Reputation: 449

I'm guessing the issue you are experiencing is unique to the UltraButton. From the looks of the image you just posted, you could probably get away with just using a standard Windows From Button. If you can, just open your ClassName.Designer.cs and find where your button text is being set. Copy the actual character into the text string:

this.YourButton.Text = "▼";

This shows up correctly in both the designer and when running the application.

If you really don't want to use a standard Windows Forms Button, you could always go about converting your text to an image and adding the image to the button. Would look something like this:

string text = "▼";
Font font = new Font("Arial Unicode MS", 12f);
Image img = new Bitmap(1, 1);
Graphics drawing = Graphics.FromImage(img);
SizeF textsize = drawing.MeasureString(text, font);
img.Dispose();
drawing.Dispose();
img = new Bitmap((int) textsize.Width, (int)textsize.Height);
drawing = Graphics.FromImage(img);
drawing.Clear(YourButton.BackColor);
Brush textBrush = new SolidBrush(Color.Black);
drawing.DrawString(text, font, textBrush, 0, 0);
drawing.Save();
textBrush.Dispose();
drawing.Dispose();

YourButton.Text = "";
YourButton.Image = img;

Upvotes: 1

Related Questions