 |
|
C# สอบถามเกี่ยวกับการใส่สี ให้ combobox แต่ละอันให้เป็นสีคนละสีกันครับ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
private void ComboColor()
{
comboBox1.Items.Add(""); comboBox1.Items[0].Attributes.Add("style", "background-color: red");
comboBox1.Items.Add(""); comboBox1.Items[1].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[2].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[3].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[4].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[5].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[6].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[7].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[8].Attributes.Add("style", "background-color: blue");
comboBox1.Items.Add(""); comboBox1.Items[9].Attributes.Add("style", "background-color: blue");
}
ลองดูครับ แบบนี้หรือเปล่า
หรือ แบบนี้
Code (VB.NET)
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
int index = e.Index >= 0 ? e.Index : 0;
var brush = Brushes.Black;
e.DrawBackground();
e.Graphics.DrawString(comboBox1.Items[index].ToString(), e.Font, brush, e.Bounds, StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
ที่มา
http://stackoverflow.com/questions/6468024/how-to-change-combobox-backgound-color-not-just-the-drop-down-list-part
|
ประวัติการแก้ไข 2014-11-18 07:13:21 2014-11-18 07:15:22
 |
 |
 |
 |
Date :
2014-11-18 07:09:31 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกอันครับ
http://www.codeproject.com/Articles/5129/ColorComboBox
|
 |
 |
 |
 |
Date :
2014-11-18 08:29:04 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากมากครับ
|
 |
 |
 |
 |
Date :
2014-11-18 11:15:46 |
By :
evenomz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถามหน่อยครับ เป็น winapp หรือ webapp ครับ
|
 |
 |
 |
 |
Date :
2014-11-18 13:51:44 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตกลงกันเสร็จแล้วบอกด้วยนะ จะได้เฉลย

|
 |
 |
 |
 |
Date :
2014-11-18 14:40:02 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็อปจากเน็ตมา
Code (C#)
private void Form1_Load(object sender, EventArgs e)
{
this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
this.comboBox1.DrawItem += comboBox1_DrawItem;
this.comboBox1.Items.Add("One");
this.comboBox1.Items.Add("Two");
this.comboBox1.Items.Add("Three");
this.comboBox1.Items.Add("Four");
this.comboBox1.Items.Add("Five");
{
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// Draw the background
e.DrawBackground();
// Get the item text
string text = ((ComboBox)sender).Items[e.Index].ToString();
// Determine the forecolor based on whether or not the item is selected
Brush brush;
// compare date with your list.
brush = (text == "Two") ? Brushes.Red : brush = Brushes.Black;
// Draw the text
e.Graphics.DrawString(text, ((Control)sender).Font, brush, e.Bounds.X, e.Bounds.Y);
}
|
 |
 |
 |
 |
Date :
2014-11-18 15:32:50 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|