write Short program using C++ or C#. Create a forms UI for consisting of common
ID: 3812051 • Letter: W
Question
write Short program using C++ or C#.
Create a forms UI for consisting of common controls such as button, checkbox, combobox, datetimepicker, label, maskedtextbox, numericupdown, picturebox, radiobutton(s), textbox, progressbar; containers such as groupbox, tabcontrol; menu & toolbars such as menutrip. Establish your own control naming convention and assign default values as needed. Feel free to adjust control properties for aesthetics. You are not to include functionality and transactional codes.Explanation / Answer
Here , is the given code for all the basic UI in form using C#. Hope it helps.
1. Label Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "This is my first Label";
label1.BorderStyle = BorderStyle.FixedSingle;
label1.TextAlign = ContentAlignment.MiddleCenter;
}
}
}
2.Button Code
private void Form1_Load(object sender, EventArgs e)
{
Button b = new Button();
b.Click += new EventHandler(ShowMessage);
Controls.Add(b);
}
3. Combobox Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Sunday");
comboBox1.Items.Add("Monday");
comboBox1.Items.Add("Tuesday");
comboBox1.Items.Add("wednesday");
comboBox1.Items.Add("Thursday");
comboBox1.Items.Add("Friday");
comboBox1.Items.Add("Saturday");
comboBox1.SelectedIndex = comboBox1.FindStringExact("Sunday");
}
private void button1_Click(object sender, EventArgs e)
{
string var;
var = comboBox1.Text;
MessageBox.Show(var);
}
}
}
4.Checkbox
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string msg = "";
if (checkBox1.Checked == true)
{
msg = "net-informations.com";
}
if (checkBox2.Checked == true)
{
msg = msg + " vb.net-informations.com";
}
if (checkBox3.Checked == true)
{
msg = msg + " csharp.net-informations.com";
}
if (msg.Length > 0)
{
MessageBox.Show (msg + " selected ");
}
else
{
MessageBox.Show ("No checkbox selected");
}
checkBox1.ThreeState = true;
}
}
}
4.Radio Button Control
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
MessageBox.Show ("You are selected Red !! ");
return;
}
else if (radioButton2.Checked == true)
{
MessageBox.Show("You are selected Blue !! ");
return;
}
else
{
MessageBox.Show("You are selected Green !! ");
return;
}
}
}
}
5. Date-Time Picker Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dateTimePicker1.Format = DateTimePickerFormat.Short;
dateTimePicker1.Value = DateTime.Today;
}
private void button1_Click(object sender, EventArgs e)
{
DateTime iDate;
iDate = dateTimePicker1.Value;
MessageBox.Show("Selected date is " + iDate);
}
}
}
6.PictureBox Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("c:\testImage.jpg");
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
}
7. TextBox Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Width = 250;
textBox1.Height = 50;
textBox1.Multiline = true;
textBox1.BackColor = Color.Blue;
textBox1.ForeColor = Color.White;
textBox1.BorderStyle = BorderStyle.Fixed3D;
}
private void button1_Click(object sender, EventArgs e)
{
string var;
var = textBox1.Text;
MessageBox.Show(var);
}
}
}
8. MenuStrip Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void menu1ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("You are selected MenuItem_1");
}
}
}
9. ProgressBar Code
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
progressBar1.Minimum = 0;
progressBar1.Maximum = 200;
for (i = 0; i <= 200; i++)
{
progressBar1.Value = i;
}
}
}
}
10. Masked TextBox Code
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void maskedTextBox1_TypeValidationCompleted(object sender,TypeValidationEventArgs e)
{
DateTime value = (DateTime)e.ReturnValue;
MessageBox.Show("Validated: " + value.ToLongDateString());
}
}
}
11. GroupBox Code
using System.Drawing;
using System.Windows.Forms;
public class OperaForm : Form
{
private RadioButton radioButton1;
private RadioButton radioButton2;
private RadioButton radioButton3;
private GroupBox groupBox1;
public OperaForm()
{
this.groupBox1 = new GroupBox();
this.radioButton3 = new RadioButton();
this.radioButton2 = new RadioButton();
this.radioButton1 = new RadioButton();
// All three radio buttons are created like this
// For brevity only code for one button is included
this.radioButton3.BackColor = Color.Transparent;
this.radioButton3.Font = new Font("Microsoft Sans Serif",
8.25F, FontStyle.Bold);
this.radioButton3.ForeColor =
SystemColors.ActiveCaptionText;
this.radioButton3.Location = new Point(16, 80);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Text = "Parsifal";
// Group Box
this.groupBox1 = new GroupBox();
this.groupBox1.BackgroundImage =
Image.FromFile("C:\opera.jpg");
this.groupBox1.Size = new Size(120, 112);
// Add radio buttons to groupbox
groupBox1.Add( new Control[]{radioButton1,radiobutton2,
radioButton3});
}
}
12. TabControl Code
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// After initialize, select the second tab.
tabControl1.SelectTab("tabPage2");
// This is another way to select the second tab.
tabControl1.SelectedIndex = 1;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.