Lecture 08 - windowsform application
Lecture 08 - windowsform application
• Tool tip:
• A tooltip is a small pop-up window that displays some information when you rollover
on a control.
• Tooltip class represents a tooltip control. Once a tooltip object is created, we need to
call set tooltips method and pass a control and text.
Program with tool bar and status bar
Button
Check box
Text box
Status strip – status label
Tool strip – button, label
• private void btn_enter_Click(object sender, EventArgs e)
• {
• toolStripLabel1.Text = "You clicked the Enter button";
• }
By setting 1sBalloon to true it makes the tooltip balloon that looks like below
Dialog Boxes
• These are used to display information and prompt the user for data needed
to continue with the application three types are there.
• Predefined Dialog Box: Message Box.
• Customer Dialog Box: Created with forms for customizing an existing dialog box.
• Standard Dialog box: File, Print, Font, Save, open and colour.
• Standard Dialog boxes
• Colour Dialog: This contains different colours, enabling the user to choose the colour.
• Font Dialog: Contains all font, style and size to change the font of particular text.
• Save file dialog: Used to save a file.
• Open a file dialog: Used to open files of different extension which is required.
• Print Dialog: Used to display the print settings and print to the file.
Sample program for standard boxes
• private void btn_open_Click(object sender, EventArgs e)
• {
• openFileDialog1.ShowDialog();
• pictureBox1.SizeMode= PictureBoxSizeMode.StretchImage;
• pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
•
• }
• Validate the text Box(for Telephone Number) that user must enter 10
numbers.
• private void maskedTextBox1_MaskInputRejected(object sender,
MaskInputRejectedEventArgs e)
• {
• if(maskedTextBox1.Text.Length != 10)
• {
• MessageBox.Show("Wrong telephone number, Please check
it again","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
• }
• }
Validations using codes
• Validate the textbox if empty and if number entered(only characters can
enter)
• if(string.IsNullOrEmpty(txt_name.Text)||
txt_name.Text.Any(Char.IsDigit))
• {
• MessageBox.Show("Please enter your first name");
• }
• if(string.IsNullOrEmpty(txt_name.Text)||
txt_name.Text.Any(c=>char.IsNumber(c)))
• {
• MessageBox.Show("Please enter your first name");
• }
Validating using error provider