Theory
Till ને control by control design કરો
તમારી જાતને મહેતા સ્ટોર્સના counter પર મૂકો અને billing screen ને શું જોઈએ છે તેની યાદી બનાવો:
એક title (ફક્ત display થાય), item name type કરવા માટે એક box, ફક્ત digits માં typed થતી quantity, Cash/Card/UPI માંથી પસંદ કરેલો ફક્ત એક payment mode, ઉપરથી કદાચ ઉમેરાતી carry-bag, bill ની date, એક Add button અને day report બને ત્યાં સુધી એક progress bar.
એ યાદીની દરેક જરૂરિયાત બરાબર એક Toolbox control સાથે map થાય છે. આ પાઠ એ map છે, અને એક જ pattern આ 17 ને શીખવા લાયક બનાવી દે છે.
Formula
3-part pattern (એક વાર શીખો, 17 વાર વાપરો)
દરેક control એક જ deal છે:
- Properties: તેની settings (Text, Checked, Value, Items)
- Events: એ શું announce કરે છે (Click, TextChanged, CheckedChanged)
- Methods: તમે એને શું કરવાનો order આપી શકો (Focus(), Items.Add())
એટલે "TextBox શીખો" નો અર્થ છે: key property Text, key event TextChanged. દરેક control question નો જવાબ આ જ આકારમાં આપો અને marks પાછળ આવશે.
At a glance
રોજિંદા આઠ
| Control | Till પરનું કામ | Key property | Key event |
|---|---|---|---|
| Label | ફક્ત display થતું text (shop name) | Text | (ભાગ્યે જ handle થાય) |
| TextBox | Item name type કરવું | Text | TextChanged |
| Button | Item ઉમેરવું, bill print કરવું | Text | Click |
| CheckBox | Any-of extras (carry bag) | Checked | CheckedChanged |
| RadioButton | 3 માંથી ફક્ત એક payment mode | Checked | CheckedChanged |
| ComboBox | Unit પસંદ કરવો (kg/pkt/pc) | SelectedItem, Items | SelectedIndexChanged |
| ListBox | દેખાતી list માંથી પસંદ કરવું | Items, SelectedIndex | SelectedIndexChanged |
| DateTimePicker | Bill ની date | Value | ValueChanged |
At a glance
Specialists
| Control | ખાસિયત | આ રીતે યાદ રાખો |
|---|---|---|
| MaskedTextBox | Typing ને pattern માં force કરે છે | 10-digit phone માટે Mask = "0000000000" |
| ProgressBar | લાંબા task નું feedback | Minimum, Maximum, Value |
| PictureBox | Image બતાવે છે | Image, SizeMode |
| RichTextBox | Formatted text (bold, colour) | Typography વાળું TextBox |
| TreeView | Hierarchies (category > item) | Nodes |
| ToolTip | બીજા control પર hover hint | SetToolTip(btnAdd, "Adds to bill") |
| NotifyIcon | System tray માં રહે છે | Minimised રહીને પણ till ચાલુ રહે છે |
| LinkLabel | Clickable link text | LinkClicked |
| CheckedListBox | એવી list જ્યાં દરેક row પર checkbox હોય | CheckedItems |
Practical
Add button controls ને વાંચે છે
Private Sub btnAdd_Click(sender As Object, e As EventArgs) _
Handles btnAdd.Click
Dim item As String = txtItem.Text
Dim qty As Integer = CInt(txtQty.Text)
Dim mode As String = "Cash"
If rdoCard.Checked Then mode = "Card"
If rdoUPI.Checked Then mode = "UPI"
If chkBag.Checked Then qty += 1 ' carry bag added
lblStatus.Text = item & " x" & qty & " (" & mode & ") on " & _
dtpBill.Value.ToString("dd/MM/yyyy")
End Sub
Quiz
Customer એ બરાબર એક જ payment mode પસંદ કરવો પડે છે, અને મહેતા અંકલ ઇચ્છે છે કે ત્રણેય options એક નજરમાં દેખાય. કયું control fit થાય છે?
- Cash, Card, UPI નામના ત્રણ CheckBoxes
- Cash, Card, UPI નામના ત્રણ RadioButtons
- એક TextBox જેમાં cashier mode type કરે
- ત્રણ Buttons, દરેક mode માટે એક
Show the answer
Cash, Card, UPI નામના ત્રણ RadioButtons
RadioButtons બરાબર exactly-one-of-few માટે જ BUILT થયેલા છે: એક select કરો એટલે તેના siblings આપોઆપ deselect થાય છે, અને બધા options દેખાતા રહે છે. CheckBoxes independent હોય છે, એટલે Cash અને Card બંને ticked થઈ શકે: checkboxes એટલે any-of, radios એટલે one-of, અને આ પ્રશ્ન એ જ ભેદ drill કરવા માટે છે. TextBox typos ને આમંત્રણ આપે છે ("cassh") અને validation નું દુઃખ ઊભું કરે છે. Buttons choice યાદ રાખવાને બદલે actions fire કરે છે; click પછી screen પર કંઈ બતાવતું નથી કે કયો mode selected છે. ComboBox પણ one-of enforce કરત, પરંતુ એ options ને એક click પાછળ છુપાવે છે, એટલે visible-at-a-glance requirement fail થાય છે.
Think first
Quantity box સુધી alphabet પહોંચતું અટકાવો
Quantity ફક્ત digits હોવી જોઈએ, અને phone numbers બરાબર 10 digits. સાદું TextBox "abc" ને ખુશીથી સ્વીકારી લે છે. Specialists table જુઓ: કયું control આ TYPING stage પર જ ઠીક કરે છે, અને કેવી રીતે?
Show the answer
MaskedTextBox, તેની Mask property દ્વારા: Mask = "0000000000" બરાબર 10 digits સ્વીકારે છે અને type થતી વખતે જ letters ને physically નકારે છે; કોઈ validation code નહીં, કોઈ error message નહીં, કારણ કે ખોટું input અંદર આવી જ શકતું નથી. એની પાછળનો design પાઠ: શ્રેષ્ઠ validation એ control છે જે invalid input ને અશક્ય બનાવે, એટલે કે Unit 2 ના Enum idea નું UI cousin. જે rules mask વ્યક્ત ન કરી શકે (price positive હોવી જોઈએ) એ માટે તમે code માં validate કરો જ છો, અને 3 પાઠ પછી આવતું ErrorProvider component એની polite રીત બતાવશે.
Watch out
Control પસંદ કરવાની ત્રણ ભૂલો
RadioButton ની જગ્યાએ CheckBox: any-of vs one-of; Cash અને Card બંનેથી ચૂકવાયેલું bill એ designer માં જન્મેલો data bug છે.
TextBox.Text હંમેશા String હોય છે: arithmetic પહેલાં CInt(txtQty.Text) કરો, બરાબર Unit 2 ના InputBox ની જેમ; "2" & 3 એ 5 નથી.
Space પ્રમાણે ListBox vs ComboBox: idea એક જ છે (Items માંથી પસંદ કરવું); ListBox list કાયમ બતાવે છે, ComboBox એને વાળીને છુપાવે છે. ફક્ત દેખાવ પરથી પસંદ કરવું, WHY કહ્યા વગર, reasoning નો mark ગુમાવે છે.
Theory
કોઈપણ નવું control 30 seconds માં વાંચો
આ pattern આ syllabus થી આગળ પણ generalise થાય છે: VB.NET માં કે Android માં કોઈ પણ અજાણ્યું control મળે (BCA305-02 ના widgets પણ એ જ deal હતા), ત્યારે 3 પ્રશ્ન પૂછો: તેની key properties કઈ છે? એ કયા events raise કરે છે? કયા methods અગત્યના છે? Properties window પહેલા 2 ના જવાબ સીધા આપે છે (તેની lightning-bolt tab events list કરે છે). આગળનો પાઠ: આ controls ને group કરતા containers, અને એ topic ની અંદર છુપાયેલી radio-button surprise.
Summary
Key takeaways
- દરેક control = properties (settings) + events (announcements) + methods (orders).
- Core mapping: Label display કરે, TextBox type કરાવે, Button click લે, DateTimePicker dates આપે.
- Choices: CheckBox = any-of (independent); RadioButton = exactly-one-of; ComboBox/ListBox = Items માંથી પસંદગી.
- Specialists: MaskedTextBox typing pattern force કરે, ProgressBar Minimum અને Maximum વચ્ચે Value બતાવે, ToolTip hover hints જોડે, NotifyIcon tray માં બેસે.
- TextBox.Text એક String છે: arithmetic પહેલાં convert કરો.
- પછીથી ઠપકો આપતા code કરતાં invalid input ને અશક્ય બનાવતાં controls પસંદ કરો.
- Memory hook: radios એક પસંદ કરે, checks ઘણા પસંદ કરે, combos list માંથી પસંદ કરે.