VintageRice

[Visual Studio] - aLauncher

Nov 30th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace aLauncher
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         int lineCount = 0;
  22.         string listLocation = Directory.GetCurrentDirectory() + "/getPrograms.txt";
  23.  
  24.         private void Form1_Load(object sender, EventArgs e)
  25.         {
  26.             string getLine;
  27.  
  28.             if (!File.Exists(listLocation))
  29.             {
  30.                 File.Create(listLocation);
  31.                 MessageBox.Show("File created; please relaunch the program!");
  32.             }
  33.             else
  34.             {
  35.                 System.IO.StreamReader theFile = new System.IO.StreamReader(listLocation);
  36.  
  37.                 while ((getLine = theFile.ReadLine()) != null)
  38.                 {
  39.                     if (File.Exists(getLine.Split('|')[0]))
  40.                     {
  41.                         Button newButton = new Button();
  42.  
  43.                         newButton.Location = new System.Drawing.Point(12 + ((lineCount + 1) * 55), 12);
  44.                         newButton.Height = 40;
  45.                         newButton.Width = 40;
  46.                         newButton.Name = "Button" + getLine;
  47.                         newButton.Image = Icon.ExtractAssociatedIcon(getLine.Split('|')[0]).ToBitmap();
  48.  
  49.                         newButton.Click += new EventHandler(this.launchProgram);
  50.                         newButton.MouseHover += new EventHandler(this.showName);
  51.                         newButton.MouseLeave += new EventHandler(this.hideName);
  52.  
  53.                         this.Controls.Add(newButton);
  54.                         lineCount++;
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.  
  60.         private void hideName(object sender, EventArgs e)
  61.         {
  62.             label1.Text = "Launch: ...";
  63.         }
  64.  
  65.         private void showName(object sender, EventArgs e)
  66.         {
  67.             Button getHover = (Button)sender;
  68.  
  69.             if (getHover.Name.Contains("config"))
  70.             {
  71.                 label1.Text = "Launch: Settings";
  72.             }
  73.             else
  74.             {
  75.                 label1.Text = "Launch: " + getHover.Name.Split('|')[1];
  76.             }
  77.         }
  78.  
  79.         private void launchProgram(object sender, EventArgs e)
  80.         {
  81.             Button getClicked = (Button)sender;
  82.  
  83.             System.Diagnostics.Process.Start(getClicked.Name.Split('|')[0].Replace("temp", ""));
  84.             this.WindowState = FormWindowState.Minimized;
  85.         }
  86.  
  87.         private void timer1_Tick(object sender, EventArgs e)
  88.         {
  89.             int trueX = Cursor.Position.X - this.Location.X;
  90.             int trueY = Cursor.Position.Y - this.Location.Y;
  91.  
  92.             if (trueX < this.Width && trueX > (this.Width - 20) && trueY < this.Height && trueY > 0)
  93.             {
  94.                 foreach (Control C in this.Controls)
  95.                 {
  96.                     if (C.Name.Contains("Button"))
  97.                     {
  98.                         ((Button)C).Location = new Point(((Button)C).Location.X - 3, 12);
  99.  
  100.                         if (((Button)C).Location.X <= 0 - ((Button)C).Width)
  101.                         {
  102.                             ((Button)C).Location = new Point((((Button)C).Location.X + (lineCount + 1) * 40) + ((lineCount + 1) * 15), 12);
  103.                         }
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.  
  109.         private void button1_Click(object sender, EventArgs e)
  110.         {
  111.             System.Diagnostics.Process.Start(listLocation);
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment