Today here, I am describing how to create a Utility Box in Windows Application to open Digital Clock, Calculator, NotePad, Microsoft Word and OutLook inside windows form application.
Here, I have created my windows form like this.
Here, I have taken Button and within that button. I have set url for image of the button.
Under Digital clock button click write the following code for showing time.
- private void button6_Click(object sender, EventArgs e)
- {
- Label namelabel = new Label();
- namelabel.Location = new Point(200, 20);
-
- this.Controls.Add(namelabel);
- namelabel.Text = System.DateTime.Now.ToLongTimeString();
- }
Here after clicking it show the time as follow.
Now after clicking the "OUTLOOK" button write that following code for showing the outlook inside the windows form.
- private void button5_Click(object sender, EventArgs e)
- {
- CreateMailItem();
- }
-
- private void CreateMailItem()
- {
- Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
- Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem) oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
- mailItem.Subject = "This is the test message";
- mailItem.To = "[email protected]";
- mailItem.CC = "[email protected]";
- mailItem.Body = "This is the test message";
- mailItem.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
- mailItem.Display(false);
- mailItem = null;
- oApp = null;
- }
Now after clicking Outlook button it will show the outlook as follow.
For generating Microsoft word just write the following code on double click the Microsoft word button.
- private void button3_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("winword");
- }
So it will show the word as following.
Now for calculator write the following code on calculator button click.
- private void button1_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("calc");
- }
For NotePad write the following code.
- private void button2_Click(object sender, EventArgs e)
- {
- System.Diagnostics.Process.Start("notepad");
- }
Now for Logout the application write the following code.
- private void button7_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("Do you Want to Exit?", "Confirm Box", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
- {
- this.Close();
- }
- else
- {}
- }
So it will show like this.
Thus in this way we can create the utility box.