none
StringFormat.SetDigitSubstitution not work in Windows 8 RRS feed

  • Question

  • I Want Use Farsi Number in My Application While Text is Any Language This Code Work in Windows 7 But Not Work In Windows 8 & 8.1. Please Help me.

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            SetDigitSubExample(e);
        }
    
        public void SetDigitSubExample(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
            Font myFont = new Font("Courier New", 12);
            StringFormat myStringFormat = new StringFormat();
            string myString = "0 1 2 3 4 5 6 7 8 9";
    
            // Farsi (1065) digits. 
    
            // Use National substitution method.
            myStringFormat.SetDigitSubstitution(1065, StringDigitSubstitute.National);
            g.DrawString("Farsi:\nMethod of substitution = National:     " + myString, myFont, blueBrush, new PointF(10.0f, 20.0f), myStringFormat);
    
            // Use Traditional substitution method.
            myStringFormat.SetDigitSubstitution(1065, StringDigitSubstitute.Traditional);
            g.DrawString("Method of substitution = Traditional:  " + myString, myFont, blueBrush, new PointF(10.0f, 55.0f), myStringFormat);
        }

    Windows 7: http://tinypic.com/r/etb5gl/5

    Windows 8: http://tinypic.com/r/30j1ysm/5

    Thursday, November 14, 2013 9:05 PM

Answers

All replies

  • Hello Ali,

    What version .net framework have it been targeted to?

    If the version is 4 or lower, unfortunately, it is not supported. See it here and have a look at the platforms.

    We can see Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    So target the version to 4.5 and it will support Windows 8

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Saturday, November 16, 2013 2:25 AM
    Moderator
  • Thanks for your guidance.

    According to your tip (.net Framework Version), I use native GDI+ methods to retest DigitSubstitution.

    Step1:

    Install clean Windows 7 And Windows 8 And Windows 8.1 (with no change, All are MSDN Version)

    Step:

    Run a sample program (below code), but no change affected.

    Visual Studio 2012, C++ 11, Native

    #include <windows.h>
    #include <objidl.h>
    #include <gdiplus.h>
    
    using namespace Gdiplus;
    #pragma comment (lib,"Gdiplus.lib")
    
    VOID OnPaint(HDC hdc)
    {
    	Graphics graphics(hdc);
    
    	WCHAR string[] = L"0123456789";
    
    	FontFamily   fontFamily(L"Tahoma");
    	Font         font(&fontFamily, 72, FontStyleRegular, UnitPoint);
    	PointF       pointF(0.0f, 10.0f);
    	StringFormat stringFormat;
    	SolidBrush   solidBrush(Color(255, 0, 0, 255));
    
    	LANGID		Farsi = 1065;
    
    
    	//stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft);
    
    	stringFormat.SetDigitSubstitution(Farsi, StringDigitSubstituteNational);
    
    	graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
    
    	graphics.DrawString(string, -1, &font, pointF, &stringFormat, &solidBrush);
    }
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)
    {
    	HWND                hWnd;
    	MSG                 msg;
    	WNDCLASS            wndClass;
    	GdiplusStartupInput gdiplusStartupInput;
    	ULONG_PTR           gdiplusToken;
    
    	// Initialize GDI+.
    	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
    	wndClass.style          = CS_HREDRAW | CS_VREDRAW;
    	wndClass.lpfnWndProc    = WndProc;
    	wndClass.cbClsExtra     = 0;
    	wndClass.cbWndExtra     = 0;
    	wndClass.hInstance      = hInstance;
    	wndClass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    	wndClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
    	wndClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wndClass.lpszMenuName   = NULL;
    	wndClass.lpszClassName  = TEXT("GettingStarted");
    
    	RegisterClass(&wndClass);
    
    	hWnd = CreateWindow(
    		TEXT("GettingStarted"),   // window class name
    		TEXT("Getting Started"),  // window caption
    		WS_OVERLAPPEDWINDOW,      // window style
    		CW_USEDEFAULT,            // initial x position
    		CW_USEDEFAULT,            // initial y position
    		CW_USEDEFAULT,            // initial x size
    		CW_USEDEFAULT,            // initial y size
    		NULL,                     // parent window handle
    		NULL,                     // window menu handle
    		hInstance,                // program instance handle
    		NULL);                    // creation parameters
    
    	ShowWindow(hWnd, iCmdShow);
    	UpdateWindow(hWnd);
    
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	GdiplusShutdown(gdiplusToken);
    	return msg.wParam;
    }  // WinMain
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	HDC          hdc;
    	PAINTSTRUCT  ps;
    
    	switch(message)
    	{
    	case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    		OnPaint(hdc);
    		EndPaint(hWnd, &ps);
    		return 0;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	default:
    		return DefWindowProc(hWnd, message, wParam, lParam);
    	}
    } // WndProc

     So I think there is a bug in Windows 8 in GDI+ modules.

    Can You Help Me?

    Sunday, November 17, 2013 12:34 PM
  • Hello Bahari,

    I am sorry that I do not realize that you use the C++.

    I should recommend you to post your issue to the C++ forum earlier.

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vcgeneral

    My first post is for C#.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, November 18, 2013 9:45 AM
    Moderator