Skip to content

Instantly share code, notes, and snippets.

@JubbaSmail
Created March 13, 2015 13:50
Show Gist options
  • Save JubbaSmail/a6473b844d5f907dc494 to your computer and use it in GitHub Desktop.
Save JubbaSmail/a6473b844d5f907dc494 to your computer and use it in GitHub Desktop.
using System;
using System.Windows.Forms;
using System.IO;
namespace CopyMyFile
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] drives = Directory.GetLogicalDrives();//C: D: E: WIN API
listBox1.Items.AddRange(drives);
listBox2.Items.AddRange(drives);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, MouseEventArgs e)
{
int index = listBox1.SelectedIndex;//UI
string path = listBox1.Items[index].ToString();//UI
//////////////////////////////////////
string[] dirs = Directory.GetDirectories(path);//WIN API
string[] files = Directory.GetFiles(path);//WIN API
//////////////////////////////////////
listBox1.Items.Clear();
listBox1.Items.AddRange(dirs); //UI
listBox1.Items.AddRange(files);//UI
}
private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = listBox2.SelectedIndex;//UI
string path = listBox2.Items[index].ToString();//UI
//////////////////////////////////////
string[] dirs = Directory.GetDirectories(path);//WIN API
string[] files = Directory.GetFiles(path);//WIN API
//////////////////////////////////////
listBox2.Items.Clear();
listBox2.Items.AddRange(dirs); //UI
listBox2.Items.AddRange(files);//UI
}
private void button1_Click(object sender, EventArgs e)
{
int index1 = listBox1.SelectedIndex;//UI
string path1 = listBox1.Items[index1].ToString();//UI
int index2 = listBox2.SelectedIndex;//UI
string path2 = listBox2.Items[index2].ToString();//UI
string filename = Path.GetFileName(path1);
File.Copy(path1, path2 + "\\" + filename);
}
}
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.button1);
this.splitContainer1.Panel1.Controls.Add(this.listBox1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.button2);
this.splitContainer1.Panel2.Controls.Add(this.listBox2);
this.splitContainer1.Size = new System.Drawing.Size(578, 421);
this.splitContainer1.SplitterDistance = 274;
this.splitContainer1.TabIndex = 0;
//
// listBox1
//
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(274, 421);
this.listBox1.TabIndex = 0;
this.listBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listBox1_SelectedIndexChanged);
//
// listBox2
//
this.listBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox2.FormattingEnabled = true;
this.listBox2.Location = new System.Drawing.Point(0, 0);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(300, 421);
this.listBox2.TabIndex = 0;
this.listBox2.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listBox2_MouseDoubleClick);
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Right;
this.button1.Location = new System.Drawing.Point(242, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(32, 421);
this.button1.TabIndex = 1;
this.button1.Text = ">";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Dock = System.Windows.Forms.DockStyle.Right;
this.button2.Location = new System.Drawing.Point(265, 0);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(35, 421);
this.button2.TabIndex = 1;
this.button2.Text = "<";
this.button2.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(578, 421);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "Browser";
this.Load += new System.EventHandler(this.Form1_Load);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment