Monday, 26 November 2012

Getting Free space on your hard Drive

Getting Free space on your hard Drive:
                                                         let's create a simple console application that out put free space of hard drive.
Step 1:
            Start a new console application in C sharp.
Step 2:
          Type the following code to get a drive char from user;
           Console.WriteLine("Please enter a Drive character : ");
            string a = Console.ReadLine();
Step 3:
          Type the following code to get the memory information;
System.IO.FileInfo f_info = new System.IO.FileInfo(a);


Step 4:
          Type the following code to get the Name of Drive;


System.IO.DriveInfo d_info = new System.IO.DriveInfo(f_info.FullName);



Step 5:
          Type the following code to get the available free space on Drive;


Console.WriteLine(d_info.AvailableFreeSpace.ToString());


Final Step:
                    Over all code is as bellow.


            Console.WriteLine("Enter andy Char:");
            string a = Console.ReadLine();
            System.IO.FileInfo f_info = new System.IO.FileInfo(a + ":");
            System.IO.DriveInfo d_info = new System.IO.DriveInfo(f_info.FullName);
            Console.WriteLine(d_info.Name);
            Console.WriteLine(d_info.AvailableFreeSpace.ToString());
            Console.ReadLine();

Thursday, 22 November 2012

How to get data from text boxes using C Sharp

How to get data from text boxes using C Sharp:

                                                                                                                            we can get data from text boxes using c sharp.But there is  some thing little tricky that we have to do.Text boxes only store data in form of text so it is needed to convert data into required for to use it. So let's see how to get and use data form text boxes in easy steps.
Step 1:
            Start a new Windows form Application project.
Step 2:
           Add tow text boxes and a button on your form.
          It should look like as shown.


Step 3 ( getting Strings): 
            If we want to get String or text form text boxes we do not have to convert it. It's already have the text form.
we have to just write the following code and its ready.
              string a = textBox1.Text;
            string b = textBox2.Text;

Step 4: 
             If we want to out print these strings we have to use the following code.
          
              MessageBox.Show(a + b);

               Our program should out put the following message box.


Step 5( getting integers):
                                            Now lets get some integers from the same text boxes and use them.
                                            But now there is really need of converting them into integer variables.

                                                to convert the strings to integers we have to use the following code.

               int x = int.Parse(a);
            int y = int.Parse(b);

 Step 6: 
              To out print them we are going using following code.

            MessageBox.Show(a +" "+ b);

Step 7 : 
           To convert string to floats we have to use the following block of code.

              float f = float.Parse(a);
            float g = float.Parse(b);

Step  8: 
             To convert string to double we have to use the following block of code.
          
            double d = double.Parse(a);
            double c = double.Parse(b);





Step 9: After converting them we can use them where ever we want to use them.

I have tried to give you the best and simple tutorial, however if you are still confused i will be pleased to answer your concerns :)
Addition In C Sharp:
                                   Lets see addition in detail in simple steps.
Step 1:
           Start a new Windows form application project. 
Step 2:
             Go to toolbox and  add a button on your form.
Step 3:
            Now double click on Button you added.
Step 4:
            Now Create 3 variables and assign them values as under.           
            int a = 10;
            int b = 20;
            int c = 0;
 Step 5:
            We want to add variable "a" in to variable "b" and save the result in c the addition syntax will
  c =  a + b;

Step 6:
           if  we want to add variable "a" , "b" and  variable " c " and save the result in d the addition syntax will:
                  int d = a b +  c
Step 7:
            Now lets add some floats and doubles.
Addition of float and double variables uses the same method and syntax as integers.  
            
            float num_1 = 10;
            float num_2 = 20;
            float num_3 = 0;

to add num_1 to num_2 and save answer in num_3 type the following code.

num_3 = num_1 + num_2;

to add num_1 to num_2 and num_3  save answer in num_4 type the following code.

float  num_4= num_1 + num_2 + num_3;
Step 8:
            Now lets add some  doubles  or float and integers.

In cause adding floats or doubles to integers the results should be save in double or float variable.

let see the example.
 double  n1=3.525;

int z =10;

double  m= z+ n1;


Step 9: lets out put via message box.

MessageBox.Show(z + " + " + n1 +" = "+m);

This will show a message box as shown 




Feel free to contact me at any time for any type of question regarding C sharp.



Float points and Doubles.

Float points and Doubles:

As we know integers are variables that contains whole numbers. They can not store numbers that contain point or decimal like 0.1  ,  5.8  , 5.0089  or 10.776012, These numbers are stored in floats or doubles

How to Create Float Double Variable:

                                                                            To create and float simple type float before the name of variable.  
For example:


float num_1 ;

To create and Double simple type Double before the name of variable.
For example.

Double num_2 ;

How to assign a value to Float Double Variable: 

                                                                    To assign a value to a float variable you need to type the name of float of double then " = " equal sign and then type the value in numbers and remember to place semi column  "  ;  " at the end.
For example.

num_1 = 10.23;
num_2=1.02356;

How to out put  a value from Float or Double Variable:

                                                                                                      To out put a value from a double or float  variable you simple need to write the following code 

Console.WriteLine( num_1 );
Console.WriteLine( num_2 );


How to use the value stored in  an Float or Double Variable:

                                                                                                           If you want to use the value of float or double take the following example.

     float num_3 = num_1 - num_2 ;

Console.WriteLine( num_3 );

Media Player Using C Sharp:


Media Player Using C Sharp:

Step 1:
           Open a new Windows form Application Project.
Step 2:
      Go to Toolbox and drag Menu Strip to your Form.


Step 3:
  Go to Tool box and Drag an Open File Dialog to your Form.

Step 4:
Click anywhere on toolbox and click Choose items…


Step 5:
           You will see Choose Toolbox Items  Dialog opened
            Click on COM Components.



Step 6:
          Select Windows Media player from the list and Click OK.



Step 7:
            Now Windows Media player has been added to your toolbox items.

Step 8:
            Search Windows Media Player in toolbox and drag it to your Form.
            



 

                  It should look like this.

Step 9:
             Give some text to your Menus as shown.

              Now double Click on Open.


Step 10:
             Now Type the following code under the open sub_menu.

            openFileDialog1.InitialDirectory = "C:";
            openFileDialog1.FileName = "";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
            }
            else
            {
                MessageBox.Show("Canceled", "Canceled");
            }

Step 11:
                     Now Run the Program.
Feel free to contact me at any time for any question regarding c Sharp.


    

Wednesday, 21 November 2012

How to Get System Sounds in C sharp:

How to Get System Sounds in C sharp:

There are several types of system sounds in Operating system.Today we are going to learn how to get them.
lets get started in simple steps.
Step 1:
           Start a new (Windows form Application)  project in C sharp.
Step 2:
           Add five buttons on your C sharp Form as shown below,
Step 3:
               Now double click on button 1 to give some code to it.
Step 4:
              Type the following code under button 1

        System.Media.SystemSounds.Hand.Play();

Step 5:
            Now double click on button 2 and give the following code to button 2.

      
            System.Media.SystemSounds.Beep.Play();

  Step 6:
            Now double click on button 3 and give the following code to button 3.  

               System.Media.SystemSounds.Asterisk.Play();

Step 7:
             Now double click on button 4 and give the following code to button 4.


              System.Media.SystemSounds.Question.Play();

 Step 8:
               Now double click on button 5 and give the following code to button 5.

              System.Media.SystemSounds.Exclamation.Play();



 Step 9:
               Finally  your program should look like this.




Now Run your program and enjoy.
feel free to contact me at any time for any type of question regarding C Sharp.

Integers in C Sharp

As we know variables can store text as well as numbers.There are many way to store numbers like numbers can be stored in Variables called Floats Doubles and Integers.In this lesson we are going to learn Integers in detail.

Integers in C Sharp:

                             Integers are whole numbers like 1,2,3 or 450 , 6809 they don't contain any dismal point. 
How to Create an Integer Variable:
To create an integer simply type ' int ' and then name of the variable for example if you want to create an integer variable  ' Age ' you need to type the following code  

int Age;

How to assign a value to an Integer Variable: 

                                                                    To assign a value to an integer you need to type the name of integer then " = " equal sign and then the value in whole numbers,For example if you want to assign  integer "Age" a value of  " 22 " you have to write code in the following way.

Age = 22;

How to out put  a value from an Integer Variable:

                                                                                                      To out put a value from an integer variable you simple need to write the following code 

Console.WriteLine( Age );

How to use the value stored in  an Integer Variable:

                                                                                                           If you want to use the value of integer            take the following example.

     int Age_of_Father = Age + 10;

Console.WriteLine( Age_of_Father );

Monday, 19 November 2012

How to comment in C Sharp

How to comment in C Sharp:

                                           In Computer Programming Comments are used to remember things and to make programming easy .One thing that makes comments unique is that these are not seen by compiler or not executed while program is running . You can comment in lines as well as in paragraphs. Line by line method or one line comment  uses the following syntax.

Step 1:

         Type two forward  slashes

Step 2:

           Then type what ever you want on this line.

Example: 


         //Creating tow string variables.


Or



Now if you want an paragraph of comments you have to use the following Syntax.

Step 1:

           Type on forward Slash and then type a Star  (  *  )

Step 2:

           Type a paragraph of comments

Step 3:

 Now time to close the paragraph of Comments..
 type star (*) and then forward slash.
Now in this way you can close the paragraph

Example:




An other way to comment is to use comment button .
Select the line you want to convert in to comment and then press comment button as shown. 



Concatenation

Concatenation in c sharp:

Joining of things together in programming is said to be concatenation. It includes joining of two or more variables to make a long string. Lets take an example.


      private void button1_Click(object sender, EventArgs e)
        {
            //Creating two string variables.

            string First_Name;                      
            string Second_Name;           
            string Name;
         
            // Assigning values to Variables.

            First_Name= textBox1.Text;                    
            Second_Name = textBox2.Text;

            //Concatenating the variables.

            Name = First_Name + Second_Name;
           
            // Out putting the String variable.
            MessageBox.Show("Your Name is" + Name);
           
        }

In this block of Code  we have 
1.Created three string variables
            
            string First_Name;                      
            string Second_Name;           
            string Name;



2.Assigning the values of two of them 
(Firs_Name and Second_Name)

             First_Name=textBox1.Text;                    
             Second_Name = textBox2.Text;

3.Then Concatenating the First_Name & Second_Name


Name = First_Name + Second_Name;

4. Out putting the variable using Message_Box.

             MessageBox.Show ("Your Name is" + Name);


Lets Code:

Now lets create and windows form application for better understanding of Concept of Concatenation. Like before we will proceed step by step.
Step 1:
        Start a Windows Forms Application new Project in C #.
Step 2:
       Now let's add some controls to our Form.
1. First go to toolbox and add one button to your form.
2. Go to toolbox and add two Text boxes to your form.
3. Go to toolbox and add two labels to your form.
4. Change the text of labels by opening their properties.
   (Right clicking on the label and chose properties at the very end).

Our form should look like this.



Step 3:
      Now Double click on the button to give some codes to it.

Step 4:
       Creating three string variables.

            string First_Name;                      
            string Second_Name;           
            string Name;
Step 5: 
         Assigning values to two of Variables.

            First_Name= textBox1.Text;                    
            Second_Name = textBox2.Text;

Step 6:     
           type this code to Concatenating the variables.

            Name = First_Name + Second_Name;

Step 7:
        Now type or paste the following code to output them.          
            
            MessageBox.Show("Your Name is" + Name);
           
        }
Step 8: Now time to run the program. 







Friday, 16 November 2012

Variables Using C sharp

Variables Using C sharp:

Computer programmes work by manipulating data stored in memory. These storage buckets come under the general heading of Variables. Now we see how to set up and use variables. After some lessons, we will create our own calculator programme using c Sharp dot net frame work.lets get started with Strings.


Strings:

              Strings are the variables that hold " text ". 

Concept:

            to understand the concept of strings variable we take an example of some buckets.
lets spouse we have 5 buckets  these buckets will remain empty until we put some thing in them.
And we can also write some names on them so we know what they contain.   

Lets code:

For better under standing lets create a  new programme.

Step 1:

            Open new Project by clicking on New Project.

Step 2:

Our Form should look like this

              

Step 3:

           Now we will  go to toolbox and add a new button to our form.



         

Step 4:

          Chang the text of Button form buttons properties.
Now form looks like this.


Step 5:

          Now again lets go to toolbox and add a new textbox to our form.Our form should look like this.



Step 6:

         Double click on Message box button to add some code to it.





There we have to code so we can :
1. Create and variable
2. Assign a value to variable 
3. Out put the value of variable.




1. Creating a string variable:

            string Name;
This code creates a string variable or a bucket that can hold some text data and it's name is "Name"   
2. Assigning a value to String Variable (Name):
            Name = textBox1.Text;
            This Code gives the value or Text of textbox1 to Name (String Variable).
3. Out Putting the Value Saved in String variable "Name".                   
            MessageBox.Show("Your Name is "+Name);         

           This code out puts the Value saved in Name via a Message box
Now run your programme and keep coding best of luck.

Thursday, 15 November 2012

Message Box using C Sharp

Message Box in C Sharp :

                                         lets create a complete message box using C sharp in easy steps.

Step 1:

              Create a new Windows Forms Application project in C sharp.

Step 2:

           



Click on toolbox and then click on button and drag it to your form.



Step 3:

Now we have a button appeared on our form.
Double click on button to add some code to it.


Step 4:

           Now lest type some code for Message box.

MessageBox.Show("   Message   ");

This is  to show a message box.




MessageBox.Show("   Message   "," Title ");

This is to show a message box with a title

Step 5: 

Now lets proceed further and  have few Buttons.



MessageBox.Show("   Message   "," Title ",MessageboxButtons);

This is to show a message box with a title and few buttons you selected form intellisense.
Intellisense in some sort of helping dialog to avoid spelling mistakes and speed up coding effectively .



Step 6:


MessageBox.Show("Message","Title",MessageboxButtons,MessageBoxIcon);
This code will add icone to your message box. while coding you can sellect Icon from intellisense.


         
Finally message box code should have the following syntax. 

 MessageBox.Show("Message","Title",MessageBoxButtons.YesNo,MessageBoxIcon.Information);

For Loop:

The most common used loop in every programming language.
It's easy and straight.
the Syntax of The loop is as follows

for ( init-expression ; cond-expression ; loop-expression)

for example


for (int i = 0 ; i<=10; i++)
{

Code Block

}

in this loop


      i = 0;  is init-expression

      i<=10; is cond-expression
   and 
    i++ is loop-expression

Detail:

i=0; or init-expression:

                        i=0; or init-expression tells for loop where to start, in this case the initial value of i is 0

i<=10 or Cond-Expression:

                             i<=10 or Cond-Expression tells the compiler that the maximum lift of Loop is 10 if i goes to the value of 10 you should stoop executing the loop.

i++ or Loop expression:

                         i++ or Loop expression tells compiler that how much increment you made in every cycle, in this case value of i is increasing by one each time until its reaches to 10.

                        

How to Save your work in c sharp

How to Save your work:

Step 1:

Click on File in Menu bar then click on save all or Press Ctrl+Shift+S
A message dialog will appear. 




Step 2:

This save project dialog contains 3 fields.

1.Name:


You can assign Your Project a Name whatever your want

2.Location:

Click on Browse button you see at the right side of the dialog and select the location of project where your want it to be saved.


2.Solution Name:

                     Project name is also automatically copied in solution Name.

 Step 3:

            Click save Button to save your project.
                                        




Your first application using C sharp

Your first application in C sharp:

                                       

Step 1:

Open Visual C sharp 2010 / Visual C sharp 2008 which you have installed on your Machine.
Now your are on start up page.


Start Up Page



Now Click on New Project to start a new project.

Step 2:

1.Click on Windows form application.
2. Name your Application what ever your want.
3.Click OK to proceed further.



Step 3:

You have started a new project
You have a form with it's title on left side and Control buttons on right side.

Step 4:

Now its time to give some controls to your form.
1. left click on toolbox witch is appeared on left site of window.
2. Double Click on "Button" to add a Button to your form.

Now we have button on our form.

Step 5 :

Now you can change the properties of your button by right clicking on it and choosing properties.



Step 6: 

            We will see properties in detail latter. Now we are going to change the text of the Button.



Click on Text and Change the text of button.

Step 7:

Now double click on Button to give it some code.

you will see above window.

Step 8:

Put the following code under your button as shown.
or copy and paste this
 MessageBox.Show("Helo World!  This is my first application and It's working good ");



Step 9: 

               Run your Application by click on Run or by pressing "F5" key on your key board.



Congratulations you have created an application successfully and its working well.