Programming Hub C,C++,C#,Asp.Net,Ado.Net,Java,  HTML,SQL.

This Blog Post Only Education Purpose For All Education Related Blogs and Articles Post Here.Download Free Software and Study Materials Mores..

Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Monday 1 September 2014

A simple media player program in C# .NET 4.0

4:46:00 pm 0

A simple media player program in C# .NET 4.0

This is a program sample that you should go through at the intermediate level of your knowledge about the .Net platform by Microsoft. The entire program is written in C#, you may also use VB.NET if you are familiar with it. The logic behind the program is same, just coding syntax will vary. Well, all the best! let’s start with a quick glance at our objective :

i. We shall construct a media player. ii. It shall be capable of playing media files of any kind, say a music file of .mp3 or .ogg format, a picture of .jpg or .png format as well as a video file of .wmv or .avi format. iii. We shall be able to add files, play them, pause them and stop them. For, our purpose we will use WPF(Windows Presentation Foundation) standard form in Visual Studio 2010 edition.

STEPS:1. Create New Project. 2. Choose WPF, give a project name and add it. A workspace is created with a default Form loaded with the XAML code engraved in it. 3. Open toolbox and choose rather drag and drop a media element on the workspace. 4. Add 4 buttons name them as ‘PLAY’,’PAUSE’,STOP’,’ADD MEDIA’ respectively and a textbox to display the filename being played. A screenshot is given below:


Screenshot of basic layout of WPF form.

5. Double-click on ‘ADD MEDIA’ button and it shall take you to the MainWindow.xaml.cs file where we write our code. Now, a default method is called as we are double clicking the ‘button4’(just an index), that is, button4_click. Now I shall write the entire code.

using system;
using system.LINQ;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace mediaplayer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.AddExtension = true;
            ofd.DefaultExt = "*.*";
            ofd.Filter = "Media(*.*)|*.*";
            ofd.ShowDialog();
            mediaElement1.MediaOpened += new RoutedEventHandler(mediaElement1_MediaOpened);
            mediaElement1.Source = new Uri(ofd.FileName);
        }
        
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            
            mediaElement1.Play();
        }
        
        private void button3_Click(object sender, RoutedEventArgs e)
        {
            mediaElement1.Stop();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            mediaElement1.Pause();
            
        }

        void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
        {
            label1.Content = mediaElement1.Source.ToString();
        }
    }
}

6. Press CTRL+F5 for the code to run. And there you go! Click on ‘Add Media’ button and choose media and watch it play!


Enjoy! Have Fun!




Thursday 24 July 2014

Exceptions in C#? example?

6:18:00 pm 0
Exceptions in C#? example?
Error Types:
*      Syntax Error:-Compile type error is syntax error.
*      Exception error:-Run time error is exception error.
*      Logical error:-If you mistake in program as like not put the correct logic then show error is called logical error.
        “A logical error occurs when an application compiles and runs properly but does not produce the expected result.”
Exception:
Ø  “An exception is termed as an abnormal condition by an application during its exception.”
Ø  An Exception is an error that occurs during program execution exceptional situations arises when an operation can’t be completed normally.
Ø  When an exception occurs in and application the system throws an error.
Ø  All exception are predefined exception
Categorized of exception:
Ø System.Exception
Ø Pre-Defined for use:
System.SystemException
Ø  User Defined for Use:
                    System.SystemApplicationException

Ø  An Exception handling is the process of providing an alternative path of execution of program, when the application is unable to execute as desired.


Example:
     System.IO.IOException exception is thrown when you try to access an illegal stream object.
ü If the denominator is zero , an integer division operation throws the
“System. DivideByZeroException” exception.

using System;
using System.Collections.Generic;
using System.Text;

namespace Exception2
{
    class Test
    {
        static int Zero = 0;
        static void AFunction()
        {
            try
            {
                int j = 22 / Zero;
            }
            // this exception doesn't match
            catch (DivideByZeroException e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("In AFunction()");
        }
        //class Program
        //{
        public static void Main()
        {
            try
            {
                AFunction();
            }
            // this exception doesn't match
            catch (ArgumentException e)
            {
                Console.WriteLine("ArgumentException {0}", e);
            }
            Console.ReadKey();
        }
        //}
    }
}

See
 Output below here…

















SO Friends these are few Blogs that will help you in “Exceptions in C# ? example ?" next time i will put some more interesting Blogs thank you.. I Hope Helpful u... Enjoy :).Krishna Singh



Wednesday 23 July 2014

Delegate in C#

3:12:00 pm 0

                  Delegate in C#

Contents

*    What is delegate?
*    How to declare delegate by keyword?
*    Types of delegate?
*    Example program in use delegate?
*    Output of the example program?


   “Delegate is a reference type method which holds the reference method.”
                                                               “Delegates are use at run time”.
Declare delegate below this keyword:
Public delegate void mydelegate(String s);
@@There are two types of delegate:
1.     Single cast delegate:-“A single cast delegate contains reference to only one method at a time".
2.     Multi cast delegate:- “A multi cast delegate hold the reference of more than method and execute all the method.it wraps in the calling order”.
@@example of delegate program print to device@@@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Delegates
{
    public class Program
    {
        static FileStream fstream;
        static StreamWriter swriter;
        public delegate  void printdata(String s); //apply delegate this program
        public static void Writeconsole(String str)
        {
            Console.WriteLine("", str);
        }
        public static void WriteFile(String s) // name method
        {
            fstream = new FileStream("C:\\Users\\KRISHNA SINGH\\Desktop\\Hi3.txt", FileMode.Append, FileAccess.Write); // Apply to system location for create file u can select any other location  for print file...and  u can create .doc file & .sxlx file & .pps file and more…
            swriter = new StreamWriter(fstream);
            s = s +"";a
            swriter.WriteLine(s);
            swriter.Flush();
            swriter.Close();
            fstream.Close();
        }
       
        public static void DisplayData(printdata pmethod)
        {
            pmethod("");
        }
        public static void Main()
        {
            printdata pd = new printdata(Writeconsole);
            printdata f1 = new printdata(WriteFile);
            DisplayData(pd);
            DisplayData(f1);
            Console.ReadLine();
        }
    }
}


Then run the program…u seen blank console CMD… just like as

Then enter the button…
Seen the output of this example of the delegate program…
Go to your system location in which location u given in program that this file print or create or not…








 Look file name is Hi3.txt…
This is your output…




SO Friends these are few Blogs that will help you in "Delegate  in C-sharp" next time i will put some more interesting Blogs thank you..I Hope Helpfull u.. enjoy :).Krishna Singh

Saturday 19 July 2014

Abstract Class in C#? example

11:24:00 pm 2
                 Abstract Class in C#?


“An abstract is implement that the class is incomplete and can’t be use directly, to use an abstract class other class can derived.”

“An abstract class contains abstract method which can be implemented by the…

v You can’t create instance of a abstract class.
v You can’t override the method of the abstract class in the base class.
v You can’t declare abstract method outside abstract class.
v You can’t declare abstract class as a sealed.
v A class which is derived from the abstract class must override all the method inside the abstract class.
v If a derived class doesn’t implement all of the abstract method in the base class, then the derived class must also be specified by abstract.
v Abstract method is method without any body.
Example:
using System;

abstract class Animal
{
    public abstract void FoodHabits();
}
class Carnivorous:Animal
{
    public override void FoodHabits()
{
    Console.WriteLine("The Carnivorous Animal Eat Only Meat");
}
}
class Herbivorous:Animal
{
    public override void FoodHabits()
    {
        Console.WriteLine("The Harbivorous Animal Eat Only Plants");
    }
}
class Implement
{
    public static void Main()
    {
        Carnivorous cn = new Carnivorous();
        Herbivorous hb = new Herbivorous();
        cn.FoodHabits();
        hb.FoodHabits();
        Console.ReadLine();
    }
}


See the output below…..

SO Friends these are few Blogs that will help you in "Abstract Class in C-sharp" next time i will put some more interesting Blogs thank you..I Hope Helpfull u.. enjoy :).
Krishna Singh

You Might Also Like

Developing Data-Centric Windows Applications using Java

Developing Data-Centric Windows Applications using Java Introduction The Core Java Programming and JDBC course provides an introd...

Unlimited Reseller Hosting