1

I need to insert a star shape into a string which will be assigned as the text of a TreeNode. Is this possible?

Each TreeNode has different levels and can be annotated by these stars. Some nodes have a single star, some have two, and some have no stars. The star(s) will always appear at the end of the text string. For example:

SU450**
DavidRR
  • 18,291
  • 25
  • 109
  • 191
Sunil
  • 175
  • 2
  • 15
  • 1
    Could you restate your question? What is the textual representation of a star? What do you mean? Tell more what you are trying to do. – BlueM Sep 04 '12 at 11:46
  • I believe OP is after a star-shaped char. – Alex Sep 04 '12 at 11:48
  • You mean a unicode char like ★ ? Windows has a tool to lookup chars and copy them. – BlueM Sep 04 '12 at 11:49

3 Answers3

6

You have to use a Font which contains the character you want to display.

Mostly, Arial Unicode MS will work.

Here's an example using 'BLACK STAR' (U+2605)

void Main()
{
    var w = new Form();
    var t = new TreeView();
    w.Controls.Add(t);
    t.Dock=DockStyle.Fill;
    var star = "\u2605";
    t.Nodes.Add("good: " + star);
    t.Nodes.Add("great: "+ star + star + star);
    t.Font=new System.Drawing.Font("Arial Unicode MS", 13f);
    w.Show();
}

enter image description here

sloth
  • 99,095
  • 21
  • 171
  • 219
  • 1
    @Sunil Yes, all strings in .net are unicode. You only have to ensure that you use a font which can display the character. It's good to use the font 'Arial Unicode MS' since it contains nearly all unicode characters and it is widely avaiable (it's part of Word, or just ship it with your software). – sloth Sep 04 '12 at 12:22
  • According to wikipedia http://en.wikipedia.org/wiki/Arial_Unicode_MS 'Arial Unicode MS' covers all of unicode 2.1, or about 38,917 chars. However according to this answer http://stackoverflow.com/a/5928054/659190 unicode 6.0 has code points for 109,384 chars. So whilst I would describe 'Arial Unicode MS''s coverage as adequate for the majority of humanity, I wouldn't say it covers nearly all chars. – Jodrell Sep 04 '12 at 13:58
  • @Jodrell Yeah, you're probably right. I should not have dared looking into the german wikipedia, which says 'Arial Unicode MS' covers the bulk of unicode characters :-) – sloth Sep 04 '12 at 14:04
4

You can't insert a shape into a string but there are a broad range of unicode characters to choose from.

Black star U+2605, looks like a good candidate.

If your font has the correct representation of a character then you will be in luck.


The is a list here on wikipedia

There is a range from U+2721 to U+2743 which offers many variations on star.


★, ✡, ✢, ✣, ✣, ✤, ✥, ✦, ✧, ✨, ✩, ✪, ✫, ✬, ✭, ✮, ✯, ✰, ✱, ✲  

Hopefully these examples are correct, my font doesen't have a representation for them.

Community
  • 1
  • 1
Jodrell
  • 34,946
  • 5
  • 87
  • 124
  • On Wikipedia, also see [Miscellaneous Symbols](https://en.wikipedia.org/wiki/Miscellaneous_Symbols). **Black star** (U+2605) is part of this Unicode block. – DavidRR Sep 24 '15 at 19:07
3

Is this character any good? (Unicode character 066D)

٭

Or, you can create your own tree node class (that inherits from System.Windows.Forms.TreeNode) and override the OnPaint method. Then you can draw whatever you require.

Or, set the icon of the TreeNode to be a star icon that you draw yourself or get from somewhere like famfamfam.

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
  • Hi Richard.. just tried to override the paint method but its not firing. Do you have any idea about that. – Sunil Sep 04 '12 at 12:14
  • You want to draw a star icon? – BlueM Sep 04 '12 at 12:34
  • @Sunil - did you go through the example on the `OnPaint` MSDN page I linked to? It's worth taking some time out to understand how the mechanism works. – Richard Ev Sep 04 '12 at 14:45