Wednesday, 21 May 2014

How to save image in database in window application


                                                                                                                                                Previous..
                                                                                                                                                    Next...
Here i will explain How to save image in database in window application.

Step(1): Form
In Tutorial 23 i shown you how to insert data into database so this is also in same way we will insert employee detail with his picture. Drag and down a textbox for image path. and this textbox name as "textBox_image_path"


Step(2): Code
Coding at saving button.Make a column a in database as "image"
we will use a namespace as "Using system . IO;

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

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

String gender;                                                              //we have to define this
        private void button1_Click(object sender, EventArgs e)
        {

         byte[]  imageBt = null;
   FileStream fstream = new FileStream ( this.textBox_image_path.Text , FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader (fstream  );
imageBt = br.ReadBytes((int)fstream.Length);

           SqlConnection con = new SqlConnection(str);
                String str = "server=MUNESH-PC;database=windowapp;UID=sa;password=123";
                String query = "insert into data (E.id,name,surname,age,gender,DOB,image) values ('"+this.eid_txt.text+"','"+this.nametxt.text+"','"+this.surname_txt.text+"','"+this.age_txt.text+"' , '"+this.gender+"' , '"+this.DateTimePicker1.Text+"' ,@IMG)";
     SqlCommand cmd = new sqComamnd(query,con);         
  SqlDataReader dbr;
                       
               try
              {
               con.open();

cmd.Parameters.Add( new MySqlParameters( "@IMG" , imageBt));
               dbr = cmd.ExecuteReader();
                MessageBox.Show("saved");
              while(dbr.read())
             {
                 
              }
            }
            catch (Exception es)
            {
                MessageBox.Show(es.Message);

            }
        }
private void rediobutton1.checked(object sender, EventArgs e)
{
gender = "male";
}
private void rediobutton1.checked(object sender, EventArgs e)
{
gender = "female";
}
    }
} 

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();
textBox_image_path.Text = picpath ;
pictureBox1.ImageLocation = picpath;


}
}
}
}


Step(3): Output

Now run your application then when you fill the data and you will see in database there image will be store. you will see database as "BLOB" which store your image.
                                                                                                                                                Previous..
                                                                                                                                                    Next...

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

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