我需要从combobox for .NET设置并获取颜色。到目前为止,它对我没用。
以下是组合框项目列表中的颜色列表:
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
Black
BlanchedAlmond
Blue
BlueViolet
Brown
BurlyWood
CadetBlue
Chartreuse
Chocolate
Coral
CornflowerBlue
Cornslik
Crimson
Cyan
DarkBlue
DarkCyan
DarkGoldRod
DarkGray
DarkGreen
DarkKhaki
DarkMagenta
DarkOliveGreen
DarkOrange
DarkOrchid
DarkRed
DarkSalmon
DarkSeaGreen
DarkSlateBlue
DarkSlateGray
DarkTurquoise
DarkViolet
DeepPink
DeepSkyBlue
DodgerBlue
FireBrick
FloralWhite
ForestGreen
Fuchsia
Gainsboro
GhostWhite
Gold
GoldenRod
Gray
Green
GreenYellow
HoneyDew
HotPink
IndianRed
Indigo
Ivory
Khaki
Lavender
LavenderBlush
LawnGreen
LemonChiffon
LightBlue
LightCoral
LightCyan
LightGoldenRodYellow
LightGray
LightGreen
LightPink
LightSalmon
LightSeaGreen
LightSkyblue
LightSlateGray
LightSteelBlue
LightYellow
Lime
LimeGreen
Linen
Magenta
Maroon
MediumAquamarine
MediumBlue
MediumOrchid
MediumPurple
MediumSeaGreen
MediumSlateBlue
MediumSpringGreen
MediumTurquoise
MediumVioletRed
MidnightBlue
MintCream
MistyRose
Moccasin
NavajoWhite
Navy
OldLace
Olive
OliveDrab
Orange
OrangeRed
Orchid
PaleGoldenRod
PaleGreen
PaleTurquoise
PaleVioletRed
PapayaWhip
PeachPuff
Peru
Pink
Plum
PowderBlue
Purple
Red
RosyBrown
RoyalBlue
SaddleBrown
Salmon
SandyBrown
SeaGreen
SeaShell
Sienna
Silver
SkyBlue
SlateBlue
SlateGray
Snow
SpringGreen
SteelBlue
Tan
Teal
Thistle
Tomato
Transparent
Turquoise
Violet
Wheat
White
WhiteSmoke
Yellow
YellowGreen
这是ComboBox的SelectedIndexChanged或get事件:
gFontColor : String;
method Maker.FontColorBoxChange(Sender: Object; e:System.EventArgs);
begin
if (Sender as combobox).SelectedIndex =-1 then exit;
gFOntCOlor := (Sender as combobox).Selectedvalue;
end;
以下是我如何设置组合框selectedValue:
FontColorBox.SelectedValue := gFontColor;
它不起作用。我能够为字体名称做到这一点,它可以工作,但不适用于颜色。我正盯着代码,似乎无法理解它或让它起作用 - 可能是因为深夜的感恩节派对。 :)
提前致谢,
答案 0 :(得分:2)
要获取和设置所选项目,您必须使用SelectedItem
属性
获取强>
gFOntCOlor :=(Sender As ComboBox).SelectedItem.ToString();
设置强>
FontColorBox.SelectedItem:='Peru';
重要说明:如果你所期望的只是存储和检索ComboBox的selectedItem属性中的数据,这样可以正常工作。但是,如果您希望组合框自动更新以反映正在设置为selectedItem的项目,则必须执行以下操作。
FontColorBox.SelectedItem:='Peru';
FontColorBox.SelectedIndex := FontComboBox.FindString('Peru');
上面的代码会自动设置项目并更新ComboBox以在winform上显示当前的selectedItem。