大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
你没有写刷新功能嘛,如LblResult.BackColor = Color.LightCoral后面再加一句LblResult.refresh()就实现了背景色变换!
10年积累的成都做网站、成都网站制作、成都外贸网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有昭苏免费网站建设让你可以放心的选择与我们合作。
Label控件是没有办法实现多种颜色的文字的,只能用RichTextBox来实现,而且你的自定义格式字符串也没有结尾的,这样很不好,至少也要red红色字/redyellow黄色字/yellow,而且实现也很麻烦的,下面的代码我没有检测正确性,有错误的自己改一改吧
Dim colortag() as string
dim colors() as color
const txt as string="red红色字/redyellow黄色字/yellow"
private sub Form_Load(object sender,eventargs e)handles mybase.load
colortag(0)="red":Colortag(1)="yellow"
colors(0)=color.red:colors(1)=color.yellow
richtextbox1.text=txt
for i as integer=0 to colortag.lenght-1
dim tag as string="" colortag(i) ""
dim endtag as string="/" colortag(i) ""
dim find as integer=1
do
find=instr(find,txt,tag)+tag.lenght
if(find0)then
dim find1 as integer=instr(find,txt,endtag)
richtextbox1.SelectionStart=find
richtextbox1.selectionlenght=find1-find
richtextbox1.selectioncolor=colors(i)
find=find1
else
exit do
end if
loop
next
end sub
近来项目用到了一个类似WEB控件DataGrid中自定义行或列的颜色的功能 然而应用却是在WIN的窗体下 实现起来无法使用类似JavaScript的脚本注册的功能来动态完成 十分着急 察看了CSDN的一些关于WinForm下的关于DataGrid的资料 看到这样的一篇介绍DG结构的美文 题目是《Henry手记:WinForm Datagrid结构剖析》 作者是韩睿(Latitude) 其中介绍了WIN DG的颜色的定义 但是主要是针对每一个Cell的 我们需要的则是标记某一行的数据 用颜色突出显示 所以作了部分改动 现在把部分代码张贴出来供大家参考 . 基础类出自韩睿 URL: ?id= Public Class DataGridColoredTextBoxColumn Inherits DataGridTextBoxColumn Public rowcollection As New Collection() Public BackColor() As Color Public ForeColor() As Color Private Function GetText(ByVal Value As Object) As String If TypeOf (Value) Is System DBNull Then Return NullText ElseIf Value Is Nothing Then Return Else Return Value ToString End If End Function Protected Overloads Overrides Sub Paint(ByVal g As System Drawing Graphics ByVal bounds As System Drawing Rectangle _ ByVal source As System Windows Forms CurrencyManager _ ByVal rowNum As Integer _ ByVal backBrush As System Drawing Brush _ ByVal foreBrush As System Drawing Brush _ ByVal alignToRight As Boolean) Dim text As String
text = GetText(GetColumnValueAtRow(source rowNum)) backBrush = New SolidBrush(TextBox BackColor) foreBrush = New SolidBrush(TextBox ForeColor)
ReDim Preserve BackColor(rowcollection Count) ReDim Preserve ForeColor(rowcollection Count) Dim i As Integer = Do While (i = rowcollection Count) If rowNum = Val(rowcollection Item(i)) Then
If Not BackColor(i ) IsEmpty Then backBrush = New SolidBrush(BackColor(i )) End If If Not ForeColor(i ) IsEmpty Then foreBrush = New SolidBrush(ForeColor(i )) End If End If i += Loop MyBase PaintText(g bounds text backBrush foreBrush alignToRight) End Sub End Class 关于行颜色定义的类 Imports System Windows Forms Namespace Truck_WEB Public Class DrawDGClass Public Class ReDrawDataDridControls : Inherits DataGridColoredTextBoxColumn Public Sub DrawCorol(ByRef DG As DataGrid Optional ByVal CurrentRowindex As Integer = ) 设置选中的行的颜色 默认是第一行选中 Dim dt As DataTable Dim ts As New DataGridTableStyle() ts AllowSorting = False Dim aColumnTextColumn As DataGridColoredTextBoxColumn dt = CType(DG DataSource DataTable) ts MappingName = CType(DG DataSource DataTable) TableName DG TableStyles Clear() Dim numCols As Integer numCols = dt Columns Count Dim i j As Integer i = j =
lishixinzhi/Article/program/net/201311/12321