none
Unicode Characters RRS feed

  • Question

  • Hi,

    I want to include a Unicode character in my WinForm GUI but can figure out how to do it, the regular [char] doesn't work. After a couple hours of Googling and I regret to say that I have given up.

    Does anyone know of a way to include characters like the one linked below to be represented in PowerShell?

    https://www.fileformat.info/info/unicode/char/1f512/index.htm

    Kind regards,

    Mark Harwood

    Wednesday, August 15, 2018 1:44 PM

Answers

  • Windows Forms does not support Unicode characters. 

    Use an image/icon in a picture control.


    \_(ツ)_/

    • Marked as answer by I.T Delinquent Thursday, August 16, 2018 4:01 PM
    Wednesday, August 15, 2018 4:13 PM
  • Just for anyone in the future that looks at this post, I converted the image of a padlock to base64 using this site

    This is the code I used to convert the base64 to an image:

    [string]$closedpadlock64=@"
    base64 string here - is going to be very long :) 
    "@
    $closedpadlockstream = [system.IO.MemoryStream][System.Convert]::FromBase64String($closedpadlock64)
    $closedpadlockbmp = [System.Drawing.Bitmap][System.Drawing.Image]::FromStream($closedpadlockstream)
    $closedpadlockhandle = $closedpadlockbmp.GetHicon()
    $closedpadlock = [System.Drawing.Icon]::FromHandle($closedpadlockhandle)

    I then used $buttonobject.image = $closedpadlock to set the button to be the padlock.

    • Marked as answer by I.T Delinquent Thursday, August 16, 2018 4:01 PM
    Thursday, August 16, 2018 4:00 PM

All replies

  • I have used code similar to below with success:

    $Ang = [char]28
    Edit: The value is a 16-bit decimal, so for example 32 is the space character.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Wednesday, August 15, 2018 2:37 PM
    Moderator
  • Hi Richard,

    I have successfully used that in the past with [char]8730 but the one I linked doesn't work, is there anyway to work with the Unicode character that I linked? I think the number is just too big for PowerShell's [char]

    Thanks for your help

    Wednesday, August 15, 2018 3:01 PM
  • I think you are correct. The character seems to be 6 digits, but the max 16-bit value (FFFF) is 65,355 in decimal. I don't know of a workaround.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Wednesday, August 15, 2018 3:25 PM
    Moderator
  • Windows Forms does not support Unicode characters. 

    Use an image/icon in a picture control.


    \_(ツ)_/

    • Marked as answer by I.T Delinquent Thursday, August 16, 2018 4:01 PM
    Wednesday, August 15, 2018 4:13 PM
  • Just for anyone in the future that looks at this post, I converted the image of a padlock to base64 using this site

    This is the code I used to convert the base64 to an image:

    [string]$closedpadlock64=@"
    base64 string here - is going to be very long :) 
    "@
    $closedpadlockstream = [system.IO.MemoryStream][System.Convert]::FromBase64String($closedpadlock64)
    $closedpadlockbmp = [System.Drawing.Bitmap][System.Drawing.Image]::FromStream($closedpadlockstream)
    $closedpadlockhandle = $closedpadlockbmp.GetHicon()
    $closedpadlock = [System.Drawing.Icon]::FromHandle($closedpadlockhandle)

    I then used $buttonobject.image = $closedpadlock to set the button to be the padlock.

    • Marked as answer by I.T Delinquent Thursday, August 16, 2018 4:01 PM
    Thursday, August 16, 2018 4:00 PM
  • To convert an image to base64 do this:

    $base64 = [convert]::ToBase64String((Get-Content D:\Images\image1.jpg -Encoding byte))


    \_(ツ)_/

    Thursday, August 16, 2018 4:55 PM
  • To convert from base64 to image:

    $bytes = [System.Convert]::FromBase64String($base64)
    $image = [System.Drawing.ImageConverter]::new().ConvertFrom($bytes)


    \_(ツ)_/

    Thursday, August 16, 2018 5:04 PM