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