Saturday 17 May 2014

Random Number Generator within range in window application


                                                                                                                                        Previous..
                                                                                                                                           Next..

Here i will explain how to Random Number Generator within range in window application.

Step(1) : Form
Drag and down a 3 lable and 3 TextBox and a button.
Here 3 textboxes in 1st text box we will put minimum value and 2nd textbox we will put maximum value and when we will click on button it will generate a random number and it will we show in 3rd textbox.

Step(2) : Code
Double click on button and write this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using System.Text;
using System.IO;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void Choose_Btn_click(object sender, EventArgs e)
{
Random rnd = new Random ();
textBox3.Text = rnd.Next( Convert.ToInt32(textBox1.Text), Convert.ToInt32(textBox2.Text) ).ToString;

//you can also write here 
//textBox3.Text = rnd.Next ( 3,500);
}

Step(3) : Run
Now run your application and enter minimum and maximum number and then generate the number.
                                                                                                                                        Previous..
                                                                                                                                           Next..

How to play a audio file in window application


                                                                                                                                            Previous..
                                                                                                                                                Next...
Here i will explain How to play a audio file in window application.

Step(1): Form
Drag and down 2 button  and a textBox for showing audio path
Step(2): Code
Double click on button and write this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using System.Text;
using System.IO;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void Choose_Btn_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
TextBox1.Text = openfile .FileName;
}
private void Audioplayer_click(object sender, EventArgs e)
{
try
{
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = textBox1.text;
player.Load();
player.PlaySync();

}
catch (Exception ex)
MessageBox.Show(ex.Message);


}
}
Step(3): Output
Run your application and select audio file and then play your audio player.


                                                                                                                                            Previous..
                                                                                                                                                Next...

Make application to beep and How to add a delay in second


                                                                                                                                     Previous..
                                                                                                                                       Next....

Here i will explain How to Make application to beep  and How to add a delay in second.

Step(1):Form
Drag and down a button from toolbox.


Step(2):Code
Double click on button a write this code.
Add a NameSpace
"Using System.Threading;"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
Using System.Diagnostics;
Using System.Threading;
using System.Text;
using System.IO;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void Choose_Btn_click(object sender, EventArgs e)
{
For(  int i = 0 ; i <= 5 ; i ++)
{
Console.Beep();
Thread. Sleep( 1000 );

}

}
Step(3):Output
Run your application and click on button then you will listen a beep.
                                                                                                                                     Previous..
                                                                                                                                       Next....

How to launch any (_exe) file in any directory in window application



                                                                                                                                        Previous..
                                                                                                                                             Next...

Here i will explain How to launch any (_exe) file in any directory in window application.

Step(1): Form
Drag and down a button from ToolBox.
Step(2): Code
Double click on button and write this code.

Add a NameSpace " Using System.Diagnostics;"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
Using System.Diagnostics;
using System.Text;
using System.IO;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void Choose_Btn_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
String FilePath openfile .FileName;
Process.StartFilePath  );

}
}
}
Step(3): OutPut.
Run Your application
                                                                                                                                        Previous..
                                                                                                                                             Next...

How to Open and show a PDF file inside the form in window application


     
                                                                                                                                          Previous...
                                                                                                                                               Next..  
Here i will explain How to Open and show a PDF file  inside the form in window application.

Step(1): Form
Drag and down a button and "PDF Tool" from toolBox. If i "PDF tool" is not showing in your tool box then right click on your toolbox and choose item and click on "COM Component" and then  select "Adob PDF  " Then it will show you on your tool box and then drag and down this.

Step(2): Code
Double click on button and write this code.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

using System.Text;
using System.IO;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void Choose_Btn_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
axAcroPDF1.src =  openfile .FileName;

}
}
}
Step(3): OutPut
Now Run your application      
                                                                                                                                                                                                                                                                                                             Previous...
                                                                                                                                               Next.. 

Friday 16 May 2014

How to import Excel File to DataGridView in window application



                                                                                                                                              Previous..
                                                                                                                                                  Next..
Here i will explain How to import Excel File to DataGridView in window application.Before this i explain how to create excel file in window application.

Step(1) :Form
Drag and down a DataGridView and 2 button. One for Choose File and other for Loading data into DataGridView, And 2 textBox.

Step(2) :Code
Double click on "Choose Button" and  "Load excel" write this code. In tutorial 24 i write this code.


private void Choose_Btn_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
this.textBox1.Text = openfile .FileName;

}

you add some namespace here.
using system.data.oleDB;
using System.data.sqlClient;

and code on button click on Load Excel Button.
private void LoadExcel_btn_click(object sender, EventArgs e)
{
string Pathconn = "Provider = Microsoft.Jet.OLEDB.4.0; DataSource = "+textBox1.Text+" ; Extended properties=\"Excel 8.0;HDR=YES;\";";

oledebconnection  con =  new oledebconnection ( Pathconn);

OledbDataAdapter MydaAtadapter =  new OledbDataAdapter ( "Select * from [ "+TextBox2.Text+ "$]", con;
DataTable dt = new DataTable ();

MydaAtadapter .Fill(dt);

dataGridView1.DataSource = dt;

}

So Code Is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using ExcelLibrary.CompoundDocumentFormat;
using ExcelLibrary.SpreadSheet;

using ExcelLibrary.BinaryDrawingFormat;
using ExcelLibrary.BinaryFileFormat;

using system.data.oleDB;

using System.data.sqlClient;

using System.Text;
using System.IO;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void Choose_Btn_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
this.textBox1.Text = openfile .FileName;

}

private void LoadExcel_btn_click(object sender, EventArgs e)
{
string Pathconn = "Provider = Microsoft.Jet.OLEDB.4.0; DataSource = "+textBox1.Text+" ; Extended properties=\"Excel 8.0;HDR=YES;\";";

oledebconnection  con =  new oledebconnection ( Pathconn);

OledbDataAdapter MydaAtadapter =  new OledbDataAdapter ( "Select * from [ "+TextBox2.Text+ "$]", con;
DataTable dt = new DataTable ();

MydaAtadapter .Fill(dt);

dataGridView1.DataSource = dt;

}

Step(3) :OutPut
Now Run your application

                                                                                                                                              Previous..
                                                                                                                                                  Next..

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...