0% found this document useful (0 votes)
37 views14 pages

Designing Basic User Input Controls

The document discusses designing basic controls like buttons, text boxes, checkboxes, and radio buttons in a Windows Form Application. It provides examples of creating a simple application with a button that displays text in a text box or message box when clicked. It also demonstrates using checkboxes to select multiple options and radio buttons to select a single option, displaying the selection in a text box or message box. The document ends with an example of a radio button application to display the user's high school level (freshman, sophomore, etc.) in a text box based on their selection.

Uploaded by

Joe Han
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views14 pages

Designing Basic User Input Controls

The document discusses designing basic controls like buttons, text boxes, checkboxes, and radio buttons in a Windows Form Application. It provides examples of creating a simple application with a button that displays text in a text box or message box when clicked. It also demonstrates using checkboxes to select multiple options and radio buttons to select a single option, displaying the selection in a text box or message box. The document ends with an example of a radio button application to display the user's high school level (freshman, sophomore, etc.) in a text box based on their selection.

Uploaded by

Joe Han
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

-Designing Basic Controls or Objects

Controls or objects are the primary medium of the user’s interaction with the application system on which we
design and develop. Mostly, controls are used to get the user input and to display the corresponding output.
Other controls provide an access to some application system and process data or information as though the
remote application system is part of our program.

Basic controls are buttons, text box, label, check boxes, radio buttons, list box, and combo box. By clicking or
typing something on these controls, the user can accomplish tasks.

Using Button and Text Box

Button is used to carry out a command or action(event) as the user clicks it. It is also used to extract simple
responses from the user or to invoke special functions of a from.

Text box provides an area to input or display text. It is commonly used to display string or numeric data and to
accept user input or for entering data.

Example 1:

Design and develop an application system that when the user clicks the Greet Now! Button, the message “Hello
World!” will be displayed at the text box.

Solution:

1. Create a new Windows Form Application project by using either File menu or the New Project icon in
the toolbar.
2. Name the new application system vbButton1.
3. Set the Form’s Text property to vbButton1, too.
4. Add a text box and a button into the form, then set the Text property of Button1 to Greet now!

5. Double-click Button1 on the Form to display the button1_Click event method. Embed the following lines
into the method:
[Link] = "Hello World!"
6. Build and execute the application system.

Sample Output:
Explanation:

The syntax for our example takes the format of

[Link]

where Textbox1 is the object(control) and Text is the property. We can use this syntax to change
property settings for any form or control in response to events that occurs while our application system is
running.
Example 2:

Design and develop an application system that when the user clicks the Greet Now! Button, the message “Hello
World!” will be displayed at the message box.

Solution:

1. Create a new Windows Form Application project. Name the new application system vbButton2. Set the
Form’s Text Property to vbButton2, too.
2. Add a button into the form, then set its Text Property to Greet now!

3. Double click the button on the Form to display button1_Click event method. Embe he following lines
into the method:
[Link]("Hello World!")

4. Build and execute the application system.


Sample Output:

Explanation:

The embedded code

[Link]("Hello World!")

is simply to display the message “Hello World!” at the message box control.

A message box is used for displaying simple message to the user.


Using Check boxes, Radio Buttons and Message box

Check boxes are valid as single controls, how ever they are not mutually exclusive, the user can check as
many check boxes as they want. Check boxes are applicable to the situation where you can select a lot of
items because you want them all, such as you can order a pizza and choose all the ingredients you want to
put on it as long as you can afford to pay.

Radio buttons, the user can only select one option at a time. It is applicable to this situation – marrying a
girl. In the Christian world, no matter how many girlfriends you have at the same time or in the same place,
you can only choose one among them to marry, unless you change your religion into something else that
allows polygamous marriage. (in which gusto ng iba diyan )

Example 3:

Design and develop a simple Check box and Text box application that when the user clicks one of the three
checkboxes, it will indicate in the text box on which checkbox the user had clicked. For example, if Check box
2 was clicked by the user, it will display “Check box 2 is clicked!” at the textbox. It will do the same with
Check box 1 and Check box 3.

Solution:

1. Create a new Windows Form Application project. Name the new application system vbCheckBox1. Set
the Form’s Text Property to vbCheckBox1, too.
2. Add three (3) Check boxes into the Form, then set their respective Text Property to Check 1, Check 2,
Check 3. Add also a Text box into the Form.

3. Double-click the Check Box 1 on the Form to display the checkBox1_CheckedChanged event method.
Embed the following lines to the method:
[Link] = "Check box 1 is clicked!"
4. Do this with Check box 2 and 3(don’t forget to change the number of checkbox).
5. Build and execute the application system.

Sample Output:

Explanation:

Although a check box control is rather similar to a Radio button, there are two fundamental differences between
them; you can select many choices in check boxes, while in Radio button you are only allowed to select one
option at a time. You can observe that when you click the checkbox1(Check 1) then you click checkbox2(Check
2), these two check boxes have the check mark on both of them. And even when you click the checkbox3(Check
3), it will also contain the check mark. In Radio button, only one radio button will contain the bullet or big dot at
a time, once you click the next Radio button, the next Radio button will contain the bullet as though it transfers
from the previous button.
Exercise 1:

Design and develop a simple Check box and Message box application that when the user clicks one of the three
checkboxes, it will indicate in the Message box on which check box the user had clicked. For example, if Check
box 2 was clicked by the user, it will display “Check box 2 is clicked!” at the Message box. It will do the same with
Check box 1 and Check box 3. Follow the given figure below:

Sample Output:
Example 4:

Design and develop a simple Text box and Radio buttons application that when the user clicks one of the three
Radio buttons, it will indicate in the Text box on which Radio button the user had clicked. For example, if Radio
button 2 was clicked by the user, it will display “Radio button 2 is clicked!” at the Text box.

Solution:

1. Create a new Windows Form Application project. Name the new application system vbRadioButton1.
Set the Form’s Text property to vbRadioButton1, too.
2. Add three (3) Radio buttons and a Text box into the form.

3. Double-click the Radio button 1 on the Form to display the radioButton1_CheckedChange event
method. Embed the following lines of code to the method:
[Link] = "Radio button 1 is clicked!"
4. Do this with Radio button 2 and 3(don’t forget to change the number of radio button).
5. Build and execute the application system.

Sample Output:
Example 5:

Design and develop a simple Message box and Radio buttons application that when the user clicks one of the
three Radio buttons, it will indicate in the Message box on which Radio button the user had clicked. For example,
if Radio button 2 was clicked by the user, it will display “Radio button 2 is clicked! at the Message box. It will do
the same with Radio button 1 and Radio button 3.

1. Create a new Windows Form Application project. Name the new application system vbRadioButton2.
Set the Form’s Text property to vbRadioButton2, too.
2. Add three (3) Radio buttons into the form.

3. Double-click the Radio button 1 on the Form to display the radioButton1_CheckedChanged event
method. Embed the following lines to the method:
If [Link] = True Then
[Link]("Radio button 1 is clicked!")
End If

4. Do this with Radio button 2 and 3(don’t forget to change the number of radio button).
5. Build and execute the application system.

Sample Output:

Explanation:

You will notice that the Radio button 1 is by default, the first control to be selected. It’s because in Radio button
controls, one its control object must be selected, and only one of the controls must be selected exclusively.
Unlike in Check boxes control, two or more check boxes can be selected simultaneously.

The If conditional statement is included because we need to check first if a particular Radio button is being
selected, and if it is, we have to trigger the Message Box to show the message. The MessageBox method needs
to be triggered to display or show something. You can experiment based on the example, what would be the
effect if you wouldn’t apply the If conditional statement.
Example 6:

Design and develop a simple Text box and Radio buttons application that when the user clicks one of the four
radio buttons, it will indicate in the Text box on which radio button the user had clicked. For example, if radio
button 2 (Second Year) was clicked by the user, it will display “Sophomore” at the Text box, it will do the same
with Radio button 1, Radio button 3 and Radio button4. The high school level of First Year is “Freshman”, for
Second Year is “Sophomore”, for Third Year is “Junior” while Fourth Year is “Senior”.

Solution:

1. Create a new Windows Form Application project. Name the new application system vbHighSchool1. Set
the Form’s Text property to vbHighSchool1, too.
2. Add a Label and set its Text Property to High School Level:. Add also four (4) Radio buttons into the form,
then set their respective Text property to First Year, Second Year, Third Year and Fourth Year. Add
another label control and place them appropriately, lastly add a Text box.

3. Double-click the First Year radio button on the Form to display the radioButton1_CheckedChanged event
method. Embe the following line of code to the method.
[Link] = "Freshman"
4. Do the same with the other three Radio buttons (for Second Year is “Sophomore”, for Third Year is
“Junior” while Fourth Year is “Senior”)
5. Build and execute the application system.

Sample Output
Hiding and Disabling Controls

We will discuss some program examples that demonstrate on an actual basis how to hide or disable a
control. It is done by simply setting the Enabled or Visible property of a particular control to false at the
design time. Or alternatively, we can set it at the run time, by using this syntax:

[Link] = false;

Or

[Link] = false;

Note: Design time means that we are modifying our program as we design it on the Form where we can set
the Control’s property through the Property Window. As we design the controls on our Form while we invoke
the Form Designer. Now, how about run-time? Run-time refers to the coding we do that sets the property
of a particular Control right on our program. In other words, as er open(invoke) the Code Designer, we hard-
coded the setting of properties.

Example 7:

Design and develop an application system that disables or enables a Button, and displays it feedback to the
Textbox. When the user clicks the Try to Click Me! Button, the feedback that says “Yes! I was enabled! Thank
you!” should be displayed at the Text box. Now when the user clicks the Disable Button! Radio button, the
Button control should be disabled (grayed), and the feedback that says “You Disabled the button!” is
displayed at the Text box. Plus, the Try to Click Me! Button is unclickable. Now when the user clicks the
Enable Button! Radio button, the Try to Click Me! Button should be restored to its enabled state, and the
feedback that says “You Enable the Button! Should be displayed at the Text box.

Solution:

1. Create a new Windows Form Application project. Name the new application system vbDisableControl1.
Set the Form’s Text property to vbDisableControl1, too.
2. Add a Button into the form, and set its Text Property to Try to Click Me!.
3. Add also a Text box into the form.
4. Add a two (2) Radio buttons into the Form the set their respective Text property to Enable Button! and
Disable Button!

5. Double-click the Try to Click Me! Button on the Form to display the button1_Click event method. Embed
the following lines to the method.
[Link] = "Yes I was Disabled! Thank you!"
6. Double-click the Enable Button! radio button on the Form to display the radioButton1_CheckedChanged
event method. Embed the following lines to the method.
[Link] = True
[Link] = "You Enabled the Button!"
7. Double-click the Disble Button! radio button on the Form to display the radioButton2_CheckedChanged
event method. Embed the following lines to the method.
[Link] = False
[Link] = "You Disabled the Button!"
8. Build and execute the application system.
Sample Output:

Output when this


button was clicked
Example 8: Design and develop an application system that shows or hides Radio button 1.

Solution:
1. Create a new Windows Form Application project. Name the new application system
vbShowHideControl1. Set the Form’s Text property to vbShowHideControl1, too.
2. Add four (4) Radio buttons into the form.
3. Add two (2) buttons into the form, then set their respective Text Property to Hide Radio1! and Show
Radio1!

4. Double-click the Hide Radio1! Button on the form to display the button1_Click event method. Embed
the following lines to the method:
[Link] = False
5. Double-click the Show Radio1! Button on the form to display the button1_Click event method.
Embed the following lines to the method:
[Link] = True
6. Build and execute the application system.

Sample Output:

Output when this Output when this


button is clicked. button is clicked.
Example 9:
Design and develop an application system that when the user points the mouse-pointer at any control
on the Form, it will display the tooltip of what kid of control it is pointing to.
Note:
When the user points to his/her mouse on the Form, the tooltip should be “This is a Form!”, now if the
user points the mouse on Label1, the tooltip should be “This is a Label!” Apply the same respective
tooltip to other controls, too.

Solution:
1. Create a new Windows Form Application project. Name the new application system vbToolTip1. Set
the Form’s Text property to vbToolTip1, too.
2. Add a Label, a Button, a Check Box, and a Radio Button into the form. Then, add also five (5) ToolTips
into the form. The ToolTip1, ToolTip2, ToolTip3, Tooltip4 and ToolTip5 controls should appear at the
bottom of the Form. Why the ToolTip is up to 5? Because we will include the Form as one of the
controls to be assigned with ToolTip control.

3. Double-click now the Form to display the Form1_Load event method. Embed the following lines to
the method:
[Link](Me, "This is a Form!")
[Link](Label2, "This is a Label!")
[Link](Button1, "This is a Button!")
[Link](CheckBox1, "This is a Check Box!")
[Link](RadioButton1, "This is a Radio Button!")

7. Build and execute the application system.

Sample Output:
Example 10:

Design and develop an application system that will echo the message typed at the Text box to the Label
with bigger font size.

Solution:

1. Create a new Windows Form Application project. Name the new application system vbEcho1. Set
the Form’s Text property to vbEcho1, too.
2. Add a Label into the Form and set its Text property as Enter a message to echo:
3. Add also a Text box into the Form. Position it properly and adjust its width appropriately.
4. Add another Label into the Form then set its Font size property to 16.

5. Double-click the Text box to display the TextBox1_TextChanged event method. Embed the following
lines into the method.
[Link] = [Link]
Or
[Link] = [Link]

8. Build and execute the application system.

Sample Output:

Common questions

Powered by AI

Labeling controls in application development is significant because it provides users with a clear understanding of each control's function and expected interaction. Well-labeled controls eliminate ambiguity, reducing user errors and enhancing navigation efficiency. This clarity in the user interface is crucial for user satisfaction and accessibility, as properly labeled controls ensure that all users, regardless of their experience level, can operate the application effectively and intuitively.

Enabling and disabling controls contribute to efficient application workflows by guiding users towards permissible actions while preventing unintended operations. Disabled controls serve as visual cues for unavailable options, reducing confusion and errors. This approach enhances user experience by ensuring that only valid operations are accessible at any given time, streamlining task completion and maintaining focus on available actions. Enabling controls only when conditions are met prevents errors and supports logical task progression.

ToolTips enhance user experience by providing additional contextual information without cluttering the interface, offering guidance or clarification when users point to controls. This can significantly aid usability by helping users understand functions and navigate applications intuitively. However, excessive reliance on ToolTips may lead users to miss out on vital information if they don't hover over controls, and can clutter the development process by necessitating careful design and testing to ensure accuracy and relevance.

Event methods like button1_Click or checkBox1_CheckedChanged are integral to the behavior of a Windows Form Application as they define the specific actions that occur when an event is triggered. These methods encapsulate the logic to execute tasks in response to user interactions, such as button clicks or checkbox changes, enabling the application to respond dynamically. This event-driven approach ensures that applications are interactive and can handle multiple user inputs effectively.

Embedding code snippets in event-driven programming environments is necessary because it defines the actions taken in response to user interactions or system events. This approach allows developers to customize application behavior dynamically, ensuring that specific responses occur only when relevant events like clicks or key presses are detected. It enables creating interactive and responsive applications by linking user interface elements to functional code, facilitating modular and maintainable code management.

Changing a control's Visibility property dynamically at runtime allows developers to enhance application functionality by showing or hiding elements based on user interactions or conditions. This affects user interaction by providing a more responsive and context-sensitive interface, helping to streamline navigation and reduce clutter by displaying only relevant controls. However, developers must carefully design these changes to maintain a coherent user experience and avoid confusion.

Setting properties at design-time involves configuring controls through the property window while building a form in the Form Designer, whereas runtime property setting is done programmatically in the Code Designer, allowing dynamic changes during execution. A developer might choose design-time setting for static properties that do not change during operation, enhancing development speed and maintaining simplicity. Runtime settings are chosen when properties need to adapt based on user interaction or other operational conditions, offering flexibility and interactivity.

The primary difference between a checkbox and a radio button is that checkboxes allow multiple selections at the same time, whereas radio buttons permit only a single option to be selected within a group. In user interface design, this difference impacts usability: checkboxes are ideal for tasks where users can choose multiple options, like selecting ingredients for a pizza, while radio buttons are suited to scenarios where only one choice is appropriate, such as selecting a subscription plan. These characteristics influence interface layout and user flow, as designers must ensure the correct control type is used to prevent confusion and enhance task efficiency.

A developer might prefer using a Message Box over text boxes or other display methods for notifications requiring immediate attention or confirmation from the user. Message Boxes are modal, meaning they halt application flow until dismissed, ensuring users see the message before proceeding, which is crucial for error messages, warnings, or obtaining user consent. These characteristics make Message Boxes ideal for critical notifications, whereas text boxes are more suited for displaying less urgent information that doesn't disrupt user tasks.

In a Radio button event method, the If conditional statement is used to verify if a particular Radio button is selected before triggering the Message Box. This ensures that the action of displaying a message is only carried out if the selection condition is met, preventing unnecessary operations and enhancing control logic. Utilizing the If statement provides a safeguard that ensures program execution aligns with user actions, improving the application's responsiveness and efficiency.

You might also like