How to Add the Urdu Fonts in Visual Studio in Window Forms c# | Styling Fonts | Visual Studio | Window Forms | C# | Add Local Fonts in the Visual Studio Window Forms |
#UrduFontStyle #VisualStudio #Winfoms
How to write Urdu on C# Controls
How to display Urdu Unicode characters on my Windows Forms
UrduTextBox Control for C#
Urdu Fonts in the Visual Studio can be written easily without any hurdle. You just need to install the Urdu Keyboard from Google. Now if you see the fonts style then you have no option to change the style of Urdu fonts in visual studio. By default, Urdu Font style is very ugly and it might be difficult for you to read it. So, if you want to give the good looking, dashing display then you have to go to do some extra effort for it. That’s why we brought here a way to achieve the Urdu font with beautiful and Good-Looking Font Style.
//class
public static class MemoryFonts { [DllImport("gdi32.dll")] private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts); private static PrivateFontCollection pfc { get; set; } static MemoryFonts() { if (pfc == null) { pfc = new PrivateFontCollection(); } } public static void AddMemoryFont(byte[] fontResource) { IntPtr p; uint c = 0; p = Marshal.AllocCoTaskMem(fontResource.Length); Marshal.Copy(fontResource, 0, p, fontResource.Length); AddFontMemResourceEx(p, (uint)fontResource.Length, IntPtr.Zero, ref c); pfc.AddMemoryFont(p, fontResource.Length); Marshal.FreeCoTaskMem(p); p = IntPtr.Zero; } public static Font GetFont(int fontIndex, float fontSize = 20, FontStyle fontStyle = FontStyle.Regular) { return new Font(pfc.Families[fontIndex], fontSize, fontStyle); } // Useful method for passing a 4 digit hex string to return the unicode character // Some fonts like FontAwesome require this conversion in order to access the characters public static string UnicodeToChar(string hex) { int code = int.Parse(hex, System.Globalization.NumberStyles.HexNumber); string unicodeString = char.ConvertFromUtf32(code); return unicodeString; } }
In the Application where you want to apply to a specific Control of form or whole form.
constructor (){InitializeComponent();
MemoryFonts.AddMemoryFont(Properties.Resources.Jameel_Noori_Nastaleeq_Kasheeda);Fonts font=MemoryFonts.GetFont(fontindex, fontsize, fontStyle);
if you are going to apply it on over all form then you will use foreach loopforeach(Control control in this.control){ control.Font=font;}
}
Good to see this blog. Because it helped me in writing urdu in the visual studio window forms
ReplyDeleteNice
ReplyDelete