الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

اصنع رسائل بالعربي وتحكم بها (create your own arabic message box)

مغلق
بدأه أبو هاشم المصري في 5 مارس 2007 · 3 رد · 5,608 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

فكرت في عرض رسالة باللغة العربية أي استخدام موافق والغاء ونعم ولا وتجاهل ..... بدلا من (ok cancel yes no ignor ....)

بحثت ووجدت مقالات في projectcode تتحدث عن التحكم في الرسائل التي يوفرها النظام مثل هذه المقالة الرابط وهي مقالة جيدة ولكن الآداة كتبت بc++ وتم استخدامها في c# ولم أفهم (hooking in c++) وأنا دائما أعتقد أن (c++ is the best control level) فبحث ووجدت دلة API وهي (messageboxindirect) وتجدون معلواتها هنا ووجدت مثالاً عنها في هذا الرابط ولكني لم أوفق والحمد لله في استخدام هذه الدلة حيث كانت تظهر انجليزية نرجو من عنده علم بالموضوع ان يوفر علينا ويريحنا

كانت الدالة ستريحنا ولكن يجب انجاز كلاس لعمل الرسائل سميته MessageBoxAr وجعلته ضمن فضاء الأسماء ArabicSubbort

وظائف الكلاس

  1. محاكاة messagebox التي يقدمها النظام
  2. اتاحة الفرصة بإستخدام اصوات الويندوز وايكونات الويندوز وكذلك استخدام أصوات وأيكونات مخصصة

سيكون الكلاس متاحا منذ لحظة تحميل البرنامج ولا يمكن عمل نسخة منه ولذلك سيكون static وبالتالي كل أعضائة static

مربع الرسالة (message box) عبارة عن نافذة انظر الصورة

post-63357-1173091579.jpg

ولكي نستخدم أصوات النظام التي يوجد مسارها في الرجستري نستعمل كلاس داخل الكلاس الأساسي سميناه SysSound ويقوم باستخراج مسارات بع الأصوات من الرجيستري ووضعها في متغيرات نصية عامة public static ليمكن استخدامها فيما بعد ولإن سألتني لماذا لا أستخدم System.Media.SystemSounds.Exclamation.Play(); أقول أني حاولت ولكني لم أسمع أي صوت ثم ان الكلاس يتيح أصوات أثر

وفي مشيد الكلاس الأساسي نحدد خصائص الاعضاء الخاصة بالكلاس

        static MessageBoxAr()
        {
            #region    Buttons and picurebox and label
            //ok button            
            Ok.TextAlign = ContentAlignment.MiddleCenter;
            Ok.AutoEllipsis = false;
            Ok.AutoSize = true;
            Ok.AutoSizeMode = AutoSizeMode.GrowOnly;
            Ok.Text = "موافق";
            Ok.DialogResult = DialogResult.OK;
            Ok.RightToLeft = RightToLeft.Inherit;
            Ok.Width += 15; Ok.Height += 5;
            //cancel button
            Cancel.TextAlign = ContentAlignment.MiddleCenter;
            Cancel.AutoEllipsis = false;
            Cancel.AutoSize = true;
            Cancel.AutoSizeMode = AutoSizeMode.GrowOnly;
            Cancel.Text = "إلغاء";
            Cancel.DialogResult = DialogResult.Cancel;
            Cancel.RightToLeft = RightToLeft.Inherit;
            Cancel.Width += 15; Cancel.Height += 5;
            //Yes button
            Yes.TextAlign = ContentAlignment.MiddleCenter;
            Yes.AutoEllipsis = false;
            Yes.AutoSize = true;
            Yes.AutoSizeMode = AutoSizeMode.GrowOnly;
            Yes.Text = "نعم";
            Yes.DialogResult = DialogResult.Yes;
            Yes.RightToLeft = RightToLeft.Inherit;
            Yes.Width += 15; Yes.Height += 5;
            //No button
            No.TextAlign = ContentAlignment.MiddleCenter;
            No.AutoEllipsis = false;
            No.AutoSize = true;
            No.AutoSizeMode = AutoSizeMode.GrowOnly;
            No.Text = "لا";
            No.DialogResult = DialogResult.No;
            No.RightToLeft = RightToLeft.Inherit;
            No.Width += 15; No.Height += 5;
            //Retry button
            Retry.TextAlign = ContentAlignment.MiddleCenter;
            Retry.AutoEllipsis = false;
            Retry.AutoSize = true;
            Retry.AutoSizeMode = AutoSizeMode.GrowOnly;
            Retry.Text = "إعادة";
            Retry.DialogResult = DialogResult.Retry;
            Retry.RightToLeft = RightToLeft.Inherit;
            Retry.Width += 15; Retry.Height += 5;
            //Ignore
            Ignore.TextAlign = ContentAlignment.MiddleCenter;
            Ignore.AutoEllipsis = false;
            Ignore.AutoSize = true;
            Ignore.AutoSizeMode = AutoSizeMode.GrowOnly;
            Ignore.Text = "تجاهل";
            Ignore.DialogResult = DialogResult.Ignore;
            Ignore.RightToLeft = RightToLeft.Inherit;
            Ignore.Width += 15; Ignore.Height += 5;
            //Abort
            Abort.TextAlign = ContentAlignment.MiddleCenter;
            Abort.AutoEllipsis = false;
            Abort.AutoSize = true;
            Abort.AutoSizeMode = AutoSizeMode.GrowOnly;
            Abort.Text = "أوقف";
            Abort.DialogResult = DialogResult.Abort;
            Abort.RightToLeft = RightToLeft.Inherit;
            Abort.Width += 15; Abort.Height += 5;
            //label
            message_text.AutoEllipsis = true;
            message_text.AutoSize = true;
            message_text.MaximumSize = new Size(473, 450);
            //picturebox
            icon_box.SizeMode = PictureBoxSizeMode.AutoSize;
            //checkbox
            Checkbox.AutoSize = true;
            Checkbox.Text = "عدم إظهار هذه الرسالة مرة أخري";
            Checkbox.RightToLeft = RightToLeft.Inherit;
            #endregion


            //خصائص النافذة
            message_box.Font = SystemFonts.MessageBoxFont;
            message_box.AutoSize = true;
            message_box.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            message_box.FormBorderStyle = FormBorderStyle.FixedDialog;
            message_box.MaximizeBox = false;
            message_box.MinimizeBox = false;
            message_box.ShowInTaskbar = false;
            message_box.RightToLeft = RightToLeft.Yes;
            message_box.RightToLeftLayout = true;

            message_box.Load += new EventHandler(message_box_Load);
            message_box.FormClosed += new FormClosedEventHandler(message_box_FormClosed);
            message_box.Shown += new EventHandler(message_box_Shown);

        }

ويتم استخدام بعض الخصائص مثل

UseCheckBox وهي لتحدد هل يتم عرض checkbox في الرسالة أم لا وعند عدم استعمالها تكون القيمة الإفتراضية خطأ

CheckBox_Result وهي تستخدم لتخزين القيمة العائدة من chechbox اذا استعمل

StartPosition وهي تستخدم لتعيين الموضع الذي تظهر به الرسالة وعند عدم استخدامها تكون القيمة الإفتراضية لها منتصف الشاشة

ParentWindow وهي تستخدم لتعيين النافذة الأب للرسالة

#region properties

        private static bool usecheckbox = false;
        /// <summary>
        /// هل تود اظهار مربع اختيار مع رسالة "عدم اظهار هذه الرسالة ثانية"ام لا<para>ستكون نتيجة هذا المربع في الخاصية</para><c>CheckBox_Result</c>
        /// </summary>
        public static bool UseCheckBox
        {
            get { return usecheckbox; }
            set { usecheckbox = value; }
        }
        private static CheckState checkbox_result = CheckState.Unchecked;
        /// <summary>
        /// Determines if checkbox is checked
        /// </summary>
        public static CheckState CheckBox_Result
        {
            get
            {
                if (UseCheckBox == true) return checkbox_result;
                else throw new Exception("لا يمكن أخذ القيمة لأنها تعتمد علي خاصية أخري وهي\nUseCheckBox");
            }
        }
        private static FormStartPosition startposition = FormStartPosition.CenterScreen;
        /// <summary>
        /// إختر موضع الرسالة عند ظهورها والوضع الإفتراضي هو<para>FormStartPosition.CenterScreen</para>
        /// </summary>
        public static FormStartPosition StartPosition
        {
            get { return startposition; }
            set { startposition = value; }
        }
        private static IWin32Window parentwindow;

        public static IWin32Window ParentWindow
        {
            set { parentwindow = value; }
        }
        #endregion

بقيت الدوال التي ستستخدم لعرض الرسالة وهي بإسم show و ShowCustom

أولا show

وهي تحاكي messagebox.show()

        public static DialogResult Show(string text)
        {
            return Show(text, "", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }
        public static DialogResult Show(string text, string caption)
        {
            return Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }
        public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
        {
            return Show(text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
        }
        public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            return Show(text, caption, buttons, icon, MessageBoxDefaultButton.Button1);
        }

وكلهم يستدعون الدالة الآتية

        public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultbutton)
        {
            string soundpath = "";// متغير نصي ليحمل مسار الصوت ويتم اسناد القيمة له كما يأتي
            Image imicon = null;//متغير يتم اسناد صورة معينة كما يأتي
            //التاكد من الرمز الصوري
            if (icon != MessageBoxIcon.None)//التأكد من استخدام أيكونة
            {
                switch (icon)
                {
                    case MessageBoxIcon.Asterisk:
                        imicon = SystemIcons.Asterisk.ToBitmap(); soundpath = SysSound.SystemAsterisk;
                        break;
                    case MessageBoxIcon.Error:
                        imicon = SystemIcons.Error.ToBitmap(); soundpath = SysSound.SystemHand;
                        break;
                    case MessageBoxIcon.Exclamation:
                        imicon = SystemIcons.Exclamation.ToBitmap(); soundpath = SysSound.SystemExclamation;
                        break;
                    /*case MessageBoxIcon.Hand:
                        icon_box.Image = SystemIcons.Hand.ToBitmap();soundpath=SysSound.SystemHand;
                        break;*/
                    /*case MessageBoxIcon.Information:
                        icon_box.Image = SystemIcons.Information.ToBitmap();soundpath=SysSound.SystemExclamation;
                        break;*/
                    case MessageBoxIcon.Question:
                        imicon = SystemIcons.Question.ToBitmap(); soundpath = SysSound.SystemQuestion;
                        break;
                    /*case MessageBoxIcon.Stop:
                        icon_box.Image = SystemIcons.Error.ToBitmap();soundpath=SysSound.SystemHand;
                        break;*/
                    /*case MessageBoxIcon.Warning:
                        icon_box.Image = SystemIcons.Warning.ToBitmap();soundpath=SysSound.SystemExclamation;
                        break;*/
                }
            }
            else { soundpath = SysSound.DefaultBeep; }//في حالة عدم وجود أيكونة
            //
            sh(text, caption, buttons, imicon, defaultbutton);//نستخدم هذه الدالة وسيأتي بيانها
            if (File.Exists(soundpath))//التأكد من مسار ملف الصوت
            {
                using (System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundpath))
                {
                    if (player.SoundLocation.ToLower().Contains("wav"))
                    {
                        player.Play();//تشغيل الصوت
                    }
                }
            }//you can replace previous if with try{}
            if (parentwindow == null)
            {
                return message_box.ShowDialog();
            }
            else { return message_box.ShowDialog(parentwindow); }

        }

الدالة sh

        private static void sh(string text, string caption, MessageBoxButtons buttons, Image icon, MessageBoxDefaultButton defaultbutton)
        {
            defbtn = defaultbutton;
            message_text.Text = string.Empty;//نزيل النص السابق ان كان موجود من اللابل
            message_text.Location = new Point(0, 0);
            int lbl_height_origin = message_text.Height;
            message_box.Controls.Clear();//ازالة كافة الأدوات من نافذة الرسالة
            message_box.MinimumSize = new Size(0, 0);
            message_box.Padding = new Padding();
            message_box.Text = caption;//عرض عنوان الرسالة
            int box_width_orogin=message_box.Width;                        
            icon_box.SizeMode = PictureBoxSizeMode.AutoSize;
            icon_box.MinimumSize = new Size(0, 0);
            icon_box.MaximumSize = new Size(0, 0);                        
            //نص الرسالة
            message_text.Text = text;
            if (icon != null)//في حالة استخداغم ايكونة
            {//استخدام مقاس ملائم
                if (icon.Width > 80 || icon.Height > 80)
                {
                    icon_box.SizeMode = PictureBoxSizeMode.Zoom;
                    icon_box.MaximumSize = new Size(80, 80);
                }
                else if (icon.Width < 30 || icon.Height < 30)
                {
                    icon_box.SizeMode = PictureBoxSizeMode.Zoom;
                    icon_box.MinimumSize = new Size(30, 30);
                }
                icon_box.Location = new Point(0, 0);
                if (buttons == MessageBoxButtons.OK&&(message_box.Width<=box_width_orogin)) { icon_box.Location = new Point(14, 0); }
                icon_box.Image = icon;
                message_box.Controls.Add(icon_box);
                message_box.Controls.Add(message_text);
                if (message_text.Height <= lbl_height_origin)
                {
                    message_text.Location = new Point(icon_box.Width + 15, icon_box.Height / 2 - 10);
                }
                else { message_text.Location = new Point(icon_box.Width + 15, 0);}
            }
            else { message_box.Controls.Add(message_text); message_text.Location = new Point(0, 0); }

            ushort y = getbtny();
            switch (buttons)
            {
                case MessageBoxButtons.AbortRetryIgnore:
                    btnnum = 3;
                    message_box.MinimumSize = new Size(Abort.Width + Retry.Width + Ignore.Width + 16, 0);
                    y = put3buttons(Abort, Retry, Ignore, y);
                    break;
                case MessageBoxButtons.OK:
                    btnnum = 1;
                    message_box.MinimumSize = new Size(Ok.Width, 0);
                    y = put1button(Ok, y);
                    break;
                case MessageBoxButtons.OKCancel:
                    btnnum = 2;
                    message_box.MinimumSize = new Size(Ok.Width + Cancel.Width + 8, 0);
                    y = put2buttons(Ok, Cancel, y);
                    break;
                case MessageBoxButtons.RetryCancel:
                    btnnum = 2;
                    message_box.MinimumSize = new Size(Retry.Width + Cancel.Width + 8, 0);
                    y = put2buttons(Retry, Cancel, y);
                    break;
                case MessageBoxButtons.YesNo:
                    btnnum = 2;
                    message_box.MinimumSize = new Size(Yes.Width + No.Width + 8, 0);
                    y = put2buttons(Yes, No, y);
                    break;
                case MessageBoxButtons.YesNoCancel:
                    btnnum = 3;
                    message_box.MinimumSize = new Size(Yes.Width + No.Width + Cancel.Width + 16, 0);
                    y = put3buttons(Yes, No, Cancel, y);
                    break;
            }
            if (usecheckbox == true)
            {
                putcheckbox(Checkbox, y);
            }
            if (message_box.Width > box_width_orogin)
            {
                message_box.Padding = new Padding(14, 16, 12, 12);
            }
            else 
            {
                message_box.Padding = new Padding(0, 16, 12, 12);
                //message_box.Width += 10;
            }
            message_box.StartPosition = startposition;

        }

لاحظنا استخدام الدوال الآتية

        private static ushort put3buttons(Button btn1, Button btn2, Button btn3, ushort y)//اضافة ثلاثة ازرار بمعلومية موقعهم الرأسي
        {
            btn2.Location = new Point((message_box.DisplayRectangle.Width - btn2.Width) / 2, y);
            btn1.Location = new Point(btn2.Left - 8 - btn1.Width, y);
            btn3.Location = new Point(btn2.Right + 8, y);
            message_box.Controls.AddRange(new Button[] { btn1, btn2, btn3 });            
            return (ushort)(btn1.Bottom + 10);
        }
        private static ushort put2buttons(Button btn1, Button btn2, ushort y)//اضافة زرين بمعلومية موقعهم الرأسي
        {
            btn1.Location = new Point(message_box.DisplayRectangle.Width / 2 - 4 - btn1.Width, y);
            btn2.Location = new Point(btn1.Right + 8, y);
            message_box.Controls.AddRange(new Button[] { btn1, btn2 });            
            return (ushort)(btn1.Bottom + 10);
        }
        private static ushort put1button(Button btn, ushort y)//اضافة زر واحد بمعلومية موقعه الرأسي
        {
            btn.Location = new Point((message_box.DisplayRectangle.Width - btn.Width) / 2, y);
            message_box.Controls.Add(btn);
            return (ushort)(btn.Bottom + 10);
        }
        private static void putcheckbox(CheckBox chkbx, ushort y)اضافة تشيك بوكس  بمعلومية موقعه الرأسي
        {
            chkbx.Location = new Point(0, y);
            message_box.Controls.Add(chkbx);
        }

تانيا ShowCustom

وهي تستخدم الدالة sh أيضا ولكن تسمح بتخصيص أيكونة سواء مسار او ايمج وصوت سواء مسار أو استريم

ليصبح شكل الكلاس في النهاية كذلك

post-63357-1173097031.jpg

ويوجد في المرفقات مثال علي استخدام الكلاس

وهذه بعض الصور

post-63357-1173097910.jpg

post-63357-1173098167.jpg

post-63357-1173099038.jpg

post-63357-1173099141.jpg

وفي النهاية آسف علي عدم النظام

post-63357-1173091579.jpg

messageboxArabic.zip

Electrical communications and electronics engineer

C++ Developer

 


stackoverflow profile : http://stackoverflow.com/users/249120/ahmed-safan


 


Just Keep Moving On , never stop until you are dead


#2

السلام عليكم

عمل جيد وكل ما أسطيع إضافته هنا هو أن أدلك على هذا الربط حيث أضاف صاحبه اللغة العربية لحاسوب الكف وهو ما ييسر لك قليلا العمل على ما أضن وللأسف الشديد أنه لم يضع الكود كاملا

0xfeac in c <=> \ufeac

#3

جزاك الله خيراً علي الرد أخي

ولكن الموضوع الذي أشرت اليه ليس مشابها لموضوعنا حيث ان الكاتب يقول أن windows CE لا يدعم العربية أصلا

أما الويندوز بتاعنا بيدعم العربي وتمام ولكن مربعات الحوار ومربعات الرسائل التي يقدمها النظام تقدم بصورة جاهزة ولغتها هي لغة النظام وفي الرابط الأول الذي ذكرته في الشرح رابط

قام الكاتب بالتعديل علي هذه المربعات باستخدام السي دوبل بلس و hooking ويمكن عمل hooking بالسي شارب ولكن بدوال API وانا غير متمرس الا مع القليل منها ولذلك في هذا الموضوع قمت بعمل نموذج بسيط وتنسيقة لكي يبدو مشابه ذلك الذي في الويندوز

Electrical communications and electronics engineer

C++ Developer

 


stackoverflow profile : http://stackoverflow.com/users/249120/ahmed-safan


 


Just Keep Moving On , never stop until you are dead


هذا الموضوع مغلق.

مواضيع مشابهة