/// <summary> /// Constructor /// </summary> public DataGridViewMaskedTextBoxAdvColumn() { CellTemplate = new DataGridViewMaskedTextBoxAdvCell(); _MaskedTextBoxAdv = new MaskedTextBoxAdv(); _MaskedTextBoxAdv.BackgroundStyle.Class = ElementStyleClassKeys.DataGridViewBorderKey; }
/// <summary> /// DrawText /// </summary> /// <param name="di"></param> /// <param name="cellStyle"></param> /// <param name="r"></param> /// <param name="g"></param> private void DrawText(MaskedTextBoxAdv di, DataGridViewCellStyle cellStyle, Rectangle r, Graphics g) { r.Inflate(-2, 0); eTextFormat tf = eTextFormat.Default | eTextFormat.NoPrefix; switch (di.TextAlign) { case HorizontalAlignment.Center: tf |= eTextFormat.HorizontalCenter; break; case HorizontalAlignment.Right: tf |= eTextFormat.Right; break; } if (cellStyle.WrapMode == DataGridViewTriState.True) tf |= eTextFormat.WordBreak; switch (cellStyle.Alignment) { case DataGridViewContentAlignment.TopLeft: case DataGridViewContentAlignment.TopCenter: case DataGridViewContentAlignment.TopRight: tf |= eTextFormat.Top; break; case DataGridViewContentAlignment.BottomLeft: case DataGridViewContentAlignment.BottomCenter: case DataGridViewContentAlignment.BottomRight: tf |= eTextFormat.Bottom; break; default: tf |= eTextFormat.VerticalCenter; break; } TextDrawing.DrawString(g, di.Text, di.Font, di.ForeColor, r, tf); }
// Methods internal static string EditMask(ITypeDiscoveryService discoverySvc, IUIService uiSvc, MaskedTextBoxAdv instance, IHelpService helpService) { string mask = null; Type formType = Type.GetType("System.Windows.Forms.Design.MaskDesignerDialog, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); ConstructorInfo ci = formType.GetConstructor(new Type[] { typeof(MaskedTextBox), typeof(IHelpService) }); Form form = ci.Invoke(new object[]{instance.MaskedTextBox, helpService}) as Form; try { MethodInfo mi = formType.GetMethod("DiscoverMaskDescriptors"); mi.Invoke(form, new object[]{discoverySvc}); //form.DiscoverMaskDescriptors(discoverySvc); DialogResult result = (uiSvc != null) ? uiSvc.ShowDialog(form) : form.ShowDialog(); if (result == DialogResult.OK) { PropertyInfo pi = formType.GetProperty("Mask"); mask = (string)pi.GetValue(form, null); pi = formType.GetProperty("ValidatingType"); Type validatingType = pi.GetValue(form, null) as Type; //mask = form.Mask; if (validatingType == instance.ValidatingType) { return mask; } instance.ValidatingType = validatingType; } } finally { form.Dispose(); } return mask; }
/// <summary> /// DrawControl /// </summary> /// <param name="di"></param> /// <param name="cellStyle"></param> /// <param name="r"></param> /// <param name="bm"></param> /// <param name="g"></param> /// <param name="oc"></param> private void DrawControl(MaskedTextBoxAdv di, DataGridViewCellStyle cellStyle, Rectangle r, Bitmap bm, Graphics g, DataGridViewMaskedTextBoxAdvColumn oc) { if (di.ButtonGroup.Items.Count > 0) { // Determine if we must perform some tom-foolery in order // to get the control to DrawToBitmap correctly in older // Windows versions if (MustRenderVisibleControl() == true) { di.Location = oc.DataGridView.Location; if (di.Parent == null) { Form form = oc.DataGridView.FindForm(); if (form != null) di.Parent = form; } di.SendToBack(); di.Visible = true; } using (Bitmap bm2 = new Bitmap(bm)) { di.Bounds = r; di.DrawToBitmap(bm2, r); foreach (VisualItem item in di.ButtonGroup.Items) { if (item.Visible == true) { Rectangle t = item.RenderBounds; t.X += r.X; t.Y += r.Y; g.DrawImage(bm2, t, t, GraphicsUnit.Pixel); if (t.Left < r.Right) r.Width -= (r.Right - t.Left - 1); } } } di.Visible = false; } DrawText(di, cellStyle, r, g); }
// Methods public MaskedTextBoxAdvDesignerActionList(MaskedTextBoxAdvDesigner designer) : base(designer.Component) { this.maskedTextBox = (MaskedTextBoxAdv)designer.Component; this.discoverySvc = base.GetService(typeof(ITypeDiscoveryService)) as ITypeDiscoveryService; this.uiSvc = base.GetService(typeof(IUIService)) as IUIService; this.helpService = base.GetService(typeof(IHelpService)) as IHelpService; if (this.discoverySvc != null) { IUIService uiSvc = this.uiSvc; } }