Dotnet - Unit 5

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Unit 5 – Dotnet

1. Write a program to create text box in windows form?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace my {

public partial class Form1 : Form {

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

// Creating and setting the properties of Lable1


Label Mylablel = new Label();
Mylablel.Location = new Point(96, 54);
Mylablel.Text = "Enter Name";
Mylablel.AutoSize = true;
Mylablel.BackColor = Color.LightGray;

// Add this label to form


this.Controls.Add(Mylablel);

// Creating and setting the properties of TextBox1


TextBox Mytextbox = new TextBox();
Mytextbox.Location = new Point(187, 51);
Mytextbox.BackColor = Color.LightGray;
Mytextbox.ForeColor = Color.DarkOliveGreen;
Mytextbox.AutoSize = true;
Mytextbox.Name = "text_box1";

// Add this textbox to form


this.Controls.Add(Mytextbox);
}
}
}

Output :

Enter Name
Name

2. Explain with an example the ThreeState property of Check Box?

public bool ThreeState { get; set; }

The ThreeState property alternates between true and false with


alternating clicks of the control and the CheckAlign alternates between
the MiddleRight and MiddleLeft values
of System.Drawing.ContentAlignment. This example shows how the
property values change as the ThreeState property changes and the
control is checked. This code requires that
a CheckBox, Label and Button have all been instantiated on a form and
that the label is large enough to display three lines of text, as well as a
reference to the System.Drawing namespace. This code should be called
in the Click event handler of the control.

private void AdjustMyCheckBoxProperties()

// Change the ThreeState and CheckAlign properties on every other click.

if (!checkBox1.ThreeState)

checkBox1.ThreeState = true;

checkBox1.CheckAlign = ContentAlignment.MiddleRight;

else

checkBox1.ThreeState = false;

checkBox1.CheckAlign = ContentAlignment.MiddleLeft;

}
// Concatenate the property values together on three lines.

label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +

"Checked: " + checkBox1.Checked.ToString() + "\n" +

"CheckState: " + checkBox1.CheckState.ToString();

3. Explain AutoCheck Property of Radio Button?

public bool AutoCheck { get; set; }

true if the Checked value and the appearance of the control automatically
change on the Click event; otherwise, false. The default value is true.

private void InitializeMyRadioButton()

// Create and initialize a new RadioButton.

RadioButton radioButton1 = new RadioButton();

// Make the radio button control appear as a toggle button.

radioButton1.Appearance = Appearance.Button;

// Turn off the update of the display on the click of the control.

radioButton1.AutoCheck = false;

// Add the radio button to the form.

Controls.Add(radioButton1);

If the Checked value is set to false, the RadioButton portion of the


control must be checked in code in the Click event handler. In
addition, if the RadioButton is part of a RadioButton control group,
this property ensures that only one of the controls is checked at a
given time.

If the AutoCheck property is set to false, a group


of RadioButton controls will not act as a mutually exclusive group
and the Checked property must be updated in code.
4. Explain BeginInvoke(Action), CreateControl(),GetChildAtPoint(Point,
GetChildAtPointSkip) and BeginInvoke(Delegate) method in Label Class?

BeginInvoke(Action)
Executes the specified delegate asynchronously on the thread that the
control's underlying handle was created on.

CreateControl()
Forces the creation of the visible control, including the creation of the handle
and any visible child controls.

GetChildAtPoint(Point, GetChildAtPointSkip)
Retrieves the child control that is located at the specified coordinates,
specifying whether to ignore child controls of a certain type.

BeginInvoke(Delegate)
Executes the specified delegate asynchronously on the thread that the
control's underlying handle was created on.

5. Explain BeginInit(),AdjustFormScrollbars(Boolean),
AccessibilityNotifyClients(AccessibleEvents, Int32) methods in NumericUpDown?

AccessibilityNotifyClients(AccessibleEvents, Int32)
Notifies the accessibility client applications of the
specified AccessibleEvents for the specified child control.

BeginInit()
Begins the initialization of a NumericUpDown control that is used on a form or
used by another component. The initialization occurs at run time.

AdjustFormScrollbars(Boolean)
Adjusts the scroll bars on the container based on the current control positions
and the control currently selected.

You might also like