Friday, 5 July 2013

Assignment:create an application like RUN


create new form place three buttons open file, cancel process or browse file from hard drive
source code of above forn as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dv = new OpenFileDialog();
            dv.InitialDirectory = @"c;\";
            if (dv.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = dv.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult d;
            d = MessageBox.Show("you want to EXIT", "quit", MessageBoxButtons.YesNo);
            if (d == DialogResult.Yes)
            {
            this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s=textBox1.Text;
            System.Diagnostics.Process.Start(s);

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

Wednesday, 3 July 2013

Assignment:create window application to browse further folders

create new form with three listboxes and one drop down menu
source code of above form is as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            DriveInfo[] dr = DriveInfo.GetDrives();
            foreach(DriveInfo d in dr)
            {
                comboBox1.Items.Add(d.Name);
             
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DirectoryInfo dr = new DirectoryInfo(comboBox1.Text);
            DirectoryInfo[] files = dr.GetDirectories();
            foreach (DirectoryInfo d in files)
            {
                listBox1.Items.Add(d.Name);
             
             
            }
         
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string s = comboBox1.Text + listBox1.Text;
            DirectoryInfo dr = new DirectoryInfo(s);
            FileInfo[] files = dr.GetFiles();
            listBox2.Items.Clear();
            foreach (FileInfo f in files)
            {
                listBox2.Items.Add(f.FullName);
            }
         
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string st = comboBox1.Text + listBox1.Text +"\\"+ listBox2.Text;
            System.Diagnostics.Process.Start(st);
        }
    }
}

Monday, 1 July 2013

To create screensaver in c#


to create screensaver create new form add timer to it and put lable in form rename it as ur wish
source code for above form is as follows

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication8
{
    public partial class screensaver : Form
    {
        int a = 10;
        int b = 10;
        public screensaver()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Point p = label1.Location;
            p.X = p.X + a;
            p.Y = p.Y + b;

            if (p.X <= 0 || p.X > (this.Width - label1.Width))
            {
                a = a * -1;
                Random r = new Random();
                int red = r.Next(0, 255);
                int green = r.Next(0, 255);
                int blue = r.Next(0, 255);
                label1.ForeColor = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
            }
            if (p.Y <= 0 || p.Y > (this.Height - label1.Height))
            {
                b = b * -1;
                Random r = new Random();
                int red = r.Next(0, 255);
                int green = r.Next(0, 255);
                int blue = r.Next(0, 255);
                label1.ForeColor = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
           
            }
            label1.Location = p;
        }

        private void screensaver_MouseMove(object sender, MouseEventArgs e)
        {
            this.Close();
        }

        private void screensaver_KeyDown(object sender, KeyEventArgs e)
        {
            this.Close();
        }
    }
}
the ouput of above program while running is shown below

Friday, 28 June 2013

how to create a simple login application


Create new form insert two textboxes and labels infront of textboxes named as username and password
as shown in picture
select two buttons rename them as sign in and cancel as shown in picture

source code of form is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "abc" & textBox2.Text == "abc")
            {
                Form2 obj = new Form2();
                obj.ShowDialog();

            }
            else
            {
                MessageBox.Show("your username or password is incorrect");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult d;

           d = MessageBox.Show("you want to close this app", "Quit", MessageBoxButtons.YesNo);
           if (d ==DialogResult.Yes)
           {
               this.Close();
           }
        }
    }
}

Thursday, 27 June 2013

how to create web browser in c#

create a Menu bar in win-forms, so we can include any number of tabs when ever needed using Menu strip Option in toolbox. Then assign some functionality to it. It would look like this.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private void nEWToolStripMenuItem_Click(object sender, EventArgs e)

{

Form1 fm = new Form1(); fm.Show();

}
private void eXITToolStripMenuItem_Click(object sender, EventArgs e)

{

Application.Exit();

}
After creating a menu strip in the background, where I have added two menu items New and Exit,
  • New for creating a new browser window,
  • And, Exit for exiting the browser.
We will add few more items like we have to create a address bar using ComboBox,Go button,Back,Forward and web browser to the window.
Note: I am Using Combo box over here, it is required to alter the collections of combo box to the specified Url,you can also try with Textbox also.
So let’s start coding for web browser in Search Button. here I am just navigating to the url specified in the combo box.
Search Button :
?
1
2
3
4
5
6
7
private void SEARCH_Click(object sender, EventArgs e)

{

webBrowser1.Navigate(new Uri(comboBox1.SelectedItem.ToString())) ;

}
Here make sure combo box values is converted to string.
Back Button :
?
1
2
3
4
5
6
7
private void BACK_Click(object sender, EventArgs e)

{

webBrowser1.GoBack();

}
Forward Button :
?
1
2
3
4
5
6
7
private void FORWARD_Click(object sender, EventArgs e)

{

webBrowser1.GoForward();

}
It will look somewhat Like this on Completion.
Now let’s run the programming, It will look like this.