// 程序的主启动方法 private static void mainStartClass(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // 判断窗口是否已经打开 Process process = RunningInstance(); if (process != null) { IntPtr handle = process.MainWindowHandle; //System.Media.SystemSounds.Asterisk.Play(); WindowsApiUtils.ShowWindow(handle, 5); WindowsApiUtils.SetForegroundWindow(handle); WindowsApiUtils.FlashWindow(handle, true); return; } if (args.Length > 0) { Application.Run(new RootDisplayForm(args)); } else { Application.Run(new RootDisplayForm()); } FormCacheFactory.clearDeaFormTimers(); }
private void setScrollOfMouse() { int MinH, MaxH, MinV, MaxV; int SB_HORZ = 0x0; int SB_VERT = 0x1; int WM_HSCROLL = 0x114; int WM_VSCROLL = 0x115; int SB_THUMBPOSITION = 4; // 获得鼠标在X和Y两个方向上的移动量。除以10是为是让移动页面的速度变慢一点。而前面的负号则是用来调节页面移动方向的。 WindowsApiUtils.GetScrollRange(Handle, 0, out MinH, out MaxH); WindowsApiUtils.GetScrollRange(Handle, 1, out MinV, out MaxV); int MoveX = 0; Console.WriteLine(MaxH); if (MouseMoveLocation.X > MouseDownLocation.X) //向左移动 { MoveX = MouseMoveLocation.X - (this.FindForm().Width / 3); MoveX = MoveX < 0? 0 : MoveX; } else // 向右移动鼠标 { MoveX = MaxH; } int MoveY = Math.Abs(MouseMoveLocation.Y - MouseDownLocation.Y); ////获取滚动条的最大最小位置和当前位置 Console.WriteLine(MouseDownLocation); WindowsApiUtils.SetScrollPos(Handle, SB_HORZ, MoveX, true); // 水平滚动栏 WindowsApiUtils.PostMessage(Handle, WM_HSCROLL, SB_THUMBPOSITION + 0x10000 * MoveX, 0); //告诉控件移动页面内容到相应的位置上 //WinApiUtilsMet.SetScrollPos(Handle, SB_VERT, MoveY, true);// 垂直滚动栏 //WinApiUtilsMet.PostMessage(Handle, WM_VSCROLL, SB_THUMBPOSITION + 0x10000 * MoveY, 0); }
private void SetCursor(Control ctrl) { if (isShowCursor) { WindowsApiUtils.ShowCaret(ctrl.Handle); } else { WindowsApiUtils.HideCaret(ctrl.Handle); } }
// 按钮鼠标移出事件 private void but_MouseLeave(object sender, EventArgs e) { Button but = this.拉按钮_but; Button but2 = this.button1; WindowsApiUtils.AnimateWindow(but.Handle, 3000, 0x80000); // 边框颜色 but.FlatAppearance.BorderColor = ColorTranslator.FromHtml("#ADADAD"); but.BackColor = ColorTranslator.FromHtml("#E1E1E1"); // 边框颜色 but2.FlatAppearance.BorderColor = ColorTranslator.FromHtml("#ADADAD"); but2.BackColor = ColorTranslator.FromHtml("#E1E1E1"); }
/*=================================策略生成区域===========================*/ /// <summary> /// 缓存对象添加到缓存List集合时的添加策略 /// </summary> /// <param name="textM"></param> /// <param name="modList"></param> /// <returns></returns> private static List <TextBoxCacheModel> cacheAddStrategy(TextBoxCacheModel textM, List <TextBoxCacheModel> modList) { // 获取上一个缓存对象 TextBoxCacheModel upMod = modList[modList.Count - 1]; // 判断是否删除了全部的文本 if (textM.Text.Length.Equals(0)) { modList.Add(textM); return(modList); } // 判断是否输入了不同语言 if ((StringUtils.IsStrChines(textM.Text) && !StringUtils.IsStrChines(upMod.Text)) || !StringUtils.IsStrChines(textM.Text) && StringUtils.IsStrChines(upMod.Text)) { modList.Add(textM); return(modList); } /*======================删除判断===========================*/ if (textM.Text.Length + 1 == upMod.Text.Length && upMod.SelectStart != upMod.Text.Length && upMod.Text.Substring(upMod.SelectStart == 0?0:upMod.SelectStart - 1, 1) .Equals(upMod.Text.Substring(upMod.SelectStart, 1))) { modList[modList.Count - 1] = textM; return(modList); } // 判断鼠标左键或者右键按下 if (WindowsApiUtils.GetAsyncKeyState(0x02) > 0 || WindowsApiUtils.GetAsyncKeyState(0x01) > 0) { modList.Add(textM); return(modList); } else { if (textM.Text == null || textM.Text.Equals("")) { return(modList); } } ///*======================按键判断===========================*/ // 判断键盘按键是否和上一个缓存一样并且不是按下了ctrl+v, delete //if (textM.KeysEvent.KeyCode.Equals(upMod.KeysEvent.KeyCode) //&& !(textM.KeysEvent.Control && textM.KeysEvent.KeyCode.Equals(Keys.V))) { // modList[modList.Count - 1] = textM; // return modList; //} modList.Add(textM); return(modList); }
// 将大小写状态赋值给状态栏 private void setCaseKey(Control con) { // 获取文本框 // 开辟新线程执行方法 ControlsUtils.AsynchronousMethod(this, 1, delegate { ToolStripLabel lable = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.大小写状态]; // 判断当前为大写 if (WindowsApiUtils.GetCapitalState()) { lable.Text = "大写"; } else { lable.Text = "小写"; } }); }
/// <summary> /// 设置文本具有pading属性 /// </summary> private void setTextDispLayout() { Rectangle rect = new Rectangle(); WindowsApiUtils.SendMessage(Handle, 178, (IntPtr)0, ref rect); int top = TextPadding != Padding.Empty? TextPadding.Top : 1; int bottom = TextPadding != Padding.Empty? TextPadding.Bottom : 1; int left = TextPadding != Padding.Empty? TextPadding.Left : 1; int right = TextPadding != Padding.Empty? TextPadding.Right : 1; rect.Y = top; rect.X = left; rect.Height = ClientSize.Height - bottom; rect.Width = ClientSize.Width - right; WindowsApiUtils.SendMessage(Handle, 179, IntPtr.Zero, ref rect); }
/// <summary> /// 获取模板文本框 /// </summary> /// <param name="name">NAME</param> /// <param name="val">文本</param> /// <returns></returns> private TextBox getTempTextB(string name, string val) { TextBox textBox = new TextBox(); textBox.Name = name; textBox.Size = new Size(textBDefSize[0], textBDefSize[1]); textBox.Text = val; textBox.Enabled = true; textBox.ReadOnly = true; textBox.Font = this.Font; textBox.ForeColor = Color.Black; textBox.BackColor = Color.White; textBox.TabStop = false; textBox.MouseDown += (object sender, MouseEventArgs e) => { WindowsApiUtils.HideCaret(((TextBox)sender).Handle); }; textBox.BorderStyle = BorderStyle.None; return(textBox); }
// 状态栏的双击事件对应关系 private Dictionary <string, Delegate> doubleClickEventBinding() { Dictionary <string, Delegate> toolBindingDic = new Dictionary <string, Delegate>(); toolBindingDic.Add(StrutsStripDataLib.ItemName.总字符数, new methodDelegate((Control con) => { if (con == null) { MessageBox.Show("无法获取控件"); } // 获取控件 if (con is TextBox) { TextBox t = (TextBox)con; CharsStatistics.openCharsStatistics(t); } return(null); })); toolBindingDic.Add(StrutsStripDataLib.ItemName.总行数, new methodDelegate((Control con) => { Form ff = UIComponentFactory.getSingleForm(DefaultNameEnum.ROW_GOTO_FORM, false); ff.ShowDialog(); return(null); })); toolBindingDic.Add(StrutsStripDataLib.ItemName.行列数, new methodDelegate((Control con) => { if (con == null) { MessageBox.Show("无法获取控件"); } // 获取控件 if (con is TextBox) { TextBox t = (TextBox)con; CharsStatistics.openCharsStatistics(t); } return(null); })); toolBindingDic.Add(StrutsStripDataLib.ItemName.中字符数, new methodDelegate((Control con) => { if (con == null) { MessageBox.Show("无法获取控件"); } // 获取控件 if (con is TextBox) { TextBox t = (TextBox)con; CharsStatistics.openCharsStatistics(t); } return(null); })); toolBindingDic.Add(StrutsStripDataLib.ItemName.编码, new methodDelegate((Control con) => { Form ff = UIComponentFactory.getSingleForm(DefaultNameEnum.SET_CODING_FORM, false); ff.ShowDialog(); return(null); })); toolBindingDic.Add(StrutsStripDataLib.ItemName.大小写状态, new methodDelegate((Control con) => { // 开辟新线程执行方法 ControlsUtils.AsynchronousMethod(this, 1, delegate { ToolStripLabel lable = (ToolStripLabel)this.Items[StrutsStripDataLib.ItemName.大小写状态]; byte[] bs = new byte[256]; //判断当前大小写1为大写 WindowsApiUtils.GetKeyboardState(bs); if (bs[0x14].Equals(1)) // 判断当前为大写 //设置为小写 { WindowsApiUtils.SetCapitalState(false); lable.Text = "小写"; } else { WindowsApiUtils.SetCapitalState(true); lable.Text = "大写"; } }); return(null); })); toolBindingDic.Add(StrutsStripDataLib.ItemName.只读状态, new methodDelegate(setTextReadOnly)); return(toolBindingDic); }
/// <summary> /// 设置分变率 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { // ChangeResolution(1920, 1080, 1); WindowsApiUtils.ChangeResolution(1024, 768, 1); }