Haha

Only available on StudyMode
  • Download(s) : 36
  • Published : April 9, 2013
Open Document
Text Preview
Practical 8

1. Create a Form that contains two buttons, one labeled Stop and one labeled Go. Add a label telling the user to click a button. When the user clicks Stop, change the BackColor of the Form to Red; when the user clicks Go, change the BackColor of the Form to Green.

namespace Practical8
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}

privatevoidbuttonStop_Click(object sender, EventArgs e)
{
this.BackColor = Color.Red;
}

privatevoidbuttonGo_Click(object sender, EventArgs e)
{
this.BackColor = Color.Green;
}
}
}

2. Create a Windows application that contains a button labeled OK and a textbox labeled Name. Change the properties of the Form to have different backgroundcolour of your choosing. Change the Font property to a font of your choice. Initially clear the text from the textbox. Align the controls nicely. Add an event handler for the button so that when the user clicks the OK button, the value entered is cleared, the form changes colour, and a message is displayed on the label prompting the user to enter their name.

namespace Practical_8
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}

privatevoidbuttonOk_Click(object sender, EventArgs e)
{
this.BackColor = Color.Lavender;
textBoxName.Clear();
MessageBox.Show("Enter Your Name");
}
}
}

3. Create a Windows application that sets the Form object properties of BackColor, Size, Location, Text, and AcceptButton. The form should contain one button labeled Click Me. When the user clicks the button, a MessageBox should be displayed indicating the button has been clicked.

namespace Practical_8
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}

privatevoidbuttonOk_Click(object sender, EventArgs e)
{
MessageBox.Show("The button has been clicked");
}
}
}

4.Create a Windows application that contains two textboxes and one button. The textboxes should be used to allow the user to input the x- and y-coordinates to indicate where the form should be positioned. When the user clicks the button, the window should be moved to that new point. Be sure to label the textboxes appropriately.

Hint: One way to do this is to set the location using an instance of the Point class when the user clicks the button. After the x and y values being retrieved and parsed/ converted to their integer equivalent, set the location by typing this.Location = new Point(x, y);

namespace Practical_8
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}

privatevoidbuttonClickMe_Click(object sender, EventArgs e)
{
int x;
int y;

if (textBoxX.Text != ""&&textBoxY.Text != "")
{
x = int.Parse(textBoxX.Text);
y = int.Parse(textBoxY.Text);
this.Location = newPoint(x, y);
}
}
}
}

5. Create a Windows application that contains textboxes for first name, last name, and title, plus one button. The textboxes should be used to allow the users to input their names. When the button is clicked, the usernames should be displayed in a label formatted with one space between the title, last name and first name.

namespace Practical_8
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}

privatevoidbuttonClickMe_Click(object sender, EventArgs e)
{
label.Text = title.Text + " " + fName.Text + " " + lName.Text; }
}
}

6. Create a Windows application that contains two textboxes and two buttons. One of thetextboxes and one of the buttons are initially invisible. The first textbox should be used to input a password. The textbox should be masked to some character of your choice so that the characters...
tracking img