.NET Controls Pemrograman Visual (TH22012 ) by Kartika Firdausy 081.328.718.768 kartikaf@indosat.net.id kartika@ee.uad.ac.id blog.uad.ac.id/kartikaf kartikaf.wordpress.com Control Creation A Windows control is a graphical object that allows the user to interact with the computer. The controls are as varied as the needs and goals are. Because there are so many controls for various purposes, their insertion to an application and their configuration are left to the application programmer. The Toolbox is the accessory that provides most of the controls used in an application.
Control Creation By default, the Toolbox is positioned on the left side of the IDE. To change that position, you can drag its title bar away and dock it to another side of the IDE. The Toolbox also uses a default width to show the items on it. If the width is too small or too large for you, you can change it. To do this, position the mouse to its right border and drag left or right. The Sections of the Toolbox When you start a Windows Forms Application, it provides various controls on the Toolbox so you can choose which ones are appropriate for your particular application. Controls can be set by categories based on their function or role. A container is a control whose main purpose is to host other controls. To design it, you pick up objects from the Toolbox and drop them where desired. The Toolbox organizes its items in categories and each category is represented by a button:
The Sections of the Toolbox If the available list of categories is not enough, you can add a new section of your choice. By default, Visual Studio.NET hides some categories because they are judged hardly used. To display these additional sections, you can right-click anywhere in the Toolbox and click Show All Tabs: The Layout of a Category To use an object of a particular category, you can first click its button. After selecting a category, it displays its items. In each category, a particular button called Pointer is selected by default. This simply indicates that no item in the group is currently selected. By default, the items in each category are organized as horizontal wide buttons:
The Layout of a Category Alternatively, you can list the items of a category as buttons of a list view. To do that, you can right-click anywhere in the category and click List View to remove its check box: List Box A list box is a control that maintains a list of objects in a rectangular box. To use the list box, the user clicks one of its items. Depending on the list box, when an item is clicks, it becomes highlighted, indicating that it is selected. There are two types of selection list boxes: one type allows the user to select only one item, another type would allow the user to select more than one item.
List Box To create a list box in MS.Net application, you can use the ListBox class. Creating a list box might not be the most difficult thing to do but when the user has performed a different selection, you will usually need to know what item(s) the user selected. A list box maintains its list of items by their text or their indexes. You can use the same ability to retrieve either the text or the index of the item(s) that was (were) selected. Combo Box A combo box is a control that maintains a list of objects but displays one at a time to the user. A regular combo box is equipped with a rectangular text area and a down-pointing arrow. To use the combo box, the user clicks the arrow, which displays its list of items. Then the user clicks one item from the list and the list retracts like a plastic. The item the user would have selected would display in the text box side of the control. To perform a different selection, the user uses the same process.
Combo Box To create a combo box in MS.Net application, you can use the ComboBox class. Creating a combo box might not be the most difficult thing to do but when the user has performed a different selection, you will usually need to know what item the user selected. A combo box maintains its list of items by their text or their indexes. You can use the same ability to retrieve either the text or the index of the item that was selected. Example ListBox ComboBox
Mengisi List Box Pada window Properties pilih komponen listboxsemesterganjil, klik dobel pada isian properti Items (atau klik pada tombol... di belakang nilai properti itu). Akan muncul jendela String Collection Editor this->listboxsemesterganjil->items->addrange(gcnew cli::array< System::Object^ >(6) {L"Bahasa Pemrograman", L"Pemrograman Berbasis Web", L"Robotika", L"Sistem Basis Data", L"Teknik Pengolahan Citra", L"Teknik Kendali"}); Mengisi Combo Box Pada window Properties pilih komponen comboboxsemestergenap, klik dobel pada isian properti Items (atau klik pada tombol... di belakang nilai properti itu). Akan muncul jendela String Collection Editor, isikan: Kecerdasan Buatan Mikroprosesor Sekuriti Teknologi Informasi Sistem Kendali Lanjut Sistem Operasi this->comboboxsemestergenap->items->addrange(gcnew cli::array< System::Object^ >(5) {L"Kecerdasan Buatan", L"Mikroprosesor", L"Sekuriti Teknologi Informasi", L"Sistem Kendali Lanjut", L"Sistem Operasi"});
Event handler private: System::Void buttonpilih_click(system::object^ sender, System::EventArgs^ e) { if ((listboxsemesterganjil->selectedindex == -1) (comboboxsemestergenap->text->equals(""))) { MessageBox::Show("Pilih dulu mata kuliahnya"); } else { MessageBox::Show("Anda memilih\n Semester Ganjil: "+ listboxsemesterganjil->items[listboxsemesterganjil->selectedindex] + "\n Semester Genap: "+ comboboxsemestergenap->text); } } Contoh hasil eksekusi
Tugas