PDA

View Full Version : سوال: فارسی کردن دکمه های پنجره پیغام



mohammad diba
چهارشنبه 16 اردیبهشت 1388, 09:04 صبح
سلام بر دوستان برنامه نویس
یه سوال داشتم می خواستم بدونم روشی هست که دکمه های ok یا yesو... پنجره پیغام رو فارسی کرد . یا باید از کامپوننت استفاده کرد ممنون می شم اگه کمکم کنید

happy65_sh
چهارشنبه 16 اردیبهشت 1388, 09:29 صبح
دوست عزیز زحمت این کار با خودت هست.اما اگه دنبال نمونه های آماده می گردی به قسمت نمونه برنامه های کوچک و مفید در سی شارپ مراجعه کن.یه
Message Box تمام فارسی (http://72.232.49.243/forum/showpost.php?p=562255&postcount=97) توسط آقای razavi_university (http://barnamenevis.org/forum/member.php?u=10478) در همان تاپیک اول گذاشته شده.

mohammad diba
چهارشنبه 16 اردیبهشت 1388, 09:44 صبح
ولی من فکر کنم روشی باشه چون آفیس رو که فارسی می کنی پیغام های آفیس هم فارسی می شه

Milad Mohseny
چهارشنبه 16 اردیبهشت 1388, 09:47 صبح
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;

public delegate int CallBack_WinProc(int uMsg , int wParam, int lParam);
public delegate int CallBack_EnumWinProc(int hWnd, int lParam);

namespace msg
{
/// <summary>
/// Summary description for MessageBox.
/// </summary>
public class MsgBox
{
public MsgBox()
{
}

[DllImport("user32.dll")]
static extern int GetWindowLong(int hwnd, int nIndex);

[DllImport("kernel32.dll")]
static extern int GetCurrentThreadId();

[DllImport("user32.dll")]
static extern int SetWindowsHookEx(int idHook, CallBack_WinProc lpfn, int hmod, int dwThreadId);

[DllImport("user32.dll")]
static extern int UnhookWindowsHookEx(int hHook);

[DllImport("user32.dll",CharSet = CharSet.Auto)]
static extern int SetWindowText(int hwnd, string lpString);

[DllImport("user32.dll")]
static extern int EnumChildWindows(int hWndParent,CallBack_EnumWinProc lpEnumFunc, int lParam);

[DllImport("user32.dll")]
static extern int GetClassName(int hwnd ,StringBuilder lpClassName,int nMaxCount);

static int TopCount;
static int ButtonCount;

private const int GWL_HINSTANCE = (-6);
private const int HCBT_ACTIVATE = 5;
private const int WH_CBT = 5;

private static int hHook;

static string strCaption1;
static string strCaption2;
static string strCaption3;

public static DialogResult ShowMessage(int hParent, string Prompt ,string Title, string Caption1, string Caption2, string Caption3, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton DefaultButton, MessageBoxOptions options)
{
int hInst;
int Thread;
TopCount = 0;
ButtonCount = 0;

strCaption1 = Caption1;
strCaption2 = Caption2;
strCaption3 = Caption3;

if (Title == "")
Title = Application.ProductName;

CallBack_WinProc myWndProc = new CallBack_WinProc(WinProc);

hInst = GetWindowLong(hParent, GWL_HINSTANCE);
Thread = GetCurrentThreadId();
hHook = SetWindowsHookEx(WH_CBT, myWndProc, hInst, Thread);

return MessageBox.Show(Prompt, Title, buttons, icon, DefaultButton, options);
}

private static int WinProc(int uMsg, int wParam, int lParam)
{
CallBack_EnumWinProc myEnumProc = new CallBack_EnumWinProc(EnumWinProc);

if (uMsg == HCBT_ACTIVATE)
{
EnumChildWindows(wParam, myEnumProc, 0);
UnhookWindowsHookEx(hHook);
}

return 0;
}

private static int EnumWinProc(int hWnd, int lParam)
{
StringBuilder strBuffer = new StringBuilder(256);
TopCount += 1;

GetClassName(hWnd, strBuffer, strBuffer.Capacity);
string ss = strBuffer.ToString();

if (ss.ToUpper().StartsWith("BUTTON"))
{
ButtonCount += 1;
switch (ButtonCount)
{
case 1:
SetWindowText(hWnd, strCaption1);
break;
case 2:
SetWindowText(hWnd, strCaption2);
break;
case 3:
SetWindowText(hWnd, strCaption3);
break;
}
}
return 1;
}
}
}

طريقه استفاده
[
MsgBox.ShowMessage(this.Handle.ToInt32(), ".نام کاربری یا کلمه عبور صحیح نمی باشد", "!! توجه", "ادامه", "", "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
از همين سايت هست ولي لينك دقيقش يادم نيست