Menu
Theme

GUI design

Visual Basic Programming

Karibu! Let's Design Interfaces Like a Pro in Visual Basic!

Habari yako, future software developer! Ever used the M-Pesa app, a banking application, or even a simple calculator on a computer? The colourful screens, the buttons you click, the boxes where you type – that's all part of the Graphical User Interface, or GUI (pronounced "gooey").

Think of it this way: the powerful code you write is like the engine of a car. It's strong and does all the work. But the GUI is the dashboard, the steering wheel, and the comfortable seats. It's how the user "drives" your program. A good GUI makes your application easy and enjoyable to use, while a bad one can make even the best program frustrating. Today, we're going to learn how to be great 'car designers' for our software!

The Visual Basic Toolbox: Your Digital 'Fundi' Kit

In Visual Basic, we don't have to build everything from scratch. The IDE (Integrated Development Environment) gives us a 'Toolbox', which is like a fundi's (artisan's) kit filled with ready-made parts. You just drag and drop them onto your form!

Here are some of the most important tools in your kit:

  • Form: This is your foundation, like the plot of land where you will build your house (application).
  • Label: A simple text signpost. You use it to display text that the user can't change, like "Enter Your Name:".
  • TextBox: This is an input field where the user can type information, like their name or a number.
  • Button: The action-taker! Users click it to make something happen, like "Submit", "Calculate", or "Exit".
  • ComboBox: A drop-down list. Perfect for when a user needs to select one option from a list, like choosing their county.
  • CheckBox: A small box to tick on or off. Used for Yes/No options, like "I agree to the terms and conditions."
  • RadioButton: Allows a user to choose only ONE option from a group. For example, selecting "Male" or "Female".
  • PictureBox: A frame to display images in your application.

Image Suggestion: A vibrant, cartoon-style illustration of the Visual Basic IDE. On the left, a prominent "Toolbox" is shown with icons for a button, textbox, and label, looking like real-life tools. A hand is dragging a button onto the main "Form" in the center, which looks like a blank canvas. The style should be friendly and educational.

Principles of Good Design: Make It 'Rahisi Kutumia' (Easy to Use)

A great GUI is not just about looking good; it's about being functional. Remember these key ideas:

  • Clarity: Everything should be clear and easy to understand. Use simple language. "Calculate Total" is much better than "Execute Summation".
  • Consistency: Keep your design consistent. All buttons should have a similar style. All labels should use the same font. Imagine a newspaper where every headline has a different font – it would be confusing!
  • User Control: The user should feel in control. Always provide a way to go back or cancel an action. An "Exit" button is a must!
  • Feedback: Let the user know what's happening. If they click a "Save" button, show a message like "Data saved successfully!".

Let's Build! Designing a Simple 'Kiosk' Calculator

Theory is good, but practice is better! Let's design a simple application for a small kiosk to calculate the total price of two items. We'll call it "DukaCalc".

Step 1: Sketch Your Design

Before you even touch the computer, always sketch your idea on paper. It saves a lot of time! Our sketch for DukaCalc might look like this:


+-------------------------------------------+
| [ DukaCalc by [Your Name] ]      [_][#][x]|
+-------------------------------------------+
|                                           |
|   DUKA TOTAL CALCULATOR                   |
|   =====================                   |
|                                           |
|   Price of Sukuma (KSh): [_________]      |
|                                           |
|   Price of Mandazi (KSh): [_________]     |
|                                           |
|                 +-----------+             |
|                 | CALCULATE |             |
|                 +-----------+             |
|                                           |
|   TOTAL COST: KSh 0.00                    |
|                                           |
+-------------------------------------------+

Step 2: The Properties Window - Naming Your Tools

After dragging the controls (Labels, TextBoxes, Button) onto your form to match the sketch, you need to give them proper names. This is SUPER important for your code later.

We use the Properties Window for this. Select a control, and the properties window will show all its settings. We will change two main properties:

  1. (Name): This is the control's ID for the programmer (you!). It's not visible to the user. We use a prefix to know the control type.
    • The first TextBox: txtPriceSukuma
    • The second TextBox: txtPriceMandazi
    • The Button: btnCalculate
    • The Label for the result: lblTotal
  2. Text: This is what the user actually sees on the screen.
    • The Button's Text: "CALCULATE"
    • The main title Label's Text: "DUKA TOTAL CALCULATOR"

Real-World Scenario: Think of it like this. Your official government name is on your ID card - that's the (Name) property. It's unique and used for official business (coding). Your nickname that your friends call you is like the Text property - it's what everyone sees and uses casually.

Step 3: Adding the 'Magic' - The Calculation Code

Now, let's make the "CALCULATE" button do its job. Double-click the button in the design view. This will open the code window, ready for you to type the instructions.

The text a user types into a TextBox is just text (a String), not a number. We need to convert it to a number before we can do math. The Val() function is perfect for this.


' This is the code that runs when btnCalculate is clicked
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    
    ' 1. Create variables to store the numbers
    Dim priceSukuma As Double
    Dim priceMandazi As Double
    Dim total As Double

    ' 2. Get the text from TextBoxes, convert to numbers and store in variables
    priceSukuma = Val(txtPriceSukuma.Text)
    priceMandazi = Val(txtPriceMandazi.Text)

    ' 3. Perform the calculation (the easy part!)
    '    Formula: Total = Price 1 + Price 2
    total = priceSukuma + priceMandazi

    ' 4. Display the final answer in the result label
    '    We add "Total: KSh " to make the output user-friendly
    lblTotal.Text = "TOTAL COST: KSh " & total.ToString()

End Sub

When you run your program, it will now function like a real calculator for the kiosk owner. Simple, clean, and effective!

Your Challenge, Mtaalam!

You've learned the basics of GUI design. You are now the architect of your application's user experience. Your challenge is to improve our DukaCalc application.

  • Add a third item, maybe "Bread". You will need to add a new Label and a new TextBox.
  • Update the calculation to include the price of bread.
  • Add a "Clear" button that resets all the textboxes and the total to zero.

Good luck! Remember, a well-designed GUI is the bridge between your powerful code and a happy user. Go build those bridges!

Pro Tip

Take your own short notes while going through the topics.

Previous Data flow diagrams
KenyaEdu
Add KenyaEdu to Home Screen
For offline access and faster experience