إضافة Cell ضوابط في أوراق العمل
مقدمة
حاليًا ، يدعم Aspose.Cells.GridDesktop إضافة ثلاثة أنواع من عناصر التحكم في الخلية ، والتي تشمل ما يلي:
- زر
- خانة الاختيار
- صندوق التحرير
كل هذه الضوابط مشتقة من فئة مجردة ،CellControlتحتوي كل ورقة عمل على مجموعة منضوابط. يمكن إضافة عناصر تحكم خلية جديدة ويمكن الوصول إلى العناصر الموجودة باستخدام هذاضوابطجمع بسهولة.
**الأهمية:**إذا كنت ترغب في إضافة عناصر تحكم الخلية إلى جميع خلايا العمود بدلاً من إضافة واحدة تلو الأخرى ، فيمكنك الرجوع إليهاإدارة Cell عناصر التحكم في الأعمدة.
إضافة زر
لإضافة زر إلى ورقة العمل باستخدام Aspose.Cells.GridDesktop ، يرجى اتباع الخطوات التالية:
- أضف Aspose.Cells.GridDesktop control إلى ملفاستمارة
- الوصول إلى أي ملفاتورقة عمل
- يضيفزرالىضوابطجمعورقة عمل
أثناء الإضافةزر، يمكننا تحديد موقع الخلية (مكان عرضها) والعرض والارتفاع وتعليق الزر.
التعامل مع حدث الزر
لقد ناقشنا حول الإضافةزرالسيطرة علىورقة عملولكن ما هي ميزة وجود زر فقط في ورقة العمل إذا لم نتمكن من استخدامه. لذلك ، هنا تأتي الحاجة إلى معالجة الحدث للزر.
للتعامل معانقرحدثزرالتحكم ، Aspose.Cells.GridDesktopCellButtonClickالحدث الذي يجب على المطورين تنفيذه حسب احتياجاتهم. على سبيل المثال ، لقد عرضنا للتو رسالة عند النقر فوق الزر كما هو موضح أدناه:
تحديد صورة خلفية لعنصر التحكم في الزر
يمكننا تعيين صورة / صورة خلفية للتحكم في الزر مع التسمية / النص الخاص به كما هو موضح في الكود أدناه:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Set the image. | |
Image image = Image.FromFile(dataDir + @"AsposeLogo.jpg"); | |
button.Image = image; |
الأهمية:تحتوي جميع أحداث عناصر التحكم في الخلية على ملفCellControlEventArgsالوسيطة التي توفر أرقام الصفوف والأعمدة للخلية التي تحتوي على عنصر تحكم الخلية (الذي يتم تشغيل الحدث الخاص به).
إضافة CheckBox
لإضافة خانة اختيار إلى ورقة العمل باستخدام Aspose.Cells.GridDesktop ، يرجى اتباع الخطوات التالية:
- أضف Aspose.Cells.GridDesktop control إلى ملفاستمارة
- الوصول إلى أي ملفاتورقة عمل
- يضيفخانة الاختيارالىضوابطجمعورقة عمل
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Accessing the location of the cell that is currently in focus | |
CellLocation cl = sheet.GetFocusedCellLocation(); | |
// Adding checkbox to the Controls collection of the Worksheet | |
sheet.Controls.AddCheckBox(cl.Row, cl.Column, true); |
أثناء الإضافةخانة الاختيار، يمكننا تحديد موقع الخلية (مكان عرضها) وحالة مربع الاختيار.
معالجة حدث CheckBox
Aspose.Cells.GridDesktop يوفرCellCheckedChangedالحدث الذي يتم تشغيله عندماالتحققتم تغيير حالة مربع الاختيار. يمكن للمطورين التعامل مع هذا الحدث وفقًا لمتطلباتهم. على سبيل المثال ، لقد عرضنا للتو رسالة لإظهار ملفالتحققحالة خانة الاختيار في الكود أدناه:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Implenting CellCheckedChanged event handler | |
private void gridDesktop1_CellCheckedChanged(object sender, CellControlEventArgs e) | |
{ | |
// Getting the reference of the CheckBox control whose event is triggered | |
Aspose.Cells.GridDesktop.CheckBox check = (Aspose.Cells.GridDesktop.CheckBox)gridDesktop1.GetActiveWorksheet().Controls[e.Row, e.Column]; | |
// Displaying the message when the Checked state of CheckBox is changed | |
MessageBox.Show("Current state of CheckBox is " + check.Checked); | |
} |
مضيفا ComboBox
لإضافة مربع تحرير وسرد إلى ورقة العمل باستخدام Aspose.Cells.GridDesktop ، يرجى اتباع الخطوات التالية:
- أضف Aspose.Cells.GridDesktop control إلى ملفاستمارة
- الوصول إلى أي ملفاتورقة عمل
- قم بإنشاء مصفوفة من العناصر (أو القيم) التي ستتم إضافتها إليهاصندوق التحرير
- يضيفصندوق التحريرالىضوابطجمعورقة عملمن خلال تحديد موقع الخلية (حيث سيتم عرض مربع التحرير والسرد) والعناصر / القيم التي سيتم عرضها عند النقر فوق مربع التحرير والسرد
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Accessing the location of the cell that is currently in focus | |
CellLocation cl = sheet.GetFocusedCellLocation(); | |
// Creating an array of items or values that will be added to combobox | |
string[] items = new string[3]; | |
items[0] = "Aspose"; | |
items[1] = "Aspose.Grid"; | |
items[2] = "Aspose.Grid.Desktop"; | |
// Adding combobox to the Controls collection of the Worksheet | |
sheet.Controls.AddComboBox(cl.Row, cl.Column, items); |
التعامل مع حدث ComboBox
Aspose.Cells.GridDesktop يوفرCellSelectedIndexChangedالحدث الذي يتم تشغيله عندماالفهرس المختارمن combobox تغيرت. يمكن للمطورين التعامل مع هذا الحدث وفقًا لرغباتهم. على سبيل المثال ، لقد عرضنا للتو رسالة لإظهار ملفالعنصر المحددمن التحرير والسرد:
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Implenting CellSelectedIndexChanged event handler | |
private void gridDesktop1_CellSelectedIndexChanged(object sender, CellComboBoxEventArgs e) | |
{ | |
// Getting the reference of the ComboBox control whose event is triggered | |
Aspose.Cells.GridDesktop.ComboBox combo = | |
(Aspose.Cells.GridDesktop.ComboBox)gridDesktop1.GetActiveWorksheet().Controls[e.Row, e.Column]; | |
// Displaying the message when the Selected Index of ComboBox is changed | |
MessageBox.Show(combo.Items[combo.SelectedIndex].ToString()); | |
} |