以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  Label 字体颜色的问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=84527)

--  作者:凡夫俗子
--  发布时间:2016/5/4 15:26:00
--  Label 字体颜色的问题
 ElseIf dr("控件类型")="Label" Then
                Dim strFont As String = iif(dr.Isnull("字体"),"宋体",dr("字体"))
                Dim IntFontSize As Integer=iif(dr.Isnull("字体大小"),9,dr("字体大小"))
                Dim fnt As New Font(strFont,IntFontSize ,FontStyle.Bold)
                Dim HuaKj As WinForm.Label = pnl.Form.CreateControl(dr("控件名称") , ControlTypeEnum.Label)
                With HuaKj
                    .BackColor = Color.Transparent
                    .basecontrol.cursor=System.Windows.Forms.Cursors.sizeAll
                    .text = dr("控件标题")
                    .Font=fnt
                    .ForeColor = Color.FromArgb(dr("字体颜色"))
                    .SetBounds(dr("左"),dr("上"),dr("宽"),dr("高"))
                End With
                HuaMenu.AddControl(HuaKj)
                If dr("最底层")=True Then
                    HuaKj.BackMost=True
                End If
                
            End If

这段代码 在某测试窗口里运行是正常的,Label 颜色有根据设置进行修改
但在另外一个窗口里,文字颜色打死都是黑色的,不随设置而改变

几乎同样的设置在设置 按钮控件标签的 文本字体颜色时又是生效的,为这样类似的问题 总是花费不少时间。
不知是何故。


--  作者:大红袍
--  发布时间:2016/5/4 15:46:00
--  

试试设置一下风格

 

HuaKj.VisualStyle = 0

HuaKj.ForeColor = Color.Red

 

实在不行的话,做个例子看看。


--  作者:凡夫俗子
--  发布时间:2016/5/4 16:23:00
--  
Dim pnl As WinForm.Panel = e.Form.Controls("Panel1")
Dim strFont As String = "宋体"
Dim IntFontSize As Integer= 10
Dim fnt As New Font(strFont,IntFontSize ,FontStyle.Bold)
Dim HuaKj As WinForm.Label = pnl.Form.CreateControl("KJ98888" , ControlTypeEnum.Label)
With HuaKj
    .BackColor = Color.Transparent
    .basecontrol.cursor=System.Windows.Forms.Cursors.sizeAll
    .text = "我的测试文字"
    .Font=fnt
    .ForeColor = Color.FromArgb(-15666)
    .SetBounds(10,30,160,30)
End With
pnl.AddControl(HuaKj)

新建项目 这样用 颜色是可以设置的
HuaKj.VisualStyle = 0 这个用不了,提示Label控件 不支持此参数


--  作者:大红袍
--  发布时间:2016/5/4 16:40:00
--  

那你就AddControl后,再设置颜色等属性。

 

做个不行的例子上来看看。