tgoop.com/CsharpWindowsForm/270
Last Update:
قد يقول البعض ان هذه الطريقة لاتنفع الا للادوات التي تحوي على قيم في خاصية text يعني يوجد لديهن نص كلامك صحيح ولاكن يوجد طريقة أخرى سوف نشرحها في نهاية الموضوع وهي عنطريق استخدام الخاصية AccessibleName
دالة الحدث FileClicked
DialogResult result;
private void FileClicked(object sender,EventArgs e)
{
MenuItem menu = (MenuItem)sender;
switch (menu.Text)
{
case "Save":
sfd.DefaultExt = "*.txt";
sfd.Filter = "text file (*.txt)|*.txt";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
sfd.FileName.Length > 0)
{
rch.SaveFile(sfd.FileName, RichTextBoxStreamType.PlainText);
}
break;
case "Open":
if (rch.Modified)
result = MessageBox.Show("Do you want to continue without saving the current file?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
{
return;
}
else
{
ofd.DefaultExt = "text file |*.txt|Rich Text Files|*.rtf";
ofd.ShowDialog();
if (ofd.FileName == "")
{
return;
}
string strExt;
strExt = System.IO.Path.GetExtension(ofd.FileName);
strExt = strExt.ToUpper();
if (strExt == ".RTF")
{
rch.LoadFile(ofd.FileName, RichTextBoxStreamType.RichText);
}
else
{
System.IO.StreamReader txtReader;
txtReader = new System.IO.StreamReader(ofd.FileName);
rch.Text = txtReader.ReadToEnd();
txtReader.Close();
txtReader = null;
}
}
break;
default:
break;
}
}
شرح لبعض الخصائص الجديدة التابعة لاداة RichTextBox
الخاصية Modified
تشير إلى أن عنصر تحكم RichTextBox هل قد تم تعديله من قبل المستخدم منذ إنشاء عنصر التحكم أو تم تعيين محتوياته آخر مرة.
الدالة الأخيرة FormatClicked الخاصة بتنسيق النص
private void FormatClicked(Object Sender, EventArgs e)
{
MenuItem mniTemp = (MenuItem)Sender;
switch (mniTemp.Text)
{
case "Font":
fd.ShowColor = true;
fd.Font = this.Font;
if (fd.ShowDialog() == DialogResult.OK)
{
rch.Font = fd.Font;
rch.ForeColor = fd.Color;
this.ForeColor = fd.Color;
}
break;
}
}
ملاحظة:
عند تحميل ملف باستخدام الدالة LoadFile ، تستبدل محتويات الملف الجاري تحميله محتويات اداة التحكم RichTextBox بالكامل. سيؤدي ذلك إلى تغيير قيم خصائص النص و Rtf.
الان نشرح استخدام خاصية AccessibleName
الترجمة الحرفية لهذه الخاصية تعني اسم الوصول
هذه الخاصية تمتلكها جميع أدوات التحكم التي تظهر في الفورم
وظيفتها تشبه الى حد ما الخاصية text ولاكن الاختلاف الوحيد هو ان خاصية اسم الوصول لاتظهر على الأداة وتستخدم كمعرف للوصول الى الأداة
BY برمجة تطبيقات الويندوز C# Programming
Share with your friend now:
tgoop.com/CsharpWindowsForm/270