using System.Runtime.InteropServices; namespace LB_VisionControl.ScriptEditControl { public partial class ScriptEditControl : UserControl { public string ScriptText { get { return fctb_ScriptEditControl.Text; } set { fctb_ScriptEditControl.Text = value; } } public ScriptEditControl() { InitializeComponent(); CommConfig.AppLocationPath = Application.StartupPath; UpStyle(); InitStylesPriority(); #region 新增自定义菜单 // // toolStripMenuItem1 // toolStripMenuItem1.ForeColor = SystemColors.ControlDarkDark; toolStripMenuItem1.Name = "toolStripMenuItem1"; toolStripMenuItem1.Size = new Size(109, 6); 获取输入变量StripMenuItem.ForeColor = Color.FromArgb(255, 255, 128); 获取全局变量StripMenuItem.ForeColor = Color.FromArgb(255, 255, 128); 设置输出变量StripMenuItem.ForeColor = Color.FromArgb(255, 255, 128); 设置全局变量StripMenuItem.ForeColor = Color.FromArgb(255, 255, 128); 获取输入变量StripMenuItem.Size = new Size(112, 26); 获取全局变量StripMenuItem.Size = new Size(112, 26); 设置输出变量StripMenuItem.Size = new Size(112, 26); 设置全局变量StripMenuItem.Size = new Size(112, 26); 获取输入变量StripMenuItem.Text = "获取输入变量"; 获取全局变量StripMenuItem.Text = "获取全局变量"; 设置输出变量StripMenuItem.Text = "设置输出变量"; 设置全局变量StripMenuItem.Text = "设置全局变量"; // 插入固定的文本 获取输入变量StripMenuItem.Click += (sender, e) => fctb_ScriptEditControl.InsertText("object temp = GetInputs(\"key\");\n"); 获取全局变量StripMenuItem.Click += (sender, e) => fctb_ScriptEditControl.InsertText("object temp = GetGlobalVars(\"key\");\n"); 设置输出变量StripMenuItem.Click += (sender, e) => fctb_ScriptEditControl.InsertText("AddOutputs(\"key\", \"value\")\n;"); 设置全局变量StripMenuItem.Click += (sender, e) => fctb_ScriptEditControl.InsertText("AddGlobalVars(\"key\", \"value\")\n;"); contextMenuStripEx1.Items.Clear(); contextMenuStripEx1.Items.AddRange(new ToolStripItem[] { 复制ToolStripMenuItem1, 剪切ToolStripMenuItem1, toolStripMenuItem4, 粘贴ToolStripMenuItem1, toolStripMenuItem5, 全选ToolStripMenuItem1, toolStripMenuItem6, 清除ToolStripMenuItem1, 新建ToolStripMenuItem, toolStripMenuItem1, 获取输入变量StripMenuItem, 获取全局变量StripMenuItem, 设置输出变量StripMenuItem, 设置全局变量StripMenuItem }); #endregion } #region 自定义菜单 private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1 = new ToolStripSeparator(); private System.Windows.Forms.ToolStripMenuItem 获取输入变量StripMenuItem = new ToolStripMenuItem(); private System.Windows.Forms.ToolStripMenuItem 获取全局变量StripMenuItem = new ToolStripMenuItem(); private System.Windows.Forms.ToolStripMenuItem 设置输出变量StripMenuItem = new ToolStripMenuItem(); private System.Windows.Forms.ToolStripMenuItem 设置全局变量StripMenuItem = new ToolStripMenuItem(); #endregion private void UpStyle() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); UpdateStyles(); } private void CreatNew() { #region 初始化数据 fctb_ScriptEditControl.Text = @"/* 日志记录 时间:" + DateTime.Now.ToLocalTime() + @" 用户:" + Environment.UserName + @" 记录: */ using System; using System.Text; class Program { static void Main() { //代码 } }"; #endregion } private void InitStylesPriority() { fctb_ScriptEditControl.ClearUndo(); fctb_ScriptEditControl.IsChanged = false; CreatNew(); KeyWordsAuto.CreatMenu(fctb_ScriptEditControl, imageList1); //KeysWordCMDAuto.CreatMenu(DebugTextBox1, imageList1); } #region 系统UI private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { if (Directory.Exists(CommConfig.BinPath)) Directory.Delete(CommConfig.BinPath, true); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Form1_KeyDown(object sender, KeyEventArgs e) { if ((Control.ModifierKeys & Keys.Control) != 0 && e.KeyCode == Keys.Up) { fctb_ScriptEditControl.Focus(); } //else if ((Control.ModifierKeys & Keys.Control) != 0 && e.KeyCode == Keys.Down) //{ DebugTextBox1.Focus(); } } private void fctb_KeyDown(object sender, KeyEventArgs e) { if (CompliReslut.RowErrorNumber != -1) { fctb_ScriptEditControl[CompliReslut.RowErrorNumber - 1].BackgroundBrush = null; fctb_ScriptEditControl.Invalidate(); CompliReslut.RowErrorNumber = -1; } } #endregion #region 右击菜单 private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e) { fctb_ScriptEditControl.Paste(); } private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) { fctb_ScriptEditControl.Copy(); } private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e) { fctb_ScriptEditControl.Cut(); } private void 全选ToolStripMenuItem_Click(object sender, EventArgs e) { fctb_ScriptEditControl.SelectAll(); } private void 清除ToolStripMenuItem_Click(object sender, EventArgs e) { fctb_ScriptEditControl.Clear(); } #endregion #region 移动 public const int WM_NCLBUTTONDOWN = 0xA1; public const int HT_CAPTION = 0x2; [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); private void splitContainer1_Panel1_MouseMove(object sender, MouseEventArgs e) { //移动 if (e.Button == MouseButtons.Left) { if (e.X < this.Width) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); } } } private void label1_MouseMove(object sender, MouseEventArgs e) { //移动 if (e.Button == MouseButtons.Left) { if (e.X < this.Width) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); } } } #endregion #region 动画 public bool isShow = true; int loadSpeed = 10; public void StartMeun() { if (isShow) { timerBack.Enabled = true; } else { timerCell.Enabled = true; } } private void CellOutputHide() { pnl_ScriptEditControl.Height -= loadSpeed; loadSpeed += loadSpeed; if (pnl_ScriptEditControl.Height <= 30) { timerCell.Enabled = false; pnl_ScriptEditControl.Height = 30; loadSpeed = 10; //back timerBack.Enabled = true; } } private void CellOutputShow() { pnl_ScriptEditControl.Height += loadSpeed; loadSpeed += loadSpeed; if (pnl_ScriptEditControl.Height >= 310) { timerCell.Enabled = false; pnl_ScriptEditControl.Height = 310; loadSpeed = 10; //OK // picDic.Image = Properties.Resources.rdir1; isShow = false;//显示过程完成 } } private void backOutputHide() { pnl_ScriptEditControl.Left += loadSpeed; loadSpeed += loadSpeed; if (pnl_ScriptEditControl.Left >= this.Width) { timerBack.Enabled = false; pnl_ScriptEditControl.Left = this.Width; loadSpeed = 10; //OK //picDic.Image = Properties.Resources.dir1; isShow = true;//显示过程结束 } } private void backOutputShow() { pnl_ScriptEditControl.Left -= loadSpeed; loadSpeed += loadSpeed; if (pnl_ScriptEditControl.Left <= this.Width - pnl_ScriptEditControl.Width - 18) { timerBack.Enabled = false; pnl_ScriptEditControl.Left = this.Width - pnl_ScriptEditControl.Width - 18; loadSpeed = 10; //celll timerCell.Enabled = true; } } private void timerCell_Tick(object sender, EventArgs e) { if (isShow) { CellOutputShow(); } else { CellOutputHide(); } } private void timerBack_Tick(object sender, EventArgs e) { if (isShow) { backOutputShow(); } else { backOutputHide(); } } #endregion public void FileSave() { if (!Directory.Exists(CommConfig.ClassLibPath)) { Directory.CreateDirectory(CommConfig.ClassLibPath); } File.WriteAllText(CommConfig.fileName, fctb_ScriptEditControl.Text); } #region 添加UI public void AddCsc() { pnl_ControlView.Controls.Clear(); ComplieUI cp = new ComplieUI(); cp.BackColor = Color.Transparent; cp.fctb = this.fctb_ScriptEditControl; cp.Dock = DockStyle.Fill; pnl_ControlView.Controls.Add(cp); } public void AddClassFileList() { pnl_ControlView.Controls.Clear(); ClassFileList cp = new ClassFileList(); cp.BackColor = Color.Transparent; cp.fctb = this.fctb_ScriptEditControl; cp.Dock = DockStyle.Fill; pnl_ControlView.Controls.Add(cp); } public void AddText(string txt) { pnl_ControlView.Controls.Clear(); TextBox tx = new TextBox(); tx.Text = txt; tx.Dock = DockStyle.Fill; tx.BorderStyle = BorderStyle.None; tx.BackColor = Color.FromArgb(30, 17, 18); tx.ForeColor = Color.Green; tx.Multiline = true; tx.ScrollBars = ScrollBars.Both; tx.Font = new System.Drawing.Font("微软雅黑", 9); pnl_ControlView.Controls.Add(tx); } #endregion private void DebugTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up) e.Handled = true; } private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) { InitStylesPriority(); } } }