Basic Components Devi, Erick, Hendrawan, Reddy © Sekolah Tinggi Teknik Surabaya 1
» Important entities: ˃Properties: define component’s behavior ˃Events » Event-Driven Programming ˃Source code is executed when an event is triggered ˃Every component has event slots that can be coded ˃ Example: click event on Button. » Every components has (name) to identify components’ ID. 2 © Sekolah Tinggi Teknik Surabaya
3
» Text: Form title » Maximize Box » Minimize Box » FormBorderStyle ˃None ˃FixedSingle ˃Fixed3D ˃FixedDialog ˃Sizeable (Default) ˃FixedToolWindow ˃SizableToolWindow 4 © Sekolah Tinggi Teknik Surabaya
» WindowState ˃Normal (Default) ˃Minimized ˃Maximized » StartPosition ˃Manual ˃CenterScreen ˃WindowsDefaultLocation ˃WindowsDefaultBounds ˃CenterParent 5 © Sekolah Tinggi Teknik Surabaya
» Load: Occurs whenever the user loads the form » FormClosed: Occurs whenever the form is closed 6 © Sekolah Tinggi Teknik Surabaya
7
» Text: Content within TextBox » TextAlign ˃Left ˃Right ˃Center » PasswordChar: Determine what character should be shown as character replacement » MaxLength 8 © Sekolah Tinggi Teknik Surabaya
» TextChanged: Occurs whenever text property is changed 9 © Sekolah Tinggi Teknik Surabaya
10 © Sekolah Tinggi Teknik Surabaya
» Text: Button Caption ˃Add ampersand (&) in front of a character to make it a mnemonic key for that button » TextAlign 11 © Sekolah Tinggi Teknik Surabaya TopLeftTopCenterTopRight MiddleLeftMiddleCenterMiddleRight BottomLeftBottomCenterBottomRight
» Click 12 © Sekolah Tinggi Teknik Surabaya
13 © Sekolah Tinggi Teknik Surabaya
» Text » TextAlign (refer to Button TextAlign) » AutoSize: determine whether its size should automatically resize to text 14 © Sekolah Tinggi Teknik Surabaya
» Click » TextChanged 15 © Sekolah Tinggi Teknik Surabaya
16 © Sekolah Tinggi Teknik Surabaya
» Text » Checked 17 © Sekolah Tinggi Teknik Surabaya
» CheckedChanged 18 © Sekolah Tinggi Teknik Surabaya
19 © Sekolah Tinggi Teknik Surabaya
» Text » Checked 20 © Sekolah Tinggi Teknik Surabaya
» CheckedChanged 21 © Sekolah Tinggi Teknik Surabaya
22 © Sekolah Tinggi Teknik Surabaya
» Items: collection of objects to be displayed » MultiColumn: one column only or not » Sorted: whether objects in it should be sorted naturally in ascending manner » SelectionMode ˃None ˃Single ˃MultiSimple (on click basis) ˃MultiExtended (on drag basis) 23 © Sekolah Tinggi Teknik Surabaya
» SelectedIndexChanged 24 © Sekolah Tinggi Teknik Surabaya
» listBox1.Items.Clear(); ˃Clear Items » listBox1.Items.Add("string"); ˃Add an item to Items » listBox1.Items.RemoveAt(2); ˃Remove an item from Items » int x = listBox1.SelectedIndex; ˃Retrieve selected item index » string x = listBox1.SelectedItem.ToString(); ˃Retrieve selected item string 25 © Sekolah Tinggi Teknik Surabaya
» For multi selection: foreach (int i in listBox1.SelectedIndices) { MessageBox.Show(i.ToString()); } foreach (string i in listBox1.SelectedItems) { MessageBox.Show(i); } 26 © Sekolah Tinggi Teknik Surabaya
27 © Sekolah Tinggi Teknik Surabaya
» Items » MaxLength » DropDownStyle ˃Simple ˃DropDown (Default) ˃DropDownList » Sorted » Text: String displayed if DropDownStyle is not DropDownList 28 © Sekolah Tinggi Teknik Surabaya
» SelectionIndexChanged » SelectionChangeCommitted: Occurs whenever the item is truly chosen 29 © Sekolah Tinggi Teknik Surabaya
» comboBox1.Items.Clear(); ˃Clear Items » comboBox1.Items.Add("string"); ˃Add an item to Items » comboBox1.Items.RemoveAt(2); ˃Remove an item from Items » int x = comboBox1.SelectedIndex; ˃Retrieve selected item index » string x = comboBox1.SelectedItem.ToString(); ˃Retrieve selected item string 30 © Sekolah Tinggi Teknik Surabaya
31 © Sekolah Tinggi Teknik Surabaya
32 © Sekolah Tinggi Teknik Surabaya
33 © Sekolah Tinggi Teknik Surabaya
34 © Sekolah Tinggi Teknik Surabaya
35 © Sekolah Tinggi Teknik Surabaya
36 © Sekolah Tinggi Teknik Surabaya
37 © Sekolah Tinggi Teknik Surabaya
» Add additional functions for previous example ˃Update selected data ˃Delete selected data. Provide a confirmation dialog before deletion. 38 © Sekolah Tinggi Teknik Surabaya