Wednesday 21 May 2014

How to load image in picture Box from computer in window application



                                                                                                                                              Previous..
                                                                                                                                                    Next..
Here i will explain How to load image in picture Box from computer in window application.

Step(1): Form
In tutorial 4 i show you how to use picture box now here i will show you how to show picture and a button click from computer. So drag and down a picture box and a button.

Step(2): Form
Now 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 LoadImage_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

openfile .filter = "JPG Files(* . jpg) | *.jpg | PNG Files(* . png) | * . png | All Files( * . *) | * . * " ;

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{

string picpath openfile .FileName.ToString();
pictureBox1.ImageLocation = picpath;

}
}
}
}
Step(3): OutPut

Now run your application and select image from computer.
                                                                                                                                              Previous..
                                                                                                                                                    Next..

Sunday 18 May 2014

MP3 media Player in window application


                                                                                                                                                Previous..
                                                                                                                                                  Next...

Here i will explain MP3 media Player in window application.

Step(1) :- Form
Before reading this artical 1st go on tutorial 37.
here we will take a listBox and a button for adding playlist in listbox.
Step(2) :- 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();
        }

String [] files , paths;
//At Choose button
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;

}
}

//At Start button
private void Start_Btn_click(object sender, EventArgs e)
{
axWindowMediaPlayer1.URL = textBox1.Text;

axWindowMediaPlayer1.Ctlcontrols.play();

}
//At Stop button
private void Stop_Btn_click(object sender, EventArgs e)
{
axWindowMediaPlayer1.Ctlcontrols.Stop();
}

//At Pause button (If you want pause button)
private void pause_Btn_click(object sender, EventArgs e)
{
axWindowMediaPlayer1.Ctlcontrols.Pause();
}

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

openfile .Multiselect = true ; 
if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
files =  openfile .SafeFileNames; //Save only the names
paths = openfile .FileNames;  //save the full path

for ( i = 0 ; i < files.Length ; i++)
{
listBox1.Items.Add ( files[ i ]);  //Add songs to list box
}
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

axWindowMediaPlayer1.URL = paths[listBox1.SelectedIndex];
}

Step(3) :- Output
Now run your application and select songs and play them.
                                                                                                                                                Previous..
                                                                                                                                                  Next...

How to add a (window media palyer) video clip to the form in window application


                                                                                                                                               Previous..
                                                                                                                                                   Next..

Here i will explain How to add a (window media palyer) video clip to the form in window application.

Step(1): Form
Drag and down 3 button and "window media palyer Tool" from toolBox. If i "(window media palyer 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 "(window media palyer  " Then it will show you on your tool box and then drag and down this.
And give these button name as "Choose File" and "Start" , "Stop".




Step(2): Code
Now write code at every buttton.

At Choose button
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;

}
}

At Start button
private void Start_Btn_click(object sender, EventArgs e)
{
axWindowMediaPlayer1.URL = textBox1.Text;

axWindowMediaPlayer1.Ctlcontrols.play();

}
At Stop button
private void Stop_Btn_click(object sender, EventArgs e)
{
axWindowMediaPlayer1.Ctlcontrols.Stop();
}

At Pause button (If you want pause button)
private void pause_Btn_click(object sender, EventArgs e)
{
axWindowMediaPlayer1.Ctlcontrols.Pause();
}

Step(3): Output
Now Run your application and choose a file and play this.
                                                                                                                                               Previous..
                                                                                                                                                   Next..

How to use and connect Sqlite in a window application


                                                                                                                                            Previous..
                                                                                                                                                Next...
Here i will explain How to use and connect Sqlite in a window application.

Why we use Sqlite in C# :-  We use Sqlite because all ther other DataBase which we use generally require server for that so Sqlite  is a database which we can embade with our system. So we don't require any server for Sqlite  database so mostof the mobile and small database where we don't require any server and want to make standalone application for one computer that doesn't depend on other server then Sqlite is a perfect for us.
For more information about Sqlite  you can go on this link.. Sqlite 
How to connect Sqlite  with C#. Basically C# doesn't support Sqlite  itself so we need some 3rd party DLL to connect Sqlite  database.
There is a link , from this link you can get some DLL file. link and at this link you go on download section and download latest version so download 1st link this is a ZIP file so you extract this file in your application in debug folder. 
Step(1) :select a new project
Open your visual stdio and select new project and in visual C# select " window form application" and give this name as Sqlite and click on OK.

Step(2) :Extract DLL file
Right click on your application and select "Open folder in your window application" and then go to
BIN -> Debug - > and extract your application here.
After this again right click on your application and select " Add reference" and Go to
Browser -> BIN -> Debug - > and select DLL file (Sqlite  Net.dll).

Step(3) :Form
Drag and down a button and give it name as "connect Sqlite ".
Step(4) :Code
Double click on button and write this code.
add a namespace
using Finisar.SQLite;
you take sample code from this link 
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 Finisar.SQLite;

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)
{
// [snip] - As C# is purely object-oriented the following lines must be put into a class:

// We use these three SQLite objects:
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;

// create a new database connection:
sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");

// open the connection:
sqlite_conn.Open(); 

// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand(); 

// Let the SQLiteCommand object know our SQL-Query:
sqlite_cmd.CommandText = "CREATE TABLE test (id integer primary key, text varchar(100));";

// Now lets execute the SQL ;D
sqlite_cmd.ExecuteNonQuery();

// Lets insert something into our new table:
sqlite_cmd.CommandText = "INSERT INTO test (id, text) VALUES (1, 'Test Text 1');";

// And execute this again ;D
sqlite_cmd.ExecuteNonQuery();

// ...and inserting another line:
sqlite_cmd.CommandText = "INSERT INTO test (id, text) VALUES (2, 'Test Text 2');";

// And execute this again ;D
sqlite_cmd.ExecuteNonQuery();

// But how do we read something out of our table ?
// First lets build a SQL-Query again:
sqlite_cmd.CommandText = "SELECT * FROM test";

// Now the SQLiteCommand object can give us a DataReader-Object:
sqlite_datareader=sqlite_cmd.ExecuteReader();

// The SQLiteDataReader allows us to run through the result lines:
while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
{
// Print out the content of the text field:
//System.Console.WriteLine( sqlite_datareader["text"] );

 string myreader  sqlite_datareader . GetString(0);
messageBox.Show( myreader );
}

// We are ready, now lets cleanup and close our connection:
sqlite_conn.Close();
}

Step(5) :Output
Run your application and click on button.
Step(4) :Database
Now if you again click on Right click on your application and select "Open folder in your window application" and then go to
BIN -> Debug - > here you will see database so for Sqlite there is no need of any server

Step(4) :DataBase Table
If you want to see this database there is a simple way to see table and everything in database then go on Mozila and click at above and go at " Add-ons".

 and at the search type " Sqlite " here you will see "Sqlite Manager 0.7.7 " and installed this.

After installed this again go at top at mozile and there click on "web developer -> Sqlite Manager"
Here you go at button ( open ) and browser your database then you will see table in your database.

                                                                                                                                            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...