Lesson 14 - Other Windows Forms Controls
In the previous lesson, Basic Windows Forms Controls, we described several basic form controls,
CheckBox. In today's C# .NET tutorial, we're going to continue the
RadioButton is very similar to
difference is that only one
RadioButton inside the current
container can be checked at a time. If you have more of them and check one, the
others will be unchecked. So we can always choose only one from a set of
options. We usually use
RadioButton controls when there are only a
few options available and a
ListBox wouldn't look nice on the
bool) - If the value is
Appearance- If set to
RadioButtonwill be rendered as an ordinary button (i.e. the
Button). A checked
RadioButtonwill look like a pressed button, others will look like unpressed ones.
Image- If we use
Appearance = Button, we can set an icon to the button easily.
TextAlign- Aligns the label text to the check button.
ImageAlign- Aligns the image.
TextImageRelation- Here we can set the relation between the text and the image. The text can be displayed over the picture, but it can also be above it, below it, etc.
CheckedChanged- Is triggered when the
RadioButtonis checked or unchecked.
If some controls on the form are logically related, we can place them in a
container. The container is a control that can contain other controls inside. We
can simply put those controls into it in the designer. One of the containers in
GroupBox. Try to create a
GroupBox and put
several controls in it. Then when you move it, you'll see those controls are
moving along with it.
Beside making the form more readable, inserting controls into containers has
other benefits as well. For example, we can hide the container (set
false) and it'll disappear along with its
contents. We can easily access the controls inside the container using its
Controls collection and a loop. And last but not least, we can put
RadioButton controls in it, of which only one can be selected at a
RadioButton controls can be checked at a time if they
are in different containers.
Text- The group title.
Controls- The collection of all the components inside this group.
No important events.
Panel is another container control. It behaves the same as the
GroupBox, except that its border isn't displayed by default. This
allows us to group form controls for inner purposes of the application, without
the user noticing it. A typical example is putting e.g. 20
controls with different values into a
Panel, then iterating through
Controls collection and setting the
Text value to
each. Without the panel, getting to the
TextBox controls would be
more difficult, and perhaps we'd accidentally rewrite all the controls on the
BorderStyle- The visual style of the panel's border. We can set
Controls- The collection of all controls inside the panel.
No important events.
FlowLayoutPanel arranges form controls for us. While in the
normal panel we have to set their positions manually,
FlowLayoutPanel doesn't use their positions, but displays the
controls as they go instead, from left to right, from top to bottom. This can
often be useful.
FlowDirection- We can set in which direction the controls should be displayed. The
Panelcan display them both from right to left, or even vertically in both directions.
BorderStyle- The style of the border. We can set
No important events.
PictureBox is an image, more specifically an image control. It's
useful for improving the application design. It's also a common practice to not
assign the image to it, but draw something instead (e.g. a graph).
Image- The image.
SizeMode- The display mode of the image. The
Normalmode displays the image as it is,
StretchImagestretches it over the entire
PictureBox, regardless of the aspect ratio, the
PictureBoxsize to the size of the image,
CenterImagecenters the image, and finally,
Zoomresizes the image respecting the aspect ratio.
Paint- This event is triggered when the image is to be redrawn (that is, when the form asks for the image to be redrawn. This happens when the form is created or when another window is moved over the form). Inside the handler method, we usually draw our own graphics on the image's canvas, using the methods of the
Graphicsproperty of the
ehandler method parameter. We've already tried it several times during this course.
DateTimePicker allows us to enter date and time with dignity.
It's certainly worth using this control for this purpose, it's easy for the user
and for us as well. We don't have to parse values from a
which spares us from handling input errors, and at the same time the operating
system solves entering the value for us. It provides us a nice calendar to enter
the date and time.
Format- Selects the output format. We can choose between the long and short date formats, time format, and even our own format, but we won't deal with this one here.
Here's how the time picker looks like:
bool) - Specifies whether to display the UpDown (arrows that are particularly useful for time entering) or the DropDown calendar (which is perfect for date entering).
Value- The entered value.
ValueChanged- Occurs when the user changes the value.
The calendar allows us to display days of a month, to select them and render some as bold. We can use it as part of some agenda app.
DateTime) - A
DateTimearray of the days that will be rendered as bold. For example, we highlight the days we have an appointment on this way.
DateTime) - Similar as the above, bold days can be specified regardless of the month, so they'll appear bold in every month.
AnnuallyBoldedDays- Again, similar as the above, but the days will appear bold every year, so they year doesn't matter.
CalendarDimensions- The number of months displayed vertically and horizontally.
bool) - Allows us to turn off the bottom bar with today's date.
bool) - Allows us to turn off the circle highlighting of today.
bool) - Displays week numbers.
DateChanged- Occurs when the date selection (or date range) has changed or when we move to the next / previous month using the arrows.
DateSelected- Occurs when the date selection (or date range) has changed.
That's all for today. In the next lesson, Windows Forms - Dialogs, we'll continue with our review of the .NET controls.
No one has commented yet - be the first!