Winforms在ComboBox中单独格式化双精度值 [英] Winforms Individually Format Double Values in ComboBox
问题描述
我需要单独格式化组合框中的项目在C#/ Winforms。组合框包含从分配给它的一组对象中取得的一组双精度(例如,1,1.01,1.02,1.03等)
我需要做什么是对其进行格式化,以便读取(1.0,1.01,1.02,1.03等)不(1.00,1.01,1.02等)
我知道格式字符串属性可以用于格式化整个集合,但是有一种方法通过crate用户控件对项集合做一些形式的条件格式化。
您可以通过为 格式
活动。
事件处理程序如下所示:
private void comboBox1_Format(object sender,ListControlConvertEventArgs e)
然后,您可以随意修改
e.Value
。I need to individually format items in a combo box in C#/Winforms. The combo box contains a set of doubles taken from a set of objects assigned to it (e.g., 1, 1.01, 1.02, 1.03 etc.)
What I need to do is format them so that the read (1.0, 1.01, 1.02, 1.03 etc.) not (1.00, 1.01, 1.02 etc.)
I know that the format string property can be used to format the whole collection, but is there a way to do some form of conditional formatting on the item collection by crating a user control?
解决方案You can format each item individually by supplying a handler for the
Format
event.The event handler looks like this:
private void comboBox1_Format(object sender, ListControlConvertEventArgs e)
You can then modify
e.Value
as you so wish.这篇关于Winforms在ComboBox中单独格式化双精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!