Exemplo n.º 1
0
 private void textBox1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter && textBox1.Text != "")
     {
         SuspendLayout();
         CommandEventArgs args = new CommandEventArgs(textBox1.Text, ParseInput());
         PrintCommand(textBox1.Text);
         Command(this, args);
         if (args.Cancel == false)
         {
             if (args.Message != "")
             {
                 PrintMessage(args.Message);
             }
         }
         textBox1.Text = "";
         ResumeLayout();
     }
     else if (e.KeyCode == Keys.Escape)
     {
         textBox1.Text = "";
     }
 }
Exemplo n.º 2
0
        private void commandPrompt1_Command(object aSender, CommandEventArgs aEventArgs)
        {
            if (aEventArgs.Command == "cls")
            {
                commandPrompt1.ClearMessages();
                aEventArgs.Cancel = true;
                return;
            }
            if (aEventArgs.Command == "date")
            {
                aEventArgs.Message = "  The current date is : " +
                    DateTime.Now.ToLongDateString();
                return;
            }
            if (aEventArgs.Command == "time")
            {
                aEventArgs.Message = "  The current time is : " +
                    DateTime.Now.ToLongTimeString();
                return;
            }
            if (aEventArgs.Command == "dir")
            {
                string msg = "";

                DirectoryInfo[] di = dirInfo.GetDirectories();
                foreach (DirectoryInfo d in di)
                {
                    msg += "  " + d.LastWriteTime.ToShortDateString()
                        + "\t" + d.LastWriteTime.ToShortTimeString()
                        + "\t<DIR>\t"
                        + "\t" + d.Name + "\n";
                }

                FileInfo[] fi = dirInfo.GetFiles();
                foreach (FileInfo f in fi)
                {
                    msg += "  " + f.LastWriteTime.ToShortDateString()
                        + "\t" + f.LastWriteTime.ToShortTimeString()
                        + "\t\t" + f.Length
                        + "\t" + f.Name + "\n";
                }
                aEventArgs.Message = msg;
                return;
            }
            if (aEventArgs.Command == "cd..")
            {
                if (dirInfo.Parent != null)
                    dirInfo = dirInfo.Parent;
                commandPrompt1.PromptString = dirInfo.FullName;
                return;
            }
            if (aEventArgs.Command.Length > 3 && aEventArgs.Command.Substring(0, 2) == "cd")
            {
                if (aEventArgs.Parameters.Length > 1)
                {
                    string path = aEventArgs.Parameters[1];
                    string newDir = dirInfo.FullName + "\\" + path;

                    path = dirInfo.FullName;
                    dirInfo = new DirectoryInfo(newDir);
                    if (dirInfo.Exists == false)
                    {
                        dirInfo = new DirectoryInfo(path);
                        aEventArgs.Message = "Could not find the specified path";
                    }
                    else
                        commandPrompt1.PromptString = dirInfo.FullName;

                    return;
                }
            }
            else
            {
                try
                {
                    Process.Start(dirInfo.FullName + "\\" + aEventArgs.Command);
                }
                catch
                {
                    aEventArgs.Message = "'" + aEventArgs.Command + "' is an unrecognized command";
                }
            }
        }