VintageRice

[Visual Studio] - gLauncher v2

Dec 4th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 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 gLauncher_v2
  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() + "/gamePaths.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!", "gLauncher v2");
  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 * 62), 15);
  44.                         newButton.Height = 50;
  45.                         newButton.Width = 50;
  46.                         newButton.Name = lineCount + "|" + 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 moveButtons_Tick(object sender, EventArgs e)
  61.         {
  62.             int trueX = this.Location.X - Cursor.Position.X;
  63.             int trueY = this.Location.Y - Cursor.Position.Y;
  64.  
  65.             foreach (Control C in this.Controls)
  66.             {
  67.                 if (C.Name.Contains("|") && trueY > -100 && trueY < -40 && trueX < 0 && trueX > -(this.Width))
  68.                 {
  69.                     int theValue = (trueX + this.Width) - (lineCount * 65 / 2);
  70.                     ((Button)C).Left = theValue + (65 * Convert.ToInt16(((Button)C).Name.Split('|')[0]));
  71.                 }
  72.             }
  73.         }
  74.  
  75.         private void hideName(object sender, EventArgs e)
  76.         {
  77.             label1.Text = "Launch: ...";
  78.         }
  79.  
  80.         private void showName(object sender, EventArgs e)
  81.         {
  82.             Button getHover = (Button)sender;
  83.  
  84.             if (getHover.Name.Contains("config"))
  85.             {
  86.                 label1.Text = "Launch: Settings";
  87.             }
  88.             else
  89.             {
  90.                 label1.Text = "Launch: " + getHover.Name.Split('|')[2];
  91.             }
  92.         }
  93.  
  94.         private void launchProgram(object sender, EventArgs e)
  95.         {
  96.             Button getClicked = (Button)sender;
  97.  
  98.             System.Diagnostics.Process.Start(getClicked.Name.Split('|')[1]);
  99.             this.WindowState = FormWindowState.Minimized;
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment