Tuesday, May 13, 2014

Text File Reader Application using C#.NET Windows Form Application.

Open Visual Studio and create a new project.
Give a design to a form like this :-

Now in the Code file add namespace :-

                             Using System.IO;

Double click on Open button :-


private void button1_Click(object sender, EventArgs e)
        {
            if (File.Exists(textBox1.Text) == true)
            {
                StreamReader sr = new StreamReader(textBox1.Text);
                richTextBox1.Text = sr.ReadToEnd();
                sr.Close();
            }
            else
            {
                MessageBox.Show("This file is not exist");
            }
        }

Double click on Clear button :-


private void button2_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
        }

Save it, Execute it and enjoy it :P :)

Sunday, May 11, 2014

How to create a Web Browser using C#.NET Windows Form Application....

Open Visual Studio.
New Project -> Windows Form Application.

Design the form as shown below:-


Double click on go button and write the following code :-

webBrowser1.Navigate(textBox1.Text);

Double click on back button :-

webBrowser1.GoBack();

Double click on forward button :-

webBrowser1.GoForward();

Double click on refresh button:-

webBrowser1.Refresh();

now select webbrowser control. Go to properties. Go to Event. Double click on Navigated Event :-

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
            textBox1.Text = webBrowser1.Url.ToString();
        }

Execute and enjoy browsing :p :)

Saturday, May 10, 2014

Email Sending Application(Only Gmail) Using C# Windows Application Form Part-2

Open Visual Studio.
New Project -> Windows Form Application.
Design form as shown below :-

In the code file :-


using System.Net;
using System.Net.Mail;

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

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();
            if (d.ShowDialog() == DialogResult.OK)
            {
                textUpload.Text = d.FileName.ToString();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mm = new MailMessage();
                mm.Subject = textSub.Text;
                mm.To.Add(textTo.Text);
                mm.From = new MailAddress(textOwnMail.Text);
                mm.Body = textMsg.Text;
                Attachment a = new Attachment(textUpload.Text);
                mm.Attachments.Add(a);

                SmtpClient sc = new SmtpClient("smtp.gmail.com");
                sc.EnableSsl = true;
                sc.Credentials = new NetworkCredential(textOwnMail.Text, textOwnPw.Text);
                sc.Port = 587;
                sc.Send(mm);
                MessageBox.Show("Your email sent successfully.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

Execute the file and send Emails... Have a great day ! ♥

Simple Email Sending Application Using C# Windows Forms Application.

Open Visual Studio.
New Project -> Windows Form Application.
Design form as shown below :-

In the Code file :-


using System.Net;
using System.Net.Mail;

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

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                SmtpClient s = new SmtpClient("smtp.gmail.com");
                s.Port = 587;
                s.EnableSsl = true;
                s.Timeout = 100000;
                s.DeliveryMethod = SmtpDeliveryMethod.Network;
                s.UseDefaultCredentials = false;
                s.Credentials = new NetworkCredential("yourID@gmail.com", "YourPassword");
                MailMessage mm = new MailMessage();
                mm.To.Add(textBox1.Text);
                mm.From = new MailAddress("YourID@gmail.com");
                mm.Subject = textBox2.Text;
                mm.Body = richTextBox1.Text;
                Attachment a = new Attachment(textBox3.Text);
                mm.Attachments.Add(a);
                s.Send(mm);
                MessageBox.Show("Your email sent successfully.");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();
            if (d.ShowDialog() == DialogResult.OK)
            {
                textBox3.Text = d.FileName.ToString();
            }
        }
    }
}

Run file and send email.... Enjoy Have a good day!

Advanced MessageBox in Windows Form Application using C#

Open Visual Studio.
File -> New Project -> Windows Form Application.
Give design to Form as Below :-

Double Click on Click1 Button and write following code :-


private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

Double click on Click2 Button and Write following code :-


private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            switch(dr)
            {
                case DialogResult.Yes:
                {
                    this.Text = "[YES]";
       break;
                }
                case DialogResult.No:
                {
                    this.Text = "[NO]";
                    break;
                }
            }
        }

Again double click on Click3 Button and write following code :-


private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("What ?", "What", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            switch (dr)
            {
                case DialogResult.Yes:
                    {
                        MessageBox.Show("You clicked Yes");
                        break;
                    }
                case DialogResult.No:
                    {
                        MessageBox.Show("You clicked No");
                        break;
                    }
            }
        }
    }

Save it and run the file. Good Day :)

Splash Screen for Windows Form Application using C#

Open Visual Studio.
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:

Add another form that will be used as the splash screen for this project. And name it as SplashScreen.cs .

Go to the properties of SplashScreen.cs and Change the FormBorderStyle to None. As well as change StartPosition to CenterScreen.

Now add PictureBox to SplashScreen form and add picture in the PictureBox as below :
Go to the file program.cs that contains the Main() method and make sure that the program starts with the SplashScreen form. Like :-

Application.Run(new SplashScreen());

Go to the SplashScreen form, click on "Events" and double-click on the "Shown" event.


Now add this Code there :-

public partial class SplashScreen : Form
    {
        Timer t;

        public SplashScreen()
        {
            InitializeComponent();
        }

        private void SplashScreen_Shown(object sender, EventArgs e)
        {
            t = new Timer();
            t.Interval=5000;
            t.Start();
            t.Tick += Tick1;
        }

        void Tick1(object sender, EventArgs e)
        {
            t.Stop();
            
            Form1 f = new Form1();
            f.Show();
            this.Hide();
        }
    }

Now save all files and run the project... :)

Note :- "A splash screen is an image that appears while a game or program is loading." , "Splash screens are typically used by particularly large applications to notify the user that the program is in the process of loading." , "A splash screen disappears when the application's main window appears." , "Since splash screens often increase the wait for the desired content and may take a long time to load, they are not liked by all users."

Friday, May 9, 2014

Text to Speak windows form application in C#

Open Visual Studio.
File-->New Project.
In the dialog box, choose windows forms application.
Form1.cs design page will be open.
After that design a form listed below:


Right click on Project-->Add Reference--->Then select System.Speech and click OK.



Then double click on Speak button and write code listed below:

//add new namespace 

using System.Speech.Synthesis;

Then :-


private void button1_Click(object sender, EventArgs e)
        {
            SpeechSynthesizer s = new SpeechSynthesizer();
            s.Speak(textBox1.Text);
        }

Now run the application and enjoy. :P