listbox背景色
1. vb裡面listbox控制項如何改變某一行的背景顏色
ListBox是由Windows操作系統提供的標准控制項,遵循Windows系統的統一標准,如果你在其內他軟體(不一定是VB編寫的)容中的ListBox發現有可單獨改變某行顏色的情況,那麼VB中的ListBox也一定能夠!如果沒發現,那麼VB也一樣辦不到!如果你真的在其他軟體發現有這樣的情況,那麼我可以負責任地告訴你,這肯定不是標準的ListBox控制項,應該是第三方控制項或自定義控制項。你在VB中也可以自己做一個具有這種功能用戶控制項,或者在網上找一些有此功能的第三方控制項,但是這樣做的話,你的軟體的通用性、兼容性將大打折扣。
2. 如何讓ListBox每一行顯示不同的背景顏色
展開全部
若是只是要顏色的話,就設一下底紋就行了;若是要不同的圖片,就需要添加不同圖片。
顏色:選中當前頁的各段,格式--邊框和底紋
選中底紋,應用范圍選中段落,再設置一種顏色就行了。不同的頁可以設不同顏色。
注意:底紋只會以段落為單位出現在...
3. VB listbox背景色如何設定
先設置list的MultiSelect屬性= 1
在最下面加一個空行 也選中
list.additem ""
然後選擇空行
List1.Selected(i) = True
那麼虛線就沒了 因為LIST的列表項專總是比實際的多一屬個空行
所以那個效果就不見了
4. 【求解】ListBox透明怎麼弄
textBox1.BackColor = Color.Transparent;
貌似不行~~學習··
5. C#中怎樣繪制ListBox控制項的奇偶項目的背景色
注冊DrawItem事件,根據抄e的Index改變你想要的顏色,可以參考以下代碼
void lbMatno_DrawItem(object sender, DevExpress.XtraEditors.ListBoxDrawItemEventArgs e)
{
e.Appearance.Options.UseFont = true;
if (lbMatno.GetItemText(e.Index)[15] == '√')
{
e.Appearance.ForeColor = Color.OrangeRed;
}
else
{
e.Appearance.ForeColor = Color.Black;
}
}
不好意思,我這個是第三方的控制項,不過我看了微軟的也是有這個事件的,你自己試試,應該就是這個
6. c# 怎麼把listbox的背景設為透明
參考這個鏈接:http://blog.csdn.net/bdstjk/article/details/7007662
publicclassTransParentListBox:ListBox
{
publicTransParentListBox()
{
//如果為true,控制項將自行繪制,而不是通過操作系統來繪制。
//如果為false,將不會引發Paint事件。此樣式僅適用於派生自Control的類。
this.SetStyle(ControlStyles.UserPaint,true);
//如果為true,控制項接受alpha組件小於255的BackColor以模擬透明。
//僅在UserPaint位設置為true並且父控制項派生自Control時才模擬透明。
this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
}
(EventArgse)
{
this.Invalidate();
base.OnSelectedIndexChanged(e);
}
protectedoverridevoidOnPaint(PaintEventArgse)
{
if(this.Focused&&this.SelectedItem!=null)
{
//設置選中行背景顏色
RectangleitemRect=this.GetItemRectangle(this.SelectedIndex);
//e.Graphics.FillRectangle(Brushes.Red,itemRect);
e.Graphics.FillRectangle(Brushes.LightBlue,itemRect);
}
for(inti=0;i<Items.Count;i++)
{
//設置繪制文字的格式
StringFormatstrFmt=newSystem.Drawing.StringFormat();
strFmt.Alignment=StringAlignment.Center;//文本垂直居中
strFmt.LineAlignment=StringAlignment.Center;//文本水平居中
e.Graphics.DrawString(this.GetItemText(this.Items[i]),this.Font,newSolidBrush(this.ForeColor),this.GetItemRectangle(i),strFmt);
//e.Graphics.DrawString(this.GetItemText(this.Items[i]),this.Font,newSolidBrush(this.ForeColor),this.GetItemRectangle(i));
}base.OnPaint(e);
}
}
7. vb listbox控制項 選中行背景色 怎麼設定
先設置list的MultiSelect屬性來= 1
在最下面加一個空行源 也選中
list.additem ""
然後選擇空行
List1.Selected(i) = True
那麼虛線就沒了 因為LIST的列表項總是比實際的多一個空行
所以那個效果就不見了
8. 如何將C# listbox背景設置成透明
在listbox的屬性選項里設forecolor為:web選項卡里的第一個Transparent.
9. 求助,,怎樣弄c#里的listBox控制項背景顏色設為透明。。。在線等待答案。
//自定義控制項, 然後在工具箱拖過來用 再把BackColor 設置為Transparent
public partial class TransparentListBox : ListBox
{
public TransparentListBox()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
this.Invalidate();
base.OnSelectedIndexChanged(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.Focused && this.SelectedItem != null)
{
Rectangle itemRect = this.GetItemRectangle(this.SelectedIndex);
e.Graphics.FillRectangle(Brushes.Green, itemRect);
}
for (int i = 0; i < Items.Count; i++)
{
e.Graphics.DrawString(this.GetItemText(Items[i]), this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i));
}
base.OnPaint(e);
}
}
10. MFC ListBox 背景色漸變
從CListBox 繼承一個新類
在其中的DrawItem和MeasureItem函數裡面設置修改顏色
void CNewListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// TODO: Add your code to determine the size of specified item
int nItem = lpMeasureItemStruct-> itemID;
CPaintDC dc(this);
CString sLabel;
CRect rcLabel;
GetText( nItem, sLabel );
GetItemRect(nItem, rcLabel);
int itemHeight = dc.DrawText( sLabel, rcLabel, DT_WORDBREAK | DT_CALCRECT );
lpMeasureItemStruct-> itemHeight = itemHeight;
}
void CNewListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC* pDC = CDC::FromHandle(lpDrawItemStruct-> hDC);
//從選項數據獲得背景顏色值
COLORREF rColor = (COLORREF)lpDrawItemStruct-> itemData; // RGB in item data
CString sLabel;
GetText(lpDrawItemStruct-> itemID, sLabel);
// 些選項被選擇
if ((lpDrawItemStruct-> itemState & ODS_SELECTED))
{
//
CBrush colorBrush(rColor);
CRect colorRect = lpDrawItemStruct-> rcItem;
// 繪制背景
CBrush labelBrush(::GetSysColor(COLOR_HIGHLIGHT));
CRect labelRect = lpDrawItemStruct-> rcItem;
pDC-> FillRect(&labelRect,&labelBrush);
// 繪制文本
COLORREF colorTextSave;
COLORREF colorBkSave;
colorTextSave = pDC-> SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
colorBkSave = pDC-> SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
pDC-> DrawText( sLabel, &lpDrawItemStruct-> rcItem, DT_WORDBREAK );
pDC-> SetTextColor(colorTextSave);
pDC-> SetBkColor(colorBkSave);
return;
}
// 些選項未被選中
if (!(lpDrawItemStruct-> itemState & ODS_SELECTED))
{
CRect rect = lpDrawItemStruct-> rcItem;
CBrush brush(rColor);
pDC-> SetBkColor(rColor);
pDC-> FillRect(&rect,&brush);
pDC-> DrawText( sLabel, -1, &lpDrawItemStruct-> rcItem, DT_WORDBREAK );
return;
}
}
void CNewListBox::AddItem(LPCTSTR lpszItem, COLORREF color, int nIndex)
{
int index=InsertString(nIndex,lpszItem);
SetItemData(index,color);
}
void CNewListBox::AddItem(CString& sitem)
{ CString str=_T( " ");
CTime time=CTime::GetCurrentTime();
str=time.Format( "[ %Y-%m-%d %I:%M %p ] ");
str+= "\r\n "+sitem;
COLORREF color;
color=GetCount()%2?RGB(222,227,247):RGB(250,250,250);
AddItem(str,color,0);
str+= "\r\n ";
}