قم بإنشاء أزرار أوامر مخصصة

إنشاء أزرار أوامر مخصصة

لإنشاء زر أمر مخصص في Aspose.Cells.GridWeb:

  1. أضف Aspose.Cells.GridWeb control إلى نموذج الويب.
  2. قم بالوصول إلى ورقة العمل.
  3. قم بإنشاء مثيل لفئة CustomCommandButton.
  4. قم بتعيين أمر الزر إلى بعض القيمة. يتم استخدام هذه القيمة في معالج حدث الزر.
  5. اضبط نص الزر.
  6. قم بتعيين عنوان URL لصورة الزر.
  7. أخيرًا ، قم بإضافة كائن CustomCommandButton إلى مجموعة CustomCommandButtons لعنصر التحكم GridWeb.

يتم عرض إخراج مقتطف الشفرة أدناه:

تمت إضافة زر أمر مخصص إلى عنصر تحكم GridWeb

ما يجب القيام به: image_بديل_نص

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Instantiating a CustomCommandButton object
CustomCommandButton button = new CustomCommandButton();
// Setting the command, text and image URL for button. Image should be relative to website root folder
button.Command = "MyButton";
button.Text = "MyButton";
button.ImageUrl = "../Image/aspose.ico";
// Adding button to CustomCommandButtons collection of GridWeb
GridWeb1.CustomCommandButtons.Add(button);

معالجة الحدث لزر الأمر المخصص

أهم جانب من جوانب أزرار الأوامر المخصصة هو الإجراء الذي يقومون به عند النقر فوقها. لتعيين الإجراء ، قم بإنشاء معالج حدث للحدث CustomCommand الخاص بعنصر التحكم GridWeb.

يتم تشغيل الحدث CustomCommand دائمًا عند النقر فوق زر أمر مخصص. لذلك يجب على معالج الحدث تحديد زر الأمر المخصص المحدد الذي ينطبق عليه بواسطة مجموعة الأوامر عند إضافة الزر إلى عنصر التحكم GridWeb. أخيرًا ، أضف التعليمات البرمجية المخصصة التي يتم تنفيذها عند النقر فوق الزر.

في مثال الرمز أدناه ، تتم إضافة رسالة نصية إلى الخلية A1 عند النقر فوق الزر.

تمت إضافة النص إلى خلية A1 عند النقر فوق زر الأمر المخصص

ما يجب القيام به: image_بديل_نص

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Creating Event Handler for CustomCommand event
protected void GridWeb1_CustomCommand(object sender, string command)
{
// Identifying a specific button by checking its command
if (command.Equals("MyButton"))
{
// Accessing the cells collection of the worksheet that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Putting value to "A1" cell
sheet.Cells["A1"].PutValue("My Custom Command Button is Clicked.");
// Set first column width to make the text visible
sheet.Cells.SetColumnWidth(0, 30);
}
}