/// <summary> /// 根据点击的历史记录按钮生成文本框的历史记录 /// </summary> /// <param name="butName"></param> private void textHistoryRecord(string butName) { if (普通_行首历史but.Name.Equals(butName)) { if (textHistory.ContainsKey(0) && textHistory[0].Length > 0) { Panel p = ControlsUtils.GetHistoricalPanel(普通_行首text , 普通_行首历史but.FindForm().Controls , true , textHistory[0] , 普通_行首text.Width + 普通_行首历史but.Width , 18); p.Location = new Point(tab容器.Location.X + 普通_行首text.Location.X , tab容器.Location.Y + tab容器.ItemSize.Height + 普通_行首text.Height + 12); } } if (普通_行尾历史but.Name.Equals(butName)) { if (textHistory.ContainsKey(1) && textHistory[1].Length > 0) { Panel p = ControlsUtils.GetHistoricalPanel(普通_行尾text , 普通_行尾历史but.FindForm().Controls , true , textHistory[1] , 普通_行尾text.Width + 普通_行尾历史but.Width , 18); p.Location = new Point(tab容器.Location.X + 普通_行尾text.Location.X , tab容器.Location.Y + tab容器.ItemSize.Height + 普通_行尾text.Height + 12); } } }
// 关联状态栏 public void statusBarAssociation() { TabPage pp = this; if (pp.Controls.Count > 0) { setSourceControl(pp); void setSourceControl(Control con) { foreach (Control c in con.Controls) { if (c is TextBox || c is DataGridView) { ControlsUtils.TimersMethod(20, 2000, this, (object sender, ElapsedEventArgs e) => { Control ccc = ControlCacheFactory.getSingletonCache(DefaultNameEnum.TOOL_START); if (ccc != null && ccc is RedrawStatusBar) { RedrawStatusBar bar = (RedrawStatusBar)ccc; bar.SetSourceControl(c); ((System.Timers.Timer)sender).Dispose(); } }); } else if (c.Controls.Count > 0) { setSourceControl(c); } } } } }
/// <summary> /// 将文本框打开的文件路径显示到文本框的父容器下目录下 /// </summary> /// <param name="t"></param> public static object setParentTextByFileName(Dictionary <Type, object> data) { TextBox t = (TextBox)data[typeof(TextBox)]; // 获取文本框的父容器 Control con = t.Parent; // 判断父容器是否为TabPage if (con.GetType().Equals(typeof(TabPage))) { ControlsUtils.AsynchronousMethod(t, 300, delegate { // 判断Tag中是否存在保存路径 if (TextBoxUtils.GetTextTagToMap(t).ContainsKey(TextBoxTagKey.SAVE_FILE_PATH)) { string filepath = TextBoxUtils.GetTextTagToMap(t)[TextBoxTagKey.SAVE_FILE_PATH].ToString(); TabPage page = (TabPage)t.Parent; string[] pathArr = FileUtils.GetPathArr(filepath); page.ResetText(); // 设置标签文本 page.Text = pathArr[1]; // 设置提示文本 page.ToolTipText = filepath; } }); } return(null); }
/// <summary> /// 获取指定单例控件中的某种类型的全部子控件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="singConName"></param> /// <returns></returns> public static T[] getSingletonChildCon <T>(DefaultNameEnum singConName) where T : Control { T[] retAll = null; // 全局单例控件工厂 if (singletonCache.ContainsKey(EnumUtils.GetDescription(singConName))) { // 全局单例控件工厂 Dictionary <string, Control> single = ControlCacheFactory.getSingletonCache(); if (single.ContainsKey(EnumUtils.GetDescription(DefaultNameEnum.TOOL_START)) && single.ContainsKey(EnumUtils.GetDescription(DefaultNameEnum.TAB_CONTENT))) { // 获取指定姓名的控件 Control tabParent = single[EnumUtils.GetDescription(singConName)]; if (tabParent != null) { List <T> conList = new List <T>(); ControlsUtils.GetAllControlByType(ref conList, tabParent.Controls); if (conList != null && conList.Count > 0) { retAll = conList.ToArray(); } } } } return(retAll); }
private void lookUpEdit1_Properties_EditValueChanged(object sender, EventArgs e) { try { if (panCountrylook.Text.Trim() != "") { string sql = f1.StoredProcedure + "@TYPE='P_SE_TU_COUNTRY' "; sql = sql + string.Format(",@BU ='{0}' ", panCountrylook.Text.Trim()); DataSet ds = f1.sqlQ(sql); ControlsUtils.BindLookUpEdit(barPolook, ds.Tables[0], "PO_CER", "PO_CER", false); ControlsUtils.BindLookUpEdit(barPoEDlook, ds.Tables[1], "PO_ED", "PO_ED", false); } else { barPolook.Properties.DataSource = null; barPolook.Properties.DisplayMember = null; barPolook.Properties.ValueMember = null; barPoEDlook.Properties.DataSource = null; barPoEDlook.Properties.DisplayMember = null; barPoEDlook.Properties.ValueMember = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 添加文本框到标签页的方法 /// </summary> public static void AddMainTextToPage(TabPage page, TextBox t) { string timeStr = DateTime.Now.ToUniversalTime().Ticks.ToString(); // 判断要添加的标签是否为null,为null则新建一个标签并添加 // t.Location = new Point(0, 2); t.Size = new Size(page.ClientSize.Width - t.Location.X, page.ClientSize.Height - t.Location.Y); if (page == null) { Control ccc = page.Parent; if (ccc != null && ccc is TabControl) { AddControlsToPage((TabControl)ccc, page, t, true, true); } } else { page.Controls.Add(t); t.BringToFront(); } ControlsUtils.TimersMethod(200, 1000, t, (object sender, ElapsedEventArgs e) => { if (t.FindForm() != null) { t.FindForm().ActiveControl = t; ((System.Timers.Timer)sender).Dispose(); } }); }
// 设置文本框的默认配置 private void initControlDefConfig() { string timeStr = DateTime.Now.ToUniversalTime().Ticks.ToString(); // 文本框姓名 this.Name = EnumUtils.GetDescription(DefaultNameEnum.TEXTBOX_NAME_DEF) + timeStr; this.TabStop = true; this.AllowDrop = true; this.BorderStyle = BorderStyle.None; this.Font = MainTextBConfig.TEXTBOX_FONT; this.ReadOnly = TextBoxDataLibcs.TEXTBOX_READ_ONLY_DEF; this.HideSelection = false; this.Location = new Point(0, 0); this.MaxLength = 999999999; this.Multiline = true; this.ShortcutsEnabled = false; this.ScrollBars = ScrollBars.Both; this.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; this.TabIndex = 0; this.WordWrap = MainTextBConfig.AUTO_WORDWRAP; this.AcceptsTab = false; this.TextPadding = new Padding(3); // 将文件默认编码写入到文本框tag数据中 TextBoxUtils.TextBoxAddTag(this, TextBoxTagKey.TEXTBOX_TAG_KEY_ECODING, TextBoxDataLibcs.TEXTBOX_ECODING_DEF); // 消除控件重绘闪烁 ControlsUtils.ClearRedrawFlashing(this); }
/// <summary> /// 将文本框打开的文件路径显示到文本框的父容器下目录下 /// </summary> private void setParentTextByFileName() { TextBox t = this; // 获取文本框的父容器 Control con = t.Parent; // 判断父容器是否为TabPage if (con.GetType().Equals(typeof(TabPage))) { ControlsUtils.AsynchronousMethod(t, 300, delegate { // 判断Tag中是否存在保存路径 if (TextBoxUtils.GetTextTagToMap(t).ContainsKey(TextBoxTagKey.SAVE_FILE_PATH)) { string filepath = TextBoxUtils.GetTextTagToMap(t)[TextBoxTagKey.SAVE_FILE_PATH].ToString(); TabPage page = (TabPage)t.Parent; string[] pathArr = FileUtils.GetPathArr(filepath); page.ResetText(); // 设置标签文本 page.Text = pathArr[1]; // 设置提示文本 page.ToolTipText = filepath; } }); } }
/// <summary> /// 获取文本框消息提示 /// </summary> /// <param name="t"></param> /// <param name="tipVal"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="time"></param> /// <returns></returns> private ToolTip textTip(TextBox t, string tipVal, int x, int y, int time) { ToolTip toolTip = ControlsUtils.GetControlMessTip(t, tipVal, x, y, time, ColorTranslator.FromHtml("#E7D5D5"), Color.Black); return(toolTip); }
// 设置文本框的默认配置 private void initTabPageConfig() { // 实例化一个Page RedrawTabPage page = this; // 设置Page的背景颜色为白色 string timeStr = DateTime.Now.ToUniversalTime().Ticks.ToString(); page.BackColor = Color.White; page.Name = EnumUtils.GetDescription(DefaultNameEnum.TAB_PAGE_NAME) + timeStr; page.Text = TabControlDataLib.PAGE_TEXT; page.UseVisualStyleBackColor = true; page.Padding = new Padding(0, 20, 0, 0); page.Margin = new Padding(0, 0, 0, 0); page.ToolTipText = page.Text; // 设置Page的大小 page.Size = new Size(1, 1); // 进入控件事件 page.Enter += (object sender, EventArgs e) => { ControlsUtils.TimersMethod(200, 1000, page.Parent, (object sender1, ElapsedEventArgs e1) => { if (page.Controls.Count > 0) { Control con = page.Controls[page.Controls.Count - 1]; if (con != null) { page.FindForm().ActiveControl = con; ((System.Timers.Timer)sender1).Dispose(); } } }); }; }
// 绘制鼠标当前位置的标签 private void DrawMouseSelectPage(Graphics g, TabControl tab, int index) { if (index < 0 || index >= tab.TabCount) { return; } // 当前处理标签 TabPage changedpage = tab.TabPages[index]; // 标签背景区域 Rectangle backrect = DrawPageRec(tab, index); Brush backbrush = new SolidBrush(page_mouse_sel_color); // 标签背景色 Brush fontbrush = new SolidBrush(page_sel_font_color); // 标签字体颜色 Color bordercolor = page_mouse_sel_color; // 边框颜色 // tab字体 Font tabFont = new Font(tab.Font.SystemFontName, tab.Font.Size, tab.Font.Style); // 标签字体 // 绘制标签背景 g.FillRectangle(backbrush, backrect); // 绘制标签边框 ControlsUtils.SetControlBorderStyle(g, backrect, ButtonBorderStyle.Solid , 1, 1, 1, 1, page_mouse_sel_color); // 绘制标签文本 PageDrawString(g, backrect, changedpage.Text, tabFont, fontbrush); }
// 鼠标移入事件 protected override void OnMouseEnter(EventArgs e) { ToolTip toolTip = ControlsUtils.GetControlMessTip(this, ButtonMess, this.Width + 2, -4, 10000, Color.White, Color.Black); this.Tag = toolTip; base.OnMouseEnter(e); }
// 调整大小事件 protected override void OnResize(EventArgs e) { ControlsUtils.AsynchronousMethod(this, 0, delegate { doIsAddPageSizeMode(); doIsAddPageButLocation(addPageBut); }); base.OnResize(e); }
/// <summary> /// 重绘菜单的边框 /// </summary> /// <param name="menu">需要重绘的菜单</param> private static void paintMenuFrame(object sender, PaintEventArgs e) { MenuStrip menu = (MenuStrip)sender; ControlsUtils.SetControlBorderStyle(e.Graphics, menu.ClientRectangle , ButtonBorderStyle.Solid , 0, 0, 0, 0 , Color.FromArgb(160, 160, 160)); }
/// <summary> /// 构造器 /// </summary> /// <param name="textBox"></param> internal SplitCharsForm() { // 赋值要操作的文本框 this.textBox = ControlsUtils.GetSelectPageTextBox(); InitializeComponent(); // 初始化消息提示控件 initToolTip(); //DoubleBuffered = true; }
public void WritePortLook(string po) { string sql = form1.StoredProcedure + "@TYPE = 'PORT_LIST'"; sql = sql + string.Format(",@PO = '{0}'", po); DataSet ds = form1.sqlQ(sql); ControlsUtils.BindLookUpEdit(lookPort, ds.Tables[0], "D_PORT", "D_PORT", false); }
public void LoadBindLookUp() { luEdit_GroupMat.EditValue = null; luEdit_GroupMat.Text = string.Empty; string sql = form1.StoredProcedure + " @TYPE='MAT_MASTER_GET' "; DataSet ds = form1.sqlQ(sql); ControlsUtils.BindLookUpEdit(luEdit_GroupMat, ds.Tables[3], "RG_NAME", "ROW_GROUP_ID", false); }
// 操作区容器重绘事件 private void 普通_操作容器_Paint(object sender, PaintEventArgs e) { Panel panel = (Panel)sender; ControlsUtils.SetControlBorderStyle(e.Graphics, panel.ClientRectangle , ButtonBorderStyle.Solid , 0, 0, 0, 1 , ColorTranslator.FromHtml("#D9D9D9")); }
/// <summary> /// 初始化单例模式下的添加标签按钮 /// </summary> private void initAddPageButton() { // 刚启动时父控件可能为空 循环判断tab的父控件是否为空 ControlsUtils.TimersMethod(200, 1000, this, (object sender, ElapsedEventArgs e) => { addPageBut.Visible = IsShowAddPageBut; this.Parent.Controls.Add(addPageBut); addPageBut.BringToFront(); this.SendToBack(); ((System.Timers.Timer)sender).Dispose(); }); }