0

I would like to put the name of a resource into a string, because this resource name appears everywhere in the code and this prevents quick changes.

Dim fontMemPointer As IntPtr = Marshal.AllocCoTaskMem(My.Resources.DIGITALDREAMNARROW.Length)

You see a font name in this case called "DIGITALDREAMNARROW". I tried declare a string in which I put the font name so I can quickly use other fonts.

Dim MyFont As String = "DIGITALDREAMNARROW"
Dim fontMemPointer As IntPtr = Marshal.AllocCoTaskMem(My.Resources.MyFont.Length)

But obviously, the part after My.Resources. is an exact literal name which is not interpreted as a string. Is there a technique to solve this?

Geoff Vane
  • 33
  • 1
  • 8
  • 1
    See the `AddFontsFromResources()` method shown here: [How to properly render an embedded Font?](https://stackoverflow.com/a/64512339/7444103) – Jimi Oct 25 '20 at 16:15
  • Thanks for the swift reply. Alas I need concrete simple examples: I am not capable to understand abstract professional descriptions of code. – Geoff Vane Oct 25 '20 at 16:33
  • 2
    There's no very much to understand. Get the `AddFontsFromResources()` method: as you can see, it uses Resources by name to install embedded Fonts. The `My.Resources.ResourceManager.GetObject(fontName)` method call creates an Object from a string, the name of a Resource. You then need to cast the object to the actual Type, which is `Byte()`, in that case. Or `Image` if you embedded an Bitmap of some kind, etc. – Jimi Oct 25 '20 at 16:48
  • Thanks for your patience and your efforts but after reading this several times I have no clue as to what you could possibly mean. I can only create apps by examining existing code and guessing what it does. The descriptions of methods and objects are beyond me. I will just use find and replace to change the font name everywhere. Sorry. – Geoff Vane Oct 25 '20 at 18:53

0 Answers0