Date Validation In Datagridview


Validate Date in particular cell

private void dgvBreakageExp_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (dgvBreakageExp.Columns[e.ColumnIndex].Name == "InvoiceDate" || dgvBreakageExp.Columns[e.ColumnIndex].Name == "ExpDate")
{
if (e.FormattedValue == null || e.FormattedValue.ToString() == "")
{
dgvBreakageExp[e.ColumnIndex, e.RowIndex].ErrorText = null;
return;
}
bool res = ValidateDate(e.FormattedValue.ToString());
if (res == false)
{
dgvBreakageExp[e.ColumnIndex, e.RowIndex].ErrorText = "Invalid Date,Date Should be('DD/MM/YYYY')";
dgvBreakageExp.EndEdit();
e.Cancel = true;
}
else
{
dgvBreakageExp[e.ColumnIndex, e.RowIndex].ErrorText = null;
e.Cancel = false;
}
}
}
//function for validate the date and return true or false
private bool ValidateDate(string date)
{
try
{
DateTime Test;
if (DateTime.TryParseExact(date, "dd/MM/yyyy", null, DateTimeStyles.None, out Test) == true)
{
return true;

}
 else
 {
 return false;
 }
 }
 catch
 {
 return false;
 }
 }

Advertisements

Custome DataGridView with Row Number and Alternate Row Color


class InfynetDgv : DataGridView
 {
 protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
 {
 this.SuspendLayout();
 base.OnRowPostPaint(e);

// get the row number in leading zero format,
 // where the width of the number = the width of the maximum number
 int RowNumWidth = this.RowCount.ToString().Length;
 StringBuilder RowNumber = new StringBuilder(RowNumWidth);
 RowNumber.Append(e.RowIndex + 1);
 while (RowNumber.Length < RowNumWidth)
 RowNumber.Insert(0, "0");
 // get the size of the row number string
 SizeF Sz = e.Graphics.MeasureString(RowNumber.ToString(), this.Font);
 // adjust the width of the column that contains the row header cells
 if (this.RowHeadersWidth < (int)(Sz.Width + 20))
 this.RowHeadersWidth = (int)(Sz.Width + 20);
 // draw the row number
 e.Graphics.DrawString(
 RowNumber.ToString(),
 this.Font,
 SystemBrushes.ControlText,
 e.RowBounds.Location.X + 15,
 e.RowBounds.Location.Y + ((e.RowBounds.Height - Sz.Height) / 2));
 this.ResumeLayout();

}

protected override void OnCellFormatting(DataGridViewCellFormattingEventArgs e)
 {
 this.SuspendLayout();
 base.OnCellFormatting(e);
 var dataGridView = this;

e.CellStyle.Font = new Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular);
 this.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(212, 255, 212);
 if (dataGridView.Rows[e.RowIndex].Selected)
 {
 e.CellStyle.Font = new Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold);
 e.CellStyle.SelectionBackColor = Color.FromArgb(123,123,123);
 }
 DataGridViewCellStyle style = this.ColumnHeadersDefaultCellStyle;

style.BackColor = Color.FromArgb(137,137,137);
 style.ForeColor = Color.White;
 style.Padding= new Padding(3,3,3,3);
 style.Font = new Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold);
 this.ResumeLayout();

}

}

TextBox TextChanged Event on DataGridView Cell


private void dgvPurItem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
 {
 int colIndex;
 int rowIndex;
 var txtBox = e.Control as TextBox;
 colIndex = dgvPurItem.CurrentCell.ColumnIndex;
 rowIndex = dgvPurItem.CurrentCell.RowIndex;
 if (e.Control is TextBox)
 {
  if (txtBox != null)
  {

   txtBox.CharacterCasing = CharacterCasing.Upper;
   txtBox.TextChanged += new EventHandler(ItemTxtBox_TextChanged);
   txtBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
   txtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
   txtBox.AutoCompleteCustomSource.Add("Item 1");
   txtBox.AutoCompleteCustomSource.Add("Item 2");
   txtBox.AutoCompleteCustomSource.Add("Item 3");
  }
 }
}

Continue reading

ASP.net,C# Code For Sending An Email using Gmail and Hotmail


ASP.net,C# Code Send Mail From GMail Account

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
  protected void btn_Click(object sender, EventArgs e)
    {
       MailMessage MyMailMessage = new MailMessage("FromMailId@gmail.com", "TOMailId@hotmail.com",
"write your subject Here ", "Hi,This is the test message ");
MyMailMessage.IsBodyHtml = false;
NetworkCredential mailAuthentication = new NetworkCredential("FromMailId@gmail.com", "Password");
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
        mailClient.EnableSsl = true;
        mailClient.UseDefaultCredentials = false;
        mailClient.Credentials = mailAuthentication;
        mailClient.Send(MyMailMessage);
     }
}

Continue reading

Data Grid View With Textbox And Edit (Insert, Update, Delete) Option


In this demo use a grid view ,text boxes, buttons(Add, delete, update, cancel ) and Ajax calendar extender.

Use one table called “empinfo” it has 4 field

  1.       Id it is integer type and identity
  2.       Name it is nvarchar(100) for employee name
  3.       email_id it is nvarchar(300) for employee email id
  4.       dob it is nvarchar(20)  for employee date of birth

Continue reading

Add SQL parameter at run time using store procedure in c#


Code for add SQL Parameter at run time using store procedure in c#

SqlConnection connection;
SqlCommand command = new SqlCommand();
string connectionstring;
SqlParameter paraName = new SqlParameter();
public void addparameter(string prameterName, string prameterValue)
{
paraName.ParameterName = prameterName;
paraName.Value = prameterValue;
command.Parameters.Add(paraName);
}

Crystal report in C#


“ open visual studio and select new project from file menu”

“ Select the Language c# and select the window application give the name to your project and select the
path where the project will save ”

“After the opening the project first create the database from server explore”

“Right click on the data connection and select the Create New SQL SERVER Database then create SQL server
database window will open”

“Select the server name or if you are using the local server just give”.” In Log on to the server if you give the username or password in sql then select the sql server authentication or use windows authentication mode   ,write the new database name in textbox you find it down side. ”

“now we going to create the table in the database called info just right click on the table folder you find it inside the server Explorer then select the add new table”

“Give the column name and its data type after this save the table by clicking the save button or CTRL+s”

“After clicking the save button one window will be open called choose name within it give the table name ‘emp’”

“Ok now your table will be created then what? Fill that table by right clicking on the emp table and choose the show table data from emp table in the server explorer”

“Enter some record in the emp table and the click on ‘!’ this”

“now the big work start in your right side open the solution explorer right click on the project  go to add and click the add new item.”

“Add new item window will open and select the crystal report give it name and click add button. after clicking it crystal report gallery will open. ”

“Select blank report and click ok button”

“After it select your form and in toolbox drag the crystalReportViewer in your form not in crystal report and drag one button in your form”

“Your form will look like this”.

“Go to data in menu and select the add new data source now data source configuration wizard will open and select the data base, click next button”

“Now if you have make new connection click the new connection button click continue”

“Give server name or ‘.’ And select the database which is created I select info database  which is created at the begging  and test your connection by clicking in the test connection if all thing is going right click ok button then click next in the data source configuration wizard”

“Give the connection string and again next button click”

“Select the table object called emp and its fields”

“Now go to your crystal report and open field explore right click on the data field and click the database expert”

“Now the window will open, project data >>ado.net database >>select your table”

“Open file explore and drag and drop the field in your data base”

“After dragging the field your crystal report looks like that”

“Now I form double click on the button and write the following code for making the connection and crystal report set the report source to the crystal report viewer for making the database connection read previous post.

private void button1_Click(object sender, EventArgs e)

{

string conn = "Data Source=.;Initial Catalog=info;Integrated Security=True;Pooling=False";

SqlConnection CN =new SqlConnection(conn);

CrystalReport1 crt = new CrystalReport1();

string sql = null;

if (CN.State == ConnectionState.Open)

CN.Close();

CN.Open();

sql = "select * from emp";

SqlDataAdapter dscmd = new SqlDataAdapter(sql, CN);

infoDataSet ds = new infoDataSet();

dscmd.Fill(ds, "emp");

crt.SetDataSource(ds);

crystalReportViewer1.ReportSource = crt;

}

 

If Unable to add reference file in visual studio 2010


If you are adding the reference file in visual studio. 2010 and after adding it show the error change the .net 4 client framework to .net 4 framework.
Select <project name>property (eg. Data property) from project in menu bar, then you find this window and select “application tag” and change the” target framework” from “.NET 4 Framework  client profile” to “.NET 4 Framework”.

Database connection with C#


To connect the database with c#(vs 2010) is very easy I connect my database to c# using the query method and add the data grid vied in project to display the table content.
To connect the c# apps to SQL data base use the following steps:

1)      Write this code in using part  “using System.Data.SqlClient;”

2)      Declare one variable connection string type.

3)      Declare SQLconnection():it make connection between database and c# Apps

4)      Declare SQL command(): for execute the command.

5)      Declare SqldataAdapter() for binding the connection with database

6)      Declare dataset.

Download you can download this Example from: http://www.4shared.com/file/TnR6qUzE/data.html

Code for display the data in data grid view:

        if(dataGridView1.DataSource != null)
               ((DataView)dataGridView1.DataSource).Table.Clear();
con = new SqlConnection(connection);
qry = "select * from customer";
if (con.State == ConnectionState.Open)
    con.Close();
 else
     con.Open();
sda = new SqlDataAdapter(qry, con);
sda.Fill(ds, "customer");
this.dataGridView1.DataSource = ds.Tables["customer"].DefaultView;
dataGridView1.Columns[1].ReadOnly = true;

this Code will check the data grid view is null or not if it is not null then it’s clear the data:

</pre>
if(dataGridView1.DataSource != null)
((DataView)dataGridView1.DataSource).Table.Clear();

Code for insert the record in table:

qry = "insert into customer values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
con = new SqlConnection(connection);
cmd = new SqlCommand(qry, con);
if (con.State == ConnectionState.Open)
con.Close();
else
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Recored is inserted");

Code for update the record:


qry = "update customer set id='" + textBox1.Text + "',name='" + textBox2.Text + "',number='" + textBox3.Text + "',email='" + textBox4.Text + "'where id='" + textBox1.Text + "'";

con = new SqlConnection(connection);cmd = new SqlCommand(qry, con);

if (con.State == ConnectionState.Open)
con.Close();

else

con.Open();

if( cmd.ExecuteNonQuery()==1)

MessageBox.Show("Recored is update");

else

MessageBox.Show("unable to update or Id not found.");

con.Close();

Code for delete the record:


qry = "delete from customer where id='" + textBox1.Text + "'";

con = new SqlConnection(connection);

cmd = new SqlCommand(qry, con);

if (con.State == ConnectionState.Open)

con.Close();

else

con.Open();

if (cmd.ExecuteNonQuery() == 1)

MessageBox.Show("Recored is deleted");

else

MessageBox.Show("unable to delete record or Id not found.");

con.Close();

when we check the sql connection is open or not if it is open the close the connection

            if (con.State == ConnectionState.Open)
                con.Close();

qry = “delete from customer where id='” + textBox1.Text + “‘”;

con = new SqlConnection(connection);

cmd = new SqlCommand(qry, con);

if (con.State == ConnectionState.Open)

con.Close();

else

con.Open();

if (cmd.ExecuteNonQuery() == 1)

MessageBox.Show(“Recored is deleted”);

else

MessageBox.Show(“unable to delete record or Id not found.”);

con.Close();

FTP using c#.net 2010


Shipper (file transfer) project is developed in c#.net (vs 2010).it use the file transfer protocol to send the file from one computer to another computer.as a small project it is able to send only limited size of file.
it is combination of two project one is shipper sever and other one is Shipper client. First discus the Shipper server part.

Download:

You can download this project from: http://www.4shared.com/file/4ha5NFj0/networking_project.html

Shipper Server

In shipper sever has two mode one is send file and second is receive file.

Send file mode: in this mode server will read to send the file to client.

And

In Receive mode: Server is ready to receive the file from client.

But the question is how?

Ans is when server is set to send mode first select the file which is send to client and give client IP address and port number.

To send the files then start the server.

Same steps will be follow when we receive the file from client but u select the path where the file will store.

Screen Shot:

Welcome screen:

Server screen


Codding:

For sending the file: we declare these namespace at the top of the project file

<br />
using System.Net;<br />
using System.Net.Sockets;<br />
using System.IO;<br />
try<br />
{<br />
IPEndPoint ipEnd;<br />
Socket sock;<br />
ipEnd = new IPEndPoint(IPAddress.Any, Convert.ToInt32( txt_port.Text));<br />
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);<br />
sock.Bind(ipEnd);<br />
msgsender = &quot;Starting...&quot;;<br />
sock.Listen(100);<br />
msgsender = &quot;Running and waiting to Send  The file.&quot;;<br />
clientSock = sock.Accept();<br />
string fileName = Path.GetFileName(dlg_open.FileName);<br />
string filePath = Path.GetDirectoryName(dlg_open.FileName);<br />
byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);<br />
if (fileNameByte.Length &gt; 850 * 1024)<br />
{<br />
lst_sserver.Items.Add(&quot;File size is more than 850kb, please try with small file.&quot;);<br />
return;<br />
}<br />
byte[] fileData = File.ReadAllBytes(filePath + &quot;\\&quot; + fileName);<br />
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];<br />
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);<br />
msgsender = &quot;Sending data...&quot;;<br />
fileNameLen.CopyTo(clientData, 0);<br />
fileNameByte.CopyTo(clientData, 4);<br />
fileData.CopyTo(clientData, 4 + fileNameByte.Length);<br />
clientSock.Send(clientData);<br />
clientSock.Close();<br />
msgsender = &quot;File send.&quot;;<br />
msgsender = &quot;Connection close.&quot;;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(&quot;Unable to send the file.&quot; + ex.Message);<br />
}<br />

Description:

“IPEndPoint” Represents a network endpoint as an IP address and a port number. It’s come under the System.Net. And “Socket” initializes a new instance of the Socket class using the specified value.

Sock.bind(ipend) is use to bind the connection. After the binding the connection set the listing state of socket which is 100. After that select the file and file file path get the file size in bytes and check if it is more than 850 kb then display the error message if it not then send the file to client data. Server socket and client socket number will be same when the server is sending the file or receiving the file from client it’s the short description of the server part code.

Shipper Client

In shipper client it has two parts one is download and other one is uploading. When client is uploading the file it selects the file and give server IP address and port number then click the upload button.when it want to download a file it select the path where the file will be store.

Screen shot

Client screen

Codding

Download part:

</p>
<p>try</p>
<p>{</p>
<p>lst_client.Items.Add(&quot;Buffering ...&quot;);</p>
<p>IPAddress[] ipAddress = Dns.GetHostAddresses(txt_ipaddress.Text);</p>
<p>IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], Convert.ToInt32(txt_port.Text));</p>
<p>Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);</p>
<p>lst_client.Items.Add( &quot;Connection to server ...&quot;);</p>
<p>clientSock.Connect(ipEnd);</p>
<p>byte[] clientData = new byte[1024 * 5000];</p>
<p>string receivedPath = dlg_folderbrowser.SelectedPath;</p>
<p>int receivedBytesLen = clientSock.Receive(clientData);</p>
<p>int fileNameLen = BitConverter.ToInt32(clientData, 0);</p>
<p>string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);</p>
<p>lst_client.Items.Add(&quot;File Reciving...&quot;);</p>
<p>BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + &quot;\\&quot; + fileName, FileMode.Append));</p>
<p>bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);</p>
<p>bWrite.Close();</p>
<p>lst_client.Items.Add(&quot;Disconnecting....&quot;);</p>
<p>clientSock.Close();</p>
<p>lst_client.Items.Add(&quot;File Recived. from:&quot; + txt_ipaddress.Text + &quot;.&quot;);</p>
<p>}</p>
<p>catch (Exception ex)</p>
<p>{</p>
<p>MessageBox.Show(&quot;Unable to recive the file.&quot; + ex.Message, &quot;Shipper Client&quot;, MessageBoxButtons.OK, MessageBoxIcon.Error);</p>
<p>}</p>
<p>

Upload part:

</p>
<p>try</p>
<p>{</p>
<p>if(x==0)</p>
<p>{</p>
<p>try</p>
<p>{</p>
<p>IPAddress[] ipAddress = Dns.GetHostAddresses(txt_ipaddress.Text);</p>
<p>IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], Convert.ToInt32(txt_port.Text));</p>
<p>Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);</p>
<p>string fileName = dlg_open.FileName;</p>
<p>string filePath = &quot;&quot;;</p>
<p>fileName = fileName.Replace(&quot;\\&quot;, &quot;/&quot;);</p>
<p>while (fileName.IndexOf(&quot;/&quot;) &gt; -1)</p>
<p>{</p>
<p>filePath += fileName.Substring(0, fileName.IndexOf(&quot;/&quot;) + 1);</p>
<p>fileName = fileName.Substring(fileName.IndexOf(&quot;/&quot;) + 1);</p>
<p>}</p>
<p>byte[] fileNameByte = Encoding.ASCII.GetBytes(fileName);</p>
<p>if (fileNameByte.Length &gt; 850 * 1024)</p>
<p>{</p>
<p>lst_client.Items.Add(&quot;File size is more than 850kb, please try with small file.&quot;);</p>
<p>return;</p>
<p>}</p>
<p>lst_client.Items.Add(&quot;Buffering ...&quot;);</p>
<p>byte[] fileData = File.ReadAllBytes(filePath + fileName);</p>
<p>byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];</p>
<p>byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);</p>
<p>fileNameLen.CopyTo(clientData, 0);</p>
<p>fileNameByte.CopyTo(clientData, 4);</p>
<p>fileData.CopyTo(clientData, 4 + fileNameByte.Length);</p>
<p>lst_client.Items.Add(&quot;Connection to server ...&quot;);</p>
<p>clientSock.Connect(ipEnd);</p>
<p>lst_client.Items.Add(&quot;File sending...&quot;);</p>
<p>clientSock.Send(clientData);</p>
<p>lst_client.Items.Add(&quot;Disconnecting...&quot;);</p>
<p>clientSock.Close();</p>
<p>lst_client.Items.Add(&quot;File transferred.&quot;);</p>
<p>}</p>
<p>catch (Exception ex)</p>
<p>{</p>
<p>MessageBox.Show(&quot;File Sending fail.&quot; + ex.Message,&quot;Shipper Client&quot;,MessageBoxButtons.OK,MessageBoxIcon.Error);</p>
<p>}</p>
<p>

Description: when we download some file from server it connects the server by giving the server IP address and its port number. “BinaryWriter” is responsible for receiving the file from server first it bind the connections using the IP address and port number. And receive the file from server byte by byte.
When we upload the file it will be done in three steps. First file length will be send to server, second file name will copy to server, it will create the file on server then the data will upload to the server using the “fileData.CopyTo()”.

Shutdown Computer Using C#.net(Cessation)


Cessation
Cessation is the project which is able to shut down your computer or reboot and perform many tasks like logoff, switch user, sleep, hibernate just one click but don’t forget to set the time for task. I use this project when I want to shut down my computer when some downloading finished. I this project is developed in c#.net 2010.
Download
You can get this project by open this link http://www.4shared.com/file/XqTzCYuH/cessation.html
Description
When developing this project I use Radio button, panels, timer, button, tools tip, notification, Doman up down components.Radio button: radio button is use to select the task it may be shut down etc…Timer is use to track the time and trigger the code of your selected task.One reset button is use to reset the application fields and abort the task.Tool tip is use to show the tip on particular components.Notification in use to send my APPs to notification area.Domain up down component is to select the hour minutes and seconds and AM/PM.

Note: Don’t forget to include user32.dll file, write this code after the class.

<br />
[DllImport(&quot;user32.dll&quot;)]<br />
 public static extern void LockWorkStation();<br />
 [DllImport(&quot;user32.dll&quot;)]<br />
 public static extern int ExitWindowsEx(int uFlags, int dwReason);<br />

Screen shot

Main form

Popup window

About Me

here the following code for shutdown,reboot, log-off,lock,switch user,hibernate,sleep

<br />
//Code for shutdown:<br />
System.Diagnostics.Process.Start(&quot;shutdown&quot;, &quot;/s /f /t 0&quot;);<br />
//Code for reboot<br />
System.Diagnostics.Process.Start(&quot;shutdown&quot;, &quot;/r /f /t 0&quot;);<br />
//Code for sleep:<br />
Application.SetSuspendState(PowerState.Suspend, true, true);<br />
//Code for logoff:<br />
ExitWindowsEx(0, 0);<br />
//Code for lock the computer:<br />
LockWorkStation();<br />
//Code for hibernate<br />
Application.SetSuspendState(PowerState.Hibernate, true, true);<br />

Display Current System Time

For displaying the current system time the following code is responsible,Timer1 code is trigger every one second

<br />
private void timer1_Tick(object sender, EventArgs e)<br />
 {<br />
 lbl_time.Text = Convert.ToString(DateTime.Now.ToLongTimeString());<br />
 }<br />

Displaying the message:

This code is responsible for display the default message on the status area.

<br />
private void tm_msg_Tick(object sender, EventArgs e)<br />
 {<br />
 lbl_msg.ForeColor = Color.Black;<br />
 lbl_msg.Text = &quot;Set Time and opration for performe the Task.&quot;;<br />
 tm_msg.Enabled = false;<br />
 }<br />

Check all the input is properly given or not

For checking all the input is proper given or not . Time and task is set or not if it is set then display the message like “your computer will be shut down at 12:00:00 pm” and display the popup window, and show notify tool tip.Trace the time and complete the peration This code is trace the time if the given time and system time is match then it execute the given task code.

<br />
private void tm_setgo_Tick(object sender, EventArgs e)<br />
{<br />
string tm = (ud_hh.Text + &quot;:&quot; + ud_mm.Text + &quot;:&quot; + ud_ss.Text + &quot; &quot; + ud_pa.Text);<br />
if (flag == true &amp;amp;&amp;amp; flag2 == true &amp;amp;&amp;amp; tm == Convert.ToString(DateTime.Now.ToLongTimeString()))<br />
{<br />
tm_setgo.Enabled = false;<br />
if (rd_hiber.Checked == true)<br />
{<br />
frm_cess.Show();<br />
Application.SetSuspendState(PowerState.Hibernate, true, true);<br />
msg = &quot;Hibernate&quot;;<br />
}<br />
if (rd_lock.Checked == true)<br />
{<br />
cessation_task fm_cess=new cessation_task();<br />
fm_cess.Show();<br />
LockWorkStation();<br />
msg = &quot;Lock&quot;;<br />
}<br />
if (rd_logoff.Checked == true)<br />
{<br />
cessation_task fm_cess = new cessation_task();<br />
fm_cess.Show();<br />
ExitWindowsEx(0, 0);<br />
msg = &quot;Logoff&quot;;<br />
}<br />
if (rd_res.Checked == true)<br />
{<br />
cessation_task fm_cess = new cessation_task();<br />
frm_cess.Show();<br />
System.Diagnostics.Process.Start(&quot;shutdown&quot;, &quot;/r /f /t 0&quot;);<br />
msg = &quot;Reboot&quot;;<br />
}<br />
if (rd_sleep.Checked == true)<br />
{<br />
cessation_task fm_cess = new cessation_task();<br />
fm_cess.Show();<br />
Application.SetSuspendState(PowerState.Suspend, true, true);<br />
msg = &quot;Sleep&quot;;<br />
}<br />
if (rd_sh.Checked == true)<br />
{<br />
cessation_task fm_cess = new cessation_task();<br />
fm_cess.Show();<br />
System.Diagnostics.Process.Start(&quot;shutdown&quot;, &quot;/s /f /t 0&quot;);<br />
msg = &quot;Shutdown&quot;;<br />
}<br />
}<br />
}<br />

Send for to notify area and display the pop up window

To hide the form and display the notification and popup window the following code is responsible

For tracing the window state define one function definition in form1.designer.cs File inside the private void InitializeComponent() Function.

<br />
private void mn_cessation_Resize(object sender, EventArgs e)<br />
{<br />
if (this.WindowState == FormWindowState.Minimized)<br />
{<br />
this.Hide();<br />
if(msg!=&quot;&quot;)<br />
frm_cess.Show();<br />
}<br />
}<br />

Main form(form1.cs ) source code

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.InteropServices;<br />
using System.Management;<br />
namespace cessation<br />
{<br />
 public partial class mn_cessation : Form<br />
{<br />
 // Importing Windows API library<br />
 [DllImport(&quot;user32.dll&quot;)]<br />
 public static extern void LockWorkStation();<br />
 [DllImport(&quot;user32.dll&quot;)]<br />
 public static extern int ExitWindowsEx(int uFlags, int dwReason);<br />
 bool flag=false;<br />
 bool flag2=false;<br />
 string msg;<br />
 int flg=0;<br />
 cessation_task frm_cess = new cessation_task();<br />
 public mn_cessation()<br />
 {<br />
 InitializeComponent();<br />
 }<br />
 private void mn_cessation_Load(object sender, EventArgs e)<br />
 {<br />
 msg = &quot;&quot;;<br />
 tm_time.Enabled = true;<br />
 }<br />
private void mn_cessation_Resize(object sender, EventArgs e)<br />
{<br />
 if (this.WindowState == FormWindowState.Minimized)<br />
 {<br />
 this.Hide();<br />
 if(msg!=&quot;&quot;)<br />
 frm_cess.Show();<br />
 }<br />
 }<br />
 private void timer1_Tick(object sender, EventArgs e)<br />
 {<br />
 lbl_time.Text = Convert.ToString(DateTime.Now.ToLongTimeString());<br />
 }<br />
 private void btn_rst_Click(object sender, EventArgs e)<br />
 {<br />
 btn_rst.Size = new Size(30, 27);&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;<br />
 reset();<br />
 btn_rst.Size = new Size(29, 26);<br />
 }<br />
 private void btn_rst_MouseLeave(object sender, EventArgs e)<br />
 {<br />
 btn_rst.Size = new Size(29, 26);<br />
 }<br />
 private void btn_rst_MouseHover(object sender, EventArgs e)<br />
 {<br />
 btn_rst.Size = new Size(30, 27);<br />
 }<br />
 public void reset()<br />
 {<br />
 msg = &quot;&quot;;<br />
 ud_hh.Text = &quot;&quot;;<br />
 ud_mm.Text = &quot;&quot;;<br />
 ud_ss.Text = &quot;&quot;;<br />
 ud_pa.Text = &quot;&quot;;<br />
 rd_hiber.Checked = false;<br />
 rd_lock.Checked = false;<br />
 rd_logoff.Checked = false;<br />
 rd_res.Checked = false;<br />
 rd_sh.Checked = false;<br />
 rd_sleep.Checked = false;<br />
 tm_msg.Enabled = true;<br />
 lbl_msg.ForeColor = Color.Blue;<br />
 lbl_msg.Text = &quot;Time and Operation will reset and task will be cancelled.&quot;;<br />
 flag2 = false;<br />
 flag = false;<br />
 }<br />
 private void rd_sh_CheckedChanged(object sender, EventArgs e)<br />
 {<br />
 if (rd_sh.Checked == true)<br />
 {<br />
 pic_oper.Visible = false;<br />
 pic_opr.Visible = true;<br />
 flag2 = true;<br />
 tm_setgo.Enabled = true;<br />
 msg = &quot;Shutdown&quot;;<br />
 }<br />
 if (rd_sh.Checked == false)<br />
 {<br />
 pic_oper.Visible = true;<br />
 pic_opr.Visible = false;<br />
 }<br />
 }<br />
 private void tm_msg_Tick(object sender, EventArgs e)<br />
 {<br />
 lbl_msg.ForeColor = Color.Black;<br />
 lbl_msg.Text = &quot;Set Time and opration for performe the Task.&quot;;<br />
 tm_msg.Enabled = false;<br />
 }<br />
 private void tm_check_Tick(object sender, EventArgs e)<br />
 {<br />
 if (ud_hh.Text == &quot;&quot; &amp;amp;&amp;amp; ud_mm.Text == &quot;&quot; &amp;amp;&amp;amp; ud_ss.Text == &quot;&quot; &amp;amp;&amp;amp; ud_pa.Text == &quot;&quot;)<br />
 {<br />
 pic_tmr.Visible = false;<br />
 pic_tmer.Visible = true;<br />
 flag = false;<br />
 }<br />
 if (ud_hh.Text != &quot;&quot; &amp;amp;&amp;amp; ud_mm.Text != &quot;&quot; &amp;amp;&amp;amp; ud_ss.Text != &quot;&quot; &amp;amp;&amp;amp; ud_pa.Text != &quot;&quot;)<br />
 {<br />
 DateTime d = DateTime.Now;<br />
 pic_tmr.Visible = true;<br />
 pic_tmer.Visible = false;<br />
 flag = true;<br />
 if (msg != &quot;&quot;)<br />
 {<br />
 int hh, mm, ss;<br />
 string tm;<br />
 tm = (ud_hh.Text + &quot;:&quot; + ud_mm.Text + &quot;:&quot; + ud_ss.Text + &quot; &quot; + ud_pa.Text);<br />
 lbl_msg.Text = &quot;Your computer will &quot; + msg + &quot; at &quot; + tm;<br />
 nty_cess.Text = &quot;Your computer will &quot; + msg + &quot; at &quot; + tm;<br />
 frm_cess.msg(lbl_msg.Text);<br />
 if (flg == 0)<br />
 {<br />
 nty_cess.ShowBalloonTip(1000, &quot;cessation&quot;, &quot;Your computer will &quot; + msg + &quot; at &quot; + tm , ToolTipIcon.Info);<br />
 flg++;<br />
 }<br />
 }<br />
 }<br />
 tm_check.Enabled = true;<br />
 }<br />
private void rd_hiber_CheckedChanged(object sender, EventArgs e)<br />
 {<br />
 if (rd_hiber.Checked == true)<br />
 {<br />
 pic_oper.Visible = false;<br />
 pic_opr.Visible = true;<br />
 flag2 = true;<br />
 msg = &quot;Hibernate&quot;;<br />
 tm_setgo.Enabled = true;<br />
 }<br />
 if (rd_hiber.Checked == false)<br />
 {<br />
 pic_oper.Visible = true;<br />
 pic_opr.Visible = false;<br />
 }<br />
 }<br />
 private void rd_lock_CheckedChanged(object sender, EventArgs e)<br />
 {<br />
 if (rd_lock.Checked == true)<br />
 {<br />
 pic_oper.Visible = false;<br />
 pic_opr.Visible = true;<br />
 flag2 = true;<br />
 msg = &quot;Lock&quot;;<br />
 tm_setgo.Enabled = true;<br />
 }<br />
 if (rd_lock.Checked == false)<br />
 {<br />
 pic_oper.Visible = true;<br />
 pic_opr.Visible = false;<br />
 }<br />
 }<br />
 private void rd_logoff_CheckedChanged(object sender, EventArgs e)<br />
 {<br />
 if (rd_logoff.Checked == true)<br />
 {<br />
 pic_oper.Visible = false;<br />
 pic_opr.Visible = true;<br />
 flag2 = true;<br />
 msg = &quot;Logoff&quot;;<br />
 tm_setgo.Enabled = true;<br />
 }<br />
 if (rd_logoff.Checked == false)<br />
 {<br />
 pic_oper.Visible = true;<br />
 pic_opr.Visible = false;<br />
 }<br />
 }<br />
 private void rd_res_CheckedChanged(object sender, EventArgs e)<br />
 {<br />
 if (rd_res.Checked == true)<br />
 {<br />
 pic_oper.Visible = false;<br />
 pic_opr.Visible = true;<br />
 flag2 = true;<br />
 msg = &quot;Reboot&quot;;<br />
 tm_setgo.Enabled = true;<br />
 }<br />
 if (rd_res.Checked == false)<br />
 {<br />
 pic_oper.Visible = true;<br />
 pic_opr.Visible = false;<br />
 }<br />
 }<br />
 private void rd_sleep_CheckedChanged(object sender, EventArgs e)<br />
 {<br />
 if (rd_sleep.Checked == true)<br />
 {<br />
 pic_oper.Visible = false;<br />
 pic_opr.Visible = true;<br />
 flag2 = true;<br />
 msg = &quot;Sleep&quot;;<br />
 tm_setgo.Enabled = true;<br />
 }<br />
 if (rd_sleep.Checked == false)<br />
 {<br />
 pic_oper.Visible = true;<br />
 pic_opr.Visible = false;<br />
 }<br />
 }<br />
 private void tm_setgo_Tick(object sender, EventArgs e)<br />
 {<br />
 string tm = (ud_hh.Text + &quot;:&quot; + ud_mm.Text + &quot;:&quot; + ud_ss.Text + &quot; &quot; + ud_pa.Text);<br />
 if (flag == true &amp;amp;&amp;amp; flag2 == true &amp;amp;&amp;amp; tm == Convert.ToString(DateTime.Now.ToLongTimeString()))<br />
 {<br />
 tm_setgo.Enabled = false;<br />
 if (rd_hiber.Checked == true)<br />
 {<br />
 frm_cess.Show();<br />
 Application.SetSuspendState(PowerState.Hibernate, true, true);<br />
 msg = &quot;Hibernate&quot;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;<br />
 }<br />
 if (rd_lock.Checked == true)<br />
 {<br />
 cessation_task fm_cess=new cessation_task();<br />
 fm_cess.Show();<br />
 LockWorkStation();<br />
 msg = &quot;Lock&quot;;<br />
 }<br />
 if (rd_logoff.Checked == true)<br />
 {<br />
 cessation_task fm_cess = new cessation_task();<br />
 fm_cess.Show();<br />
 ExitWindowsEx(0, 0);<br />
 msg = &quot;Logoff&quot;;<br />
 }<br />
 if (rd_res.Checked == true)<br />
 {<br />
 cessation_task fm_cess = new cessation_task();<br />
 fm_cess.Show();<br />
 System.Diagnostics.Process.Start(&quot;shutdown&quot;, &quot;/r /f /t 0&quot;);<br />
 msg = &quot;Reboot&quot;;<br />
 }<br />
 if (rd_sleep.Checked == true)<br />
 {<br />
 cessation_task fm_cess = new cessation_task();<br />
 fm_cess.Show();<br />
 Application.SetSuspendState(PowerState.Suspend, true, true);<br />
 msg = &quot;Sleep&quot;;<br />
 }<br />
 if (rd_sh.Checked == true)<br />
 {<br />
 cessation_task fm_cess = new cessation_task();<br />
 fm_cess.Show();<br />
 System.Diagnostics.Process.Start(&quot;shutdown&quot;, &quot;/s /f /t 0&quot;);<br />
 msg = &quot;Shutdown&quot;;<br />
 }<br />
 }<br />
 }<br />
 private void nty_cess_MouseDoubleClick(object sender, MouseEventArgs e)<br />
 {<br />
 this.Show();<br />
 this.WindowState = FormWindowState.Normal;<br />
}<br />
 private void toolStripMenuItem1_Click(object sender, EventArgs e)<br />
 {<br />
 this.Hide();<br />
 }<br />
 private void toolStripMenuItem2_Click(object sender, EventArgs e)<br />
 {<br />
 this.Show();<br />
 this.WindowState = FormWindowState.Normal;<br />
 }<br />
 private void toolStripMenuItem3_Click(object sender, EventArgs e)<br />
 {<br />
 Application.Exit();<br />
 }<br />
 private void label6_Click(object sender, EventArgs e)<br />
 {<br />
 aboutme abm = new aboutme();<br />
abm.Show();<br />
 }<br />
private void pictureBox2_Click(object sender, EventArgs e)<br />
 {<br />
 aboutme abm = new aboutme();<br />
 abm.Show();<br />
 }<br />
 }<br />
}<br />

cessation_task.cs code

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
namespace cessation<br />
{<br />
 public partial class cessation_task : Form<br />
 {<br />
 public cessation_task()<br />
 {<br />
 InitializeComponent();<br />
 }<br />
 private void cessation_task_Load(object sender, EventArgs e)<br />
 {<br />
 this.Opacity = 0.1;<br />
 Screen screen = Screen.PrimaryScreen;<br />
 int S_width = screen.Bounds.Width;<br />
 int S_height = screen.Bounds.Height;<br />
 this.Location = new Point((S_width - 240), (S_height-150));<br />
 timer1.Enabled = true;<br />
 timer1.Interval = 100;<br />
 }<br />
 public void msg(string msgg)<br />
 {<br />
 lbl_msg.Text = msgg;<br />
 }<br />
 private void timer1_Tick(object sender, EventArgs e)<br />
 {<br />
 if (this.Opacity &amp;lt; 1)<br />
 {<br />
 this.Opacity = this.Opacity + 0.1;<br />
 timer1.Enabled = true;<br />
 }<br />
 else<br />
 {<br />
 timer1.Enabled = false;<br />
 timer2.Enabled = true;<br />
 timer2.Interval = 3000;<br />
 }<br />
 }<br />
 private void button1_Click(object sender, EventArgs e)<br />
 {<br />
 this.Hide();<br />
 }<br />
 private void timer2_Tick(object sender, EventArgs e)<br />
 {<br />
 if (timer2.Interval == 3000)<br />
 timer3.Enabled = true;<br />
 }<br />
private void timer3_Tick(object sender, EventArgs e)<br />
 {<br />
 if (this.Opacity &gt; .1)<br />
 {<br />
 this.Opacity -= .1;<br />
 timer3.Enabled = true;<br />
 }<br />
 else<br />
 {<br />
 timer3.Enabled = false;<br />
 this.Close();<br />
 }<br />
 }<br />
 }<br />
}<br />

aboutme.cs code

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
namespace cessation<br />
{<br />
 public partial class aboutme : Form<br />
 {<br />
 public aboutme()<br />
 {<br />
 InitializeComponent();<br />
 }<br />
 private void button1_Click(object sender, EventArgs e)<br />
 {<br />
 this.Close();<br />
 }<br />
 }<br />
}<br />

Java Vs C-Sharp


Now compare which language is effective C#.net and Java,lets compare both:

Language and features comparison

Data types Java C#
Single-root (unified) type system No Yes
Signed integers Yes; 8, 16, 32, 64 bits Yes; 8, 16, 32, 64 bits
Unsigned integers No Yes; 8, 16, 32, 64 bits
Character Yes Yes
Date/time Yes; reference type Yes; value type
IEEE 754 binary32 floating point number Yes Yes
IEEE 754 binary64 floating point number Yes Yes
High precision floating point number No; but see Arbitrary size decimals 128-bit (28 digits) Decimal type
Boolean type Yes Yes
Strings Immutable reference type, Unicode Immutable reference type, Unicode
Arbitrary size integers Reference type; no operators Yes
Arbitrary size decimals Reference type; no operators No
Complex numbers No Yes
Reference types Yes Yes
Arrays Yes Yes
Value types No; only primitive types Yes
Enumerated types Yes; reference type Yes; scalar
Lifted (nullable) types No; but wrapper types Yes
Tuples No Yes
Pointers No Yes
Reference types Java C#
Garbage collection Yes Yes
Weak references Yes Yes
Soft references Yes No
Proxy support Yes; proxy generation Yes; object contexts
Object initialization Bottom-up (fields and constructors) Top-down (fields); bottom-up (constructors)
Object orientation Java C#
Classes Yes Yes
Interfaces Yes Yes
Abstract classes Yes Yes
Member accessibility levels Public, package, private, protected Public, protected, internal, protected internal, private
Class level inner classes Yes Yes
Instance level inner classes Yes No
Partial classes No Yes
Anonymous classes Yes No
Deprecation/obsolescence Yes Yes
Overload versioning Some Yes
Properties No Yes
Events No Yes
Operators (operator overloading) No Yes
Indexers No Yes
Implicit conversions No Yes
Explicit conversions No Yes
Fields and initialization Java C#
Fields Yes Yes
Constants Yes Yes
Static (class) constructors Yes Yes
Instance constructors Yes Yes
Finalizers/destructors Yes Yes
Instance initializers Yes No
Hierarchy initialization Top-bottom, lexical order Top-bottom-top, lexical order
Object initializers No Yes
Collection initializers No; can be modelled Yes
Array initializers Yes Yes
Methods and properties Java C#
Static imports Yes No
Virtual Virtual by default Non-virtual by default
Abstract Yes Yes
Sealing Yes Yes
Explicit interface implementation No Yes
Value (input) parameters Yes Yes
Reference (input/output) parameters No Yes
Output (output) parameters No Yes
Variadic methods Yes Yes
Optional arguments No Yes
Named arguments No Yes
Generator methods No Yes
Extension methods No Yes
Conditional methods No Yes
Partial methods No Yes
Generics Java C#
Reified generics No Yes
Co-variance Yes Yes
Contra-variance Yes Yes
Reference type constraint Yes; implicit Yes
Value/primitive type constraint No Yes
Constructor constraint No Yes
Relation constraint Yes Yes
Primitive/value type support No Yes
Migration compatibility Yes No
Functional programming Java C#
Method references No; some use cases covered by anonymous inner classes Yes
Closures/lambdas No; some use cases covered by anonymous inner classes Yes
Expression trees No Yes
Language-integrated SQL Yes No
Generic query language No Yes
Runtime (dynamic) binding Java C#
Late-bound (dynamic) type No Yes
Runtime type information and manipulation Java C#
Runtime type information Yes; but with type erasure Yes
Runtime generics realization No Yes
Runtime type construction No; third party tools exist Yes
Statements Java C#
Loops Yes Yes
Conditionals Yes Yes
Flow control Yes Yes
Assignment Yes Yes
Exception control Yes Yes
Variable declaration Yes Yes
Variable type inference No Yes
Deterministic disposal (ARM-blocks) No Yes
Expressions and operators Java C#
Arithmetic operators Yes Yes
Logical operators Yes Yes
Bitwise logic operators Yes Yes
Conditional Yes Yes
String concatenation Yes Yes
Casts Yes Yes
Boxing Yes; implicit Yes; implicit
Unboxing Yes; implicit Yes; explicit
Lifted operators No Yes
Overflow control No Yes
Strict floating point evaluation Yes; opt-in/out No
Local classes Yes No
Ad-hoc (anonymous) classes No Yes
Verbatim (here-)strings No Yes
Exceptions Java C#
Checked exceptions Yes No
Try-catch-finally Yes Yes
Arrays and collections Java C#
Abstract data types Yes Partial
One-dimensional, zero-based index arrays Yes Yes
Rectangular (multidimensional) arrays Yes Yes
Jagged (arrays of arrays) arrays Yes Yes
Non-zero based arrays No Some
Unified arrays and collections No Yes
Maps/dictionaries Yes Yes
Sorted dictionaries Yes No
Sets Yes Yes
Sorted sets Yes No
Lists/vectors Yes Yes
Queues/stacks Yes Yes
Priority queue Yes No
Bags/multisets Yes Yes
Metadata Java C#
Metadata annotations/attributes Interface based Class based
Positional arguments No; unless a single argument Yes
Named arguments Yes Yes
Default values At definition Through initialization
Nested types Yes Yes
Specialization No Yes
Conditional metadata No Yes
Preprocessing, compilation and packaging Java C#
Namespaces Packages Namespaces
Packaging Package Assembly
Classpath Yes No
File contents
Restricted
Free
Conditional compilation No Yes
Custom errors/warnings No Yes
Explicit regions No Yes
Threading and synchronization Java C#
Threads Yes Yes
Thread pool Yes Yes
Semaphores Yes Yes
Monitors Yes Yes
Thread local variables Yes No
Native interoperability Java C#
External/native methods Yes Yes
Marshalling External glue code required Yes; metadata controlled
Pointers and arithmetics No Yes
Native types No Yes
Fixed size buffers No Yes
Explicit stack allocation No Yes
Address pinning (fixing) No Yes
Address-of No Yes
Object pinning (fix variable to address) No Yes
Platform support Java C#
Linux Yes Partial
Mac OS X Yes Partial
Solaris Yes Partial
FreeBSD Yes Partial
AIX Yes Partial
iOS No Partial
Windows Yes Yes
Enterprise features Java C#
Enterprise-specific SDK Yes; Java EE No
Enterprise-specific virtual machine Yes No
Unified enterprise application server Yes No
Object persistence Yes; JPA Yes; Entity Framework
Transaction processing Yes Yes
Dependency injection Partial; JNDI No
Messaging using queues Yes; JMS Yes; MSMQ
Messaging using topics Yes; JMS No
Built-in clustering Yes No
Object lifecycle metrics Yes No
Web services Yes Yes
Open source & standards Java C#
Standardised by national standards body No Yes
Open source Yes Partial
Patent grant Partial Partial

source taken from:: http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Java

DataType Convertion In C#.net


To Convert the Base Data Type To an other Base Data Type,we use “Convert” class and its functions the target Data Type,Check the below example


int i;
 for (i = 0; i < 5; i++)
 {
 MessageBox.Show(Convert.ToString(i), "Integer To String", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }

Description

we use one integer type variable “i”.and use “for” loop to increment the value of “i” and display the message box.

Convert.ToString(i),is responsible to convert the integer value to string, and message box is only show the string value so i use the Convert.ToString(i) inside the message box.

The above Example is convert the base data type Integer to other base data type String.

It is not only convert the integer data type to string, but its able to convert any base data type to other base data type.

Check Message Box Result


To check the message box result use the Key word “DialogResult” and its option after the giving dot “.”  in if condition The sample code is:


if (DialogResult.Yes == MessageBox.Show("Hello word", "hello", MessageBoxButtons.YesNo, MessageBoxIcon.Question))

{

MessageBox.Show("you press 'yes' button.", "hello", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

else

{

MessageBox.Show("you press 'no' button.", "hello", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

Description

Above code first message box will display with the message of “hello word”, and the title of the message box is “hello” it contain two button yes and no.

We using the if condition to check the result which key user press if it is yes or no,it was check by DialogResult.yes if it was  yes the condition is true and display another message box with the message “you press yes button.” Title is “hello”.
If the IF condition is false control go to else part and display the other message box with the message “you press no button.”

MessageBox.show() function is use to display the message box. the first field of messagebox is use to display the message and the second field is use to display the title of message box and third field is use to set the buttons,which type of button you want you can select it from list and fourth field is icon field of message box by using it you can give icon to your message box and last field is default button by using this you give the default selection to your button.