Çalışma Sayfalarında Hücre Denetimleri Eklemek

Giriş

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

  • Düğme
  • Onay Kutusu
  • Kombo Kutusu

Tüm bu denetimler, HücreDenetim soyut sınıfından türetilmiştir. Her çalışma sayfası, Denetimler adlı bir koleksiyon içerir. Yeni hücre denetimleri eklenip mevcut olanlara bu Denetimler koleksiyonunu kullanarak kolayca erişilebilir.

ÖNEMLİ: Bir sütunun tüm hücrelerine tek tek eklemek yerine yönetmeniz gerekiyorsa Sütunlarda Hücre Denetimlerini Yönetme. bağlantısına bakabilirsiniz.

Düğme Ekleme

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

Form‘unuza Aspose.Cells.GridDesktop denetimini ekleyin

  • Herhangi bir istenen Elektronik Tablo‘na erişin
  • Denetimler koleksiyonuna Düğme ekleyin
// 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");

Düğme eklerken, hücrenin konumunu (nerede görüntüleneceği), genişliği ve yüksekliği ve düğmenin açıklamasını belirleyebiliriz.

Düğmenin Olaylarını Ele Alma

Düğme denetimini Çalışma Sayfası‘na eklemeyi tartıştık ancak sadece bir düğmeye sahip olmanın avantajı nedir, eğer kullanamıyorsak. İşte burada, düğmenin olaylarını ele almanın gerekliliği ortaya çıkar.

Düğme denetiminin Tıklama olayını ele almak için, Aspose.Cells.GridDesktop, CellButtonClick olayını geliştiricilere ihtiyaçlarına göre uygulamaları için sağlar. Örneğin, aşağıdaki gibi düğmeye tıklandığında bir mesajı sadece 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 İçin Arka Plan Resmi Belirtme

Düğme denetiminin arkaplan resmini resmini/ görüntüsünü aşağıdaki kodda gösterildiği şekilde etiket/metin ile birlikte belirleyebiliriz:

// 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 denetimlerinin tüm olayları, tetiklenen hücre denetimini içeren CellControlEventArgs argümanını içerir (veya sağlar);

CheckBox Ekleme

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

Form‘unuza Aspose.Cells.GridDesktop denetimini ekleyin

  • Herhangi bir istenen Elektronik Tablo‘na erişin - CheckBox‘ı Elektronik Tablo‘nun Denetimler koleksiyonuna ekleyin
// 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 eklerken, kutunun konumunu (nerede görüntüleneceğini) ve onay kutusunun durumunu belirtebiliriz.

CheckBox Olay İşleme

Aspose.Cells.GridDesktop, onay kutusunun İşaretlendiği durumun değiştiğinde tetiklenen CellCheckedChanged olayını sağlar. Geliştiriciler bu olaya kendi gereksinimlerine göre işleyebilir. Örneğin, aşağıdaki kodda onay kutusunun İşaretlendi durumunu göstermek için sadece bir iletiyi gösterdik:

// 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 elektronik tabloya bir açılır kutu eklemek için lütfen aşağıdaki adımları izleyin:

Form‘unuza Aspose.Cells.GridDesktop denetimini ekleyin

  • Herhangi bir istenen Elektronik Tablo‘na erişin - ComboBox‘ın tıklanacağında görüntülenecek hücrenin konumunu (açılır kutunun görüntüleneceği konum) ve öğeler/değerler dizisini oluşturun - ComboBox‘ı Elektronik Tablo‘nun Denetimler koleksiyonuna konumunu (açılır kutunun görüntüleneceği hücrenin konumu) ve combobox tıklanıldığında görüntülenecek öğeler/değerler dizisini belirterek ekleyin
// 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, açılır kutunun Seçilen İndeksi değiştiğinde tetiklenen CellSelectedIndexChanged olayını sağlar. Geliştiriciler bu olayı isteklerine göre işleyebilirler. Örneğin, aşağıdaki kodda sadece açılır kutunun Seçili Öğe sini göstermek için bir iletiyi gösterdik:

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