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 ";
}