Çalışma Sayfalarına Cell Kontrolleri Ekleme

Giriş

Şu anda Aspose.Cells.GridDesktop, aşağıdakileri içeren üç tür hücre denetimi eklemeyi destekler:

  • Buton
  • Onay Kutusu
  • Açılan kutu

Bu kontrollerin tümü soyut bir sınıftan türetilmiştir,Hücre KontrolüHer çalışma sayfası bir koleksiyon içerirKontroller. Bu kullanılarak yeni hücre kontrolleri eklenebilir ve mevcut olanlara erişilebilir.Kontrollerkolayca toplayın.

**ÖNEMLİ:**Tek tek eklemek yerine bir sütunun tüm hücrelerine hücre kontrolleri eklemek istiyorsanız, o zaman başvurabilirsiniz.Cell Kontrollerini Sütunlarda Yönetme.

Ekleme Düğmesi

Aspose.Cells.GridDesktop kullanarak çalışma sayfasına düğme eklemek için lütfen aşağıdaki adımları izleyin:

  • Aspose.Cells.GridDesktop kontrolünü ekleyin.Biçim
  • İstediğiniz herhangi birine erişinÇalışma kağıdı
  • EklemekButoniçinKontrollerkoleksiyonuÇalışma kağıdı
// 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 button to the Controls collection of the Worksheet
Aspose.Cells.GridDesktop.Button button = sheet.Controls.AddButton(cl.Row, cl.Column, 80, 20, "Button");

eklerkenButon, hücrenin konumunu (nerede görüntüleneceğini), genişliğini ve yüksekliğini ve düğmenin başlığını belirtebiliriz.

Düğmenin Olay İşleme

ekleme hakkında konuştukButonkontrol etmekÇalışma kağıdıancak kullanamıyorsak, çalışma sayfasında bir düğme olmasının avantajı nedir? Bu nedenle, düğmenin olay işleme ihtiyacı burada ortaya çıkıyor.

işlemek içinTıklamakolayıButonkontrol, Aspose.Cells.GridDesktop sağlarHücreDüğmesiTıklamageliştiriciler tarafından ihtiyaçlarına göre uygulanması gereken olay. Örneğin, aşağıda gösterildiği gibi, düğmeye tıklandığında bir mesaj görüntüledik:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Implenting CellButtonClick event handler
private void gridDesktop1_CellButtonClick(object sender, CellControlEventArgs e)
{
// Displaying the message when button is clicked
MessageBox.Show("Button is clicked.");
}

Düğme Denetimi için Arka Plan Görüntüsü Belirtme

Aşağıdaki kodda gösterildiği gibi etiketi/metni ile düğme kontrolü için arka plan resmini/resmini ayarlayabiliriz:

// 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;

ÖNEMLİ:Hücre kontrollerinin tüm olayları birCellControlEventArgshücre kontrolünü içeren (olayı tetiklenen) hücrenin satır ve sütun numaralarını sağlayan bağımsız değişken.

Onay Kutusu Ekleme

Aspose.Cells.GridDesktop kullanarak çalışma sayfasına bir onay kutusu eklemek için lütfen aşağıdaki adımları izleyin:

  • Aspose.Cells.GridDesktop kontrolünü ekleyin.Biçim
  • İstediğiniz herhangi birine erişinÇalışma kağıdı
  • EklemekOnay KutusuiçinKontrollerkoleksiyonuÇalışma kağıdı
// 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);

eklerkenOnay Kutusu, hücrenin konumunu (nerede görüntüleneceğini) ve onay kutusunun durumunu belirtebiliriz.

CheckBox Olay İşleme

Aspose.Cells.GridDesktop sağlarHücre Kontrol EdildiDeğiştirildiolduğunda tetiklenen olayKontrolonay kutusunun durumu değiştirilir. Geliştiriciler bu olayı gereksinimlerine göre işleyebilir. Örneğin, göstermek için az önce bir mesaj görüntüledik.Kontrolaşağıdaki koddaki onay kutusunun durumu:

// 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 ekleme

Aspose.Cells.GridDesktop kullanarak çalışma sayfasına açılan kutu eklemek için lütfen aşağıdaki adımları izleyin:

  • Aspose.Cells.GridDesktop kontrolünü ekleyin.Biçim
  • İstediğiniz herhangi birine erişinÇalışma kağıdı
  • Eklenecek bir dizi öğe (veya değer) oluşturunAçılan kutu
  • EklemekAçılan kutuiçinKontrollerkoleksiyonuÇalışma kağıdıhücrenin konumunu (birleşik kutunun görüntüleneceği yer) ve açılan kutu tıklandığında görüntülenecek öğeleri/değerleri belirterek
// 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 Olay İşleme

Aspose.Cells.GridDesktop sağlarCellSelectedIndexChangedolduğunda tetiklenen olaySeçilmiş Dizinaçılan kutunun şekli değişti. Geliştiriciler bu olayı kendi isteklerine göre halledebilirler. Örneğin, göstermek için az önce bir mesaj görüntüledik.Seçilen öğeaçılan kutunun:

// 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());
}