/// <summary> /// 编辑数据 /// </summary> /// <param name="context">参数</param> /// <param name="provider">参数</param> /// <param name="Value">旧数值</param> /// <returns>新数值</returns> public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object Value) { if (provider == null) { return(Value); } System.Windows.Forms.Design.IWindowsFormsEditorService svc = (System.Windows.Forms.Design.IWindowsFormsEditorService) provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService)); if (svc == null) { return(Value); } using (dlgFormatDesigner dlg = new dlgFormatDesigner()) { ValueFormater format = Value as ValueFormater; if (format == null) { format = new ValueFormater(); } else { format = format.Clone(); } dlg.InputFormater = format; if (svc.ShowDialog(dlg) == DialogResult.OK) { return(dlg.InputFormater); } } return(Value); }
private void UpdateSample() { if (this.lstStyle.SelectedIndex < 0) { this.lblSample.Text = ""; } else { ValueFormater formater = new ValueFormater(); try { formater.Style = (ValueFormatStyle)Enum.Parse(typeof(ValueFormatStyle), lstStyle.Text, true); formater.Format = cboFormat.Text; string strText = ""; if (formater.Style == ValueFormatStyle.String) { strText = "\"" + formater.Execute(DataStrings.SampleText) + "\""; } else if (formater.Style == ValueFormatStyle.Currency) { strText = formater.Execute("123456.789"); } else if (formater.Style == ValueFormatStyle.DateTime) { strText = formater.Execute(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } else if (formater.Style == ValueFormatStyle.Numeric) { strText = formater.Execute("123456.789"); } else if (formater.Style == ValueFormatStyle.Boolean) { strText = "True:" + formater.Execute("true") + " False:" + formater.Execute("false"); } else if (formater.Style == ValueFormatStyle.Percent) { strText = formater.Execute("123.45678"); } this.lblSample.Text = strText; } catch (Exception ext) { lblSample.Text = "#" + ext.Message; } } }
private void cmdOK_Click(object sender, System.EventArgs e) { if (myInputFormater == null) { myInputFormater = new ValueFormater(); } if (lstStyle.SelectedIndex >= 0) { myInputFormater.Style = (ValueFormatStyle)Enum.Parse(typeof(ValueFormatStyle), lstStyle.Text, true); myInputFormater.Format = cboFormat.Text; } else { myInputFormater.Style = ValueFormatStyle.None; } this.DialogResult = DialogResult.OK; this.Close(); }
private void ctlFormat_Load(object sender, System.EventArgs e) { myFormats[ValueFormatStyle.Currency] = DataStrings.FormatSample_Currency.Split('|'); myFormats[ValueFormatStyle.Numeric] = new string[] { "0.00", "#.00", "c", //"d", "e", "f", "g", "r", "FormatedSize" //"X" }; myFormats[ValueFormatStyle.DateTime] = DataStrings.FormatSample_DateTime.Split('|'); myFormats[ValueFormatStyle.String] = new string[] { "trim", "normalizespace", "htmltext", "left,1", "right,1", "lower", "upper" }; myFormats[ValueFormatStyle.Boolean] = DataStrings.FormatSample_Boolean.Split('|'); myFormats[ValueFormatStyle.Percent] = new string[] { "0", "1", "2", "3", "4" }; lstStyle.Items.AddRange(Enum.GetNames(typeof(ValueFormatStyle))); if (myInputFormater == null) { myInputFormater = new ValueFormater(); } lstStyle.Text = myInputFormater.Style.ToString(); cboFormat.Text = myInputFormater.Format; this.bolModified = false; }