using System.Runtime.InteropServices;
|
|
namespace LB_VisionControls
|
{
|
public partial class ScriptEditControl : UserControl
|
{
|
public string ScriptText
|
{
|
get { return fctb.Text; }
|
set { fctb.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.InsertText("object temp = GetInputs(\"key\");\n");
|
获取全局变量StripMenuItem.Click += (sender, e) => fctb.InsertText("object temp = GetGlobalVars(\"key\");\n");
|
设置输出变量StripMenuItem.Click += (sender, e) => fctb.InsertText("AddOutputs(\"key\", \"value\")\n;");
|
设置全局变量StripMenuItem.Click += (sender, e) => fctb.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.Text = @"/*
|
日志记录
|
时间:" + DateTime.Now.ToLocalTime() + @"
|
用户:" + Environment.UserName + @"
|
记录:
|
*/
|
using System;
|
using System.Text;
|
class Program
|
{
|
static void Main()
|
{
|
//代码
|
|
}
|
}";
|
|
#endregion
|
}
|
|
private void InitStylesPriority()
|
{
|
|
fctb.ClearUndo();
|
fctb.IsChanged = false;
|
|
CreatNew();
|
|
KeyWordsAuto.CreatMenu(fctb, 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.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[CompliReslut.RowErrorNumber - 1].BackgroundBrush = null;
|
fctb.Invalidate();
|
CompliReslut.RowErrorNumber = -1;
|
}
|
}
|
#endregion
|
|
#region 右击菜单
|
private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
fctb.Paste();
|
}
|
|
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
fctb.Copy();
|
}
|
|
private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
fctb.Cut();
|
|
}
|
|
private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
fctb.SelectAll();
|
}
|
|
private void 清除ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
fctb.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()
|
{
|
panel1.Height -= loadSpeed;
|
loadSpeed += loadSpeed;
|
if (panel1.Height <= 30)
|
{
|
timerCell.Enabled = false;
|
panel1.Height = 30;
|
loadSpeed = 10;
|
|
//back
|
timerBack.Enabled = true;
|
}
|
}
|
private void CellOutputShow()
|
{
|
panel1.Height += loadSpeed;
|
loadSpeed += loadSpeed;
|
if (panel1.Height >= 310)
|
{
|
timerCell.Enabled = false;
|
panel1.Height = 310;
|
loadSpeed = 10;
|
|
//OK
|
// picDic.Image = Properties.Resources.rdir1;
|
isShow = false;//显示过程完成
|
}
|
}
|
|
private void backOutputHide()
|
{
|
panel1.Left += loadSpeed;
|
loadSpeed += loadSpeed;
|
if (panel1.Left >= this.Width)
|
{
|
timerBack.Enabled = false;
|
panel1.Left = this.Width;
|
loadSpeed = 10;
|
|
//OK
|
//picDic.Image = Properties.Resources.dir1;
|
isShow = true;//显示过程结束
|
}
|
}
|
private void backOutputShow()
|
{
|
panel1.Left -= loadSpeed;
|
loadSpeed += loadSpeed;
|
if (panel1.Left <= this.Width - panel1.Width - 18)
|
{
|
timerBack.Enabled = false;
|
panel1.Left = this.Width - panel1.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.Text);
|
}
|
|
#region 添加UI
|
public void AddCsc()
|
{
|
panControlView.Controls.Clear();
|
ComplieUI cp = new ComplieUI();
|
cp.BackColor = Color.Transparent;
|
cp.fctb = this.fctb;
|
cp.Dock = DockStyle.Fill;
|
panControlView.Controls.Add(cp);
|
}
|
public void AddClassFileList()
|
{
|
panControlView.Controls.Clear();
|
ClassFileList cp = new ClassFileList();
|
cp.BackColor = Color.Transparent;
|
cp.fctb = this.fctb;
|
cp.Dock = DockStyle.Fill;
|
panControlView.Controls.Add(cp);
|
}
|
public void AddText(string txt)
|
{
|
panControlView.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);
|
panControlView.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();
|
}
|
}
|
|
}
|