示例#1
0
 private void TextBox_程序位置_Leave(object sender, EventArgs e)
 {
     if (TextBox_程序位置.Text == "")
     {
         TextBox_程序位置.SendToBack();
     }
     TextBox_程序位置.BackColor = Color.WhiteSmoke;
     Label_程序位置.BackColor   = Color.WhiteSmoke;
 }
示例#2
0
 // 处理拖放进来的文件
 private void Handling_File_Drop(string Drag_File_PATH)
 {
     Debug.Print(Drag_File_PATH);
     if (Path.GetExtension(Drag_File_PATH).ToLower() == ".exe" || Path.GetExtension(Drag_File_PATH).ToLower() == ".bat")
     {
         if (System.IO.File.Exists(Drag_File_PATH))
         {
             TextBox_程序位置.Text = Drag_File_PATH;
             TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text);
             TextBox_启动参数.Text = "";
             TextBox_起始位置.Text = "";
             TextBox_启动参数.SendToBack();
             TextBox_起始位置.SendToBack();
             TextBox_程序位置.BringToFront();
             TextBox_程序名称.BringToFront();
         }
         else
         {
             MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Drag_File_PATH, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else if (Path.GetExtension(Drag_File_PATH).ToLower() == ".lnk")
     {
         if (System.IO.File.Exists(Drag_File_PATH))
         {
             WshShell     shell    = new WshShell();
             IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(Drag_File_PATH);
             if (System.IO.File.Exists(Shortcut.TargetPath))
             {
                 TextBox_程序位置.Text = Shortcut.TargetPath;
                 TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text);
                 TextBox_启动参数.Text = Shortcut.Arguments;
                 TextBox_起始位置.Text = Shortcut.WorkingDirectory;
                 TextBox_程序位置.BringToFront();
                 TextBox_程序名称.BringToFront();
                 if (TextBox_启动参数.Text != "")
                 {
                     TextBox_启动参数.BringToFront();
                 }
                 else
                 {
                     TextBox_启动参数.SendToBack();
                 }
                 if (TextBox_起始位置.Text != "")
                 {
                     TextBox_起始位置.BringToFront();
                 }
                 else
                 {
                     TextBox_起始位置.SendToBack();
                 }
             }
             else
             {
                 MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Shortcut.TargetPath, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Drag_File_PATH, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("只支持拖入 .exe .lnk 格式的文件!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#3
0
 // 切换焦点为输入框
 private void Label_程序位置_MouseClick(object sender, MouseEventArgs e)
 {
     TextBox_程序位置.Focus();
 }
示例#4
0
 // 置顶输入框并修改背景颜色
 private void TextBox_程序位置_Enter(object sender, EventArgs e)
 {
     TextBox_程序位置.BringToFront();
     TextBox_程序位置.BackColor = Color.Gainsboro;
     Label_程序位置.BackColor   = Color.Gainsboro;
 }
示例#5
0
 // 用对话框选择文件
 private void Button_浏览_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         if (Path.GetExtension(openFileDialog1.FileName) == ".exe")
         {
             if (System.IO.File.Exists(openFileDialog1.FileName))
             {
                 TextBox_程序位置.Text = openFileDialog1.FileName;
                 TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text);
                 TextBox_启动参数.Text = "";
                 TextBox_起始位置.Text = "";
                 TextBox_启动参数.SendToBack();
                 TextBox_起始位置.SendToBack();
                 TextBox_程序位置.BringToFront();
                 TextBox_程序名称.BringToFront();
             }
             else
             {
                 MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + openFileDialog1.FileName, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else if (Path.GetExtension(openFileDialog1.FileName) == ".lnk")
         {
             if (System.IO.File.Exists(openFileDialog1.FileName))
             {
                 WshShell     shell    = new WshShell();
                 IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(openFileDialog1.FileName);
                 if (System.IO.File.Exists(Shortcut.TargetPath))
                 {
                     TextBox_程序位置.Text = Shortcut.TargetPath;
                     TextBox_程序名称.Text = Path.GetFileNameWithoutExtension(TextBox_程序位置.Text);
                     TextBox_启动参数.Text = Shortcut.Arguments;
                     TextBox_起始位置.Text = Shortcut.WorkingDirectory;
                     TextBox_程序位置.BringToFront();
                     TextBox_程序名称.BringToFront();
                     if (TextBox_启动参数.Text != "")
                     {
                         TextBox_启动参数.BringToFront();
                     }
                     else
                     {
                         TextBox_启动参数.SendToBack();
                     }
                     if (TextBox_起始位置.Text != "")
                     {
                         TextBox_起始位置.BringToFront();
                     }
                     else
                     {
                         TextBox_起始位置.SendToBack();
                     }
                 }
                 else
                 {
                     MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + Shortcut.TargetPath, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("文件不存在!请检查!" + Environment.NewLine + openFileDialog1.FileName, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("只支持拖入 .exe .lnk 格式的文件!", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }