0% found this document useful (0 votes)
17 views8 pages

C# TextBox and Control Properties Explained

The document explains various properties and controls in C# Windows Forms, including TextBox, CheckBox, ComboBox, and others, detailing their functionalities and use cases. It also covers event handling with delegates, mouse events, and keyboard events, providing insights into how user interactions are managed. Additionally, it discusses layout mechanisms like anchoring and docking, as well as MDI forms for managing multiple child windows.

Uploaded by

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

C# TextBox and Control Properties Explained

The document explains various properties and controls in C# Windows Forms, including TextBox, CheckBox, ComboBox, and others, detailing their functionalities and use cases. It also covers event handling with delegates, mouse events, and keyboard events, providing insights into how user interactions are managed. Additionally, it discusses layout mechanisms like anchoring and docking, as well as MDI forms for managing multiple child windows.

Uploaded by

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

1.

Explain the following TextBox properties


A TextBox control in C# is used to get input from the user or display text. It
provides several properties to control its appearance and behavior.
a) AcceptReturn:
This property determines whether the Enter key is accepted as input in a
multiline TextBox.
If the value is set to true, pressing Enter will insert a new line within the text box.
If set to false, pressing Enter will not add a new line; instead, it will move focus to
the default button on the form (if any).
It is commonly used when users are allowed to type multi-line comments or
descriptions.
b) MultiLine:
The MultiLine property allows the TextBox to display multiple lines of text. When
set to true, text can wrap to the next line or include line breaks. It also enables
vertical scrolling if needed.
For example, a feedback or address box often uses a multiline TextBox.
c) ReadOnly:
This property makes the TextBox non-editable without disabling it. When set to
true, the user cannot modify the text, but the text can still be selected and
copied. This is useful for displaying output or computed results without allowing
changes.
d) ScrollBars:
The ScrollBars property specifies whether scroll bars are visible. It can have
values such as None, Horizontal, Vertical, or Both. This property is only effective
when MultiLine is set to true.
For example, long text inputs may need vertical scroll bars for easy viewing.
e) UseSystemPasswordChar:
This property is used when creating password fields. When set to true, the
TextBox masks all characters entered with a system-defined character (like ● or
*). This improves security by hiding the actual input.

2. Explain AcceptButton, AutoScroll, CancelButton, FormBorderStyle, and Font


properties of Windows Form control
A Windows Form in C# represents the main window of a desktop application. It
has various properties to control form behavior and appearance.
AcceptButton:
This property sets the button that will be clicked automatically when the user
presses the Enter key. It is useful in forms where a default action (like “Submit”
or “OK”) is expected.
AutoScroll:
When set to true, this property enables automatic scroll bars if the content of the
form exceeds the visible area. It helps when placing large numbers of controls on
a small form.
CancelButton:
This defines the button that is triggered when the Esc key is pressed. It is
commonly used for “Cancel” or “Exit” buttons to allow easy form closure through
the keyboard.
FormBorderStyle:
This property controls the border appearance and behavior of the form. Options
include None, FixedSingle, FixedDialog, Sizable, and more. It determines whether
the user can resize or move the form.
Font:
The Font property specifies the font style, size, and family used for text in the
form and its controls. For example, setting Font = new Font("Arial", 10) changes
the default text appearance.

3. Explain how delegates can be used in event handling


A delegate in C# is a type-safe object that holds a reference to a method.
Delegates are the foundation of event handling because events use delegates
internally to call event handler methods.
When an event occurs (like a button click), the event is raised, and the
associated delegate calls the event-handling method.
Example:
public delegate void MyDelegate(string message);

public class Test


{
public static void DisplayMessage(string msg)
{
[Link](msg);
}

public static void Main()


{
MyDelegate del = new MyDelegate(DisplayMessage);
del("Event handled using delegate!");
}
}
Here, the delegate MyDelegate refers to the method DisplayMessage.
In Windows Forms, event handlers like [Link] use delegates automatically.
The delegate enables decoupling between the event source and event handler,
promoting flexibility and reusability.

4. Explain the following properties with respect to Control Class


Every control in C# inherits from the Control class, which provides common
properties to all controls.
a) Enabled:
Indicates whether the control can respond to user input. If Enabled = false, the
control appears dim and does not react to clicks or keystrokes.
b) ForeColor:
Specifies the color used to draw text or foreground graphics in the control. It
changes the text color.
c) BackColor:
Sets the background color of the control. It’s often used to highlight or categorize
controls visually.
d) Text:
Represents the text displayed on the control. For example, a Button’s Text
property shows its label.
e) TabIndex:
Determines the order in which controls receive focus when the user presses the
Tab key.
f) TabStop:
Indicates whether a control can receive focus via the Tab key. When TabStop =
false, the control is skipped during tab navigation.

5. Explain about anchoring and docking a control


Both anchoring and docking are layout mechanisms used to control how a control
behaves when the form is resized.
Anchoring:
Anchoring ties one or more sides of a control to the edges of its container (form).
When the form is resized, the control maintains its relative position to those
edges.
For example:
[Link] = [Link] | [Link];
This keeps the button fixed at the bottom-right corner even when the form is
resized.
Docking:
Docking attaches a control to one side (top, bottom, left, right) or fills the entire
parent container.
Example:
[Link] = [Link];
This makes the TextBox expand across the top of the form.

6. Explain Padding, Location, Size, Anchor, Dock properties of control layout


Padding:
Specifies the spacing inside a control’s border and its content. It helps maintain
neat spacing and appearance.
Location:
Defines the X (horizontal) and Y (vertical) coordinates of a control on a form,
measured from the top-left corner.
Size:
Represents the width and height of the control. Changing this property resizes
the control.
Anchor:
Keeps the control positioned relative to form edges during resizing.
Dock:
Aligns the control to one side of its container or makes it fill the container
completely.

7. Explain the following properties of CheckBox


A CheckBox control allows users to make binary or multiple selections.
a) Appearance:
Determines whether the CheckBox looks like a box or a button. The values are
Normal or Button.
b) Checked:
A Boolean property indicating whether the CheckBox is selected.
c) CheckState:
Indicates the state of the CheckBox – Checked, Unchecked, or Indeterminate.
d) Text:
Displays the label beside the CheckBox.
e) ThreeState:
When set to true, enables a third state (Indeterminate) besides Checked and
Unchecked. This is useful for mixed selections.

8. Explain MonthCalendar control with any of its 4 unique properties


The MonthCalendar control displays a monthly calendar for selecting dates or
date ranges.
Unique Properties:
1. MaxSelectionCount: Sets the maximum number of days the user can
select.
2. SelectionStart: Gets or sets the first date in the selected range.
3. SelectionEnd: Gets or sets the last date in the selected range.
4. TodayDate: Gets or sets the date displayed as “Today” on the control.
The MonthCalendar control is often used in applications involving date
scheduling or event planning.

9. Explain DateTimePicker control with any of its 4 unique properties


The DateTimePicker control allows users to pick a date or time from a drop-down
calendar or spinner.
Unique Properties:
1. Format: Defines how the date/time is displayed (Short, Long, Time,
Custom).
2. CustomFormat: Allows a user-defined format like "dd/MM/yyyy".
3. Value: Gets or sets the currently selected date and time.
4. ShowUpDown: Displays spin buttons instead of a drop-down calendar for
time selection.
This control ensures accurate date/time entry and simplifies date handling in
programs.

10. Explain NumericUpDown control with its unique properties


The NumericUpDown control allows the user to enter numeric values using small
up and down arrows.
Unique Properties:
1. Minimum: Specifies the lowest possible value.
2. Maximum: Specifies the highest possible value.
3. Increment: Sets how much the value changes with each click.
4. DecimalPlaces: Defines how many digits are displayed after the decimal
point.
This control is often used for quantity or numeric input fields where range limits
are required.

11. Explain the mouse events and mouse event arguments


Mouse events in C# allow controls to respond to mouse actions.
Common Mouse Events:
 MouseClick – Occurs when the mouse button is clicked.
 MouseDoubleClick – Occurs when double-clicked.
 MouseDown – Fires when the button is pressed.
 MouseUp – Fires when the button is released.
 MouseMove – Fires when the pointer moves over a control.
 MouseHover – Fires when the pointer hovers over a control.
MouseEventArgs properties include:
 Button – Indicates which mouse button was pressed.
 Clicks – Number of clicks.
 X and Y – Coordinates of the pointer.
 Delta – Wheel movement amount.

12. List the KeyEventArgs class properties with their purpose


The KeyEventArgs class provides data for keyboard-related events (KeyDown,
KeyUp).

Property Purpose

Alt Checks if the Alt key was pressed.

Control Checks if the Ctrl key was pressed.

Shift Checks if the Shift key was pressed.

KeyCode Returns the key code of the key pressed.

KeyData Combines key code and modifier keys.

KeyValue Numeric value of the key pressed.

Handled Indicates whether the event was handled.

13. Explain ComboBox control with at least 5 of its unique properties


A ComboBox control combines a TextBox with a drop-down list, allowing users to
either type or select an item.
Unique Properties:
1. DropDownStyle: Specifies the ComboBox behavior (DropDown,
DropDownList).
2. Items: Stores all the list items in the ComboBox.
3. SelectedIndex: Index of the selected item.
4. SelectedItem: Gets or sets the currently selected item.
5. Sorted: Automatically sorts the items alphabetically.
The ComboBox is ideal for selecting from predefined options such as country
lists, categories, or settings.

14. Explain how to add, remove and clear items from a ListBox control with code
snippets
The ListBox control displays a list of items from which a user can select one or
more.
Adding items:
[Link]("Apple");
[Link]("Orange");
Removing an item:
[Link]("Apple");
Clearing all items:
[Link]();
This control is commonly used for displaying lists like products, names, or file
lists.

15. Explain any 5 unique properties of CheckedListBox


The CheckedListBox control is similar to a ListBox, but with checkboxes beside
each item.
Unique Properties:
1. CheckOnClick: Toggles the check state when the item is clicked.
2. CheckedItems: Returns the collection of checked items.
3. CheckedIndices: Returns indices of all checked items.
4. ThreeDCheckBoxes: Enables a 3D visual appearance.
5. SelectionMode: Defines how the user can select items (single or multiple).
This control is useful in scenarios like feature selection or preference settings.

16. Explain MDI form with relevant properties


An MDI (Multiple Document Interface) form allows multiple child forms to be
opened within a single parent window. It’s often used in applications like
Microsoft Word or Visual Studio.
Properties and Example:
 IsMdiContainer: Set to true for the parent form.
 [Link] = true;
 MdiParent: Assigns a parent form to a child form.
 Form child = new Form();
 [Link] = this;
 [Link]();
 ActiveMdiChild: Gets the currently active child form.
 MdiChildren: Returns an array of all child forms.
MDI applications allow better management of multiple open documents or
windows within a single interface.

You might also like