?? form1.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace java
{
public partial class Form1 : Form
{
//dos命令變量
string pathall;
string path;
string panfu = "G:";
string javac;
string java;
string[] str=new string[7];
public bool flag = true;
public bool IsSave = true;
public Form1()
{
InitializeComponent();
}
string filename="";
bool IsNew = true;
private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Text = "java1";
IsNew = true;
richTextBox1.Enabled = true;
flag = false;
}
private void 打開ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Enabled=true;
IsNew = false;
try
{
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.Clear();
filename = this.openFileDialog1.FileName;
richTextBox1.LoadFile(filename,RichTextBoxStreamType.PlainText);
this.Text = filename;
flag = true;
}
IsSave = true;
}
catch (ArgumentException ae)
{
if (ae.Message == "Invalid file format.")
MessageBox.Show("There was an error loading the file: " + openFileDialog1.FileName);
}
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (flag==true)
{
if (!IsNew)
{
saveFileDialog1.FileName = filename;
}
richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
}
else
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK && saveFileDialog1.FileName.Length > 0)
{
richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
flag = true;
this.Text = saveFileDialog1.FileName;
}
}
IsSave = true;
}
catch (ObjectDisposedException)
{
MessageBox.Show("沒有文件保存");
}
}
private void 編譯ToolStripMenuItem_Click(object sender, EventArgs e)
{
pathall = filename.ToString();
str = pathall.Split('\\');
path = str[0];
int i;
for (i = 1; i < str.Length; i++)
{
if (str[i] == null)
{
break;
}
}
javac = str[i - 1];
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(path);
p.StandardInput.WriteLine("cd "+pathall);
p.StandardInput.WriteLine("javac "+javac);
p.Close();
}
private void 執行ToolStripMenuItem_Click(object sender, EventArgs e)
{
string[] str2 = new string[2];
str2 = javac.Split('.');
java = str2[0];
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
//p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine("java "+java);
p.StartInfo.RedirectStandardInput = false;
p.Close();
}
private void 關閉ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (IsSave==false)
{
switch (MessageBox.Show("是否要保存文檔?\n\n" + this.Text, "關閉", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
{
case DialogResult.Yes:
this.保存ToolStripMenuItem_Click(sender,e);
break;
case DialogResult.Cancel:
break;
}
}
richTextBox1.Clear();
richTextBox1.Enabled = false;
flag = true;
this.Text = "java編譯器";
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
IsSave = false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -