以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于动态添加控件的Font属性问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=62663)

--  作者:jiangxun
--  发布时间:2015/1/5 23:51:00
--  关于动态添加控件的Font属性问题

                    If (dr("_FontName") Or dr("_FontSize") Or dr("_FontStyle")) Is Nothing Then
                    Dim fnt As New font("宋体",9,FontStyle.Regular)
                    ctl_Label.Font = fnt
                    Else
                    ctl_Label.Font("""" & dr("_FontName") & """",dr("_FontSize"),dr("_FontStyle"))
                    End If
执行后系统提示:

从字符串“宋体”到类型“Long”的转换无效。”,请求帮助


--  作者:Bin
--  发布时间:2015/1/6 8:07:00
--  
弹出一下 dr("_FontSize") 看看   另外 dr("_FontStyle") 的值可能也不对.
--  作者:有点甜
--  发布时间:2015/1/6 9:14:00
--  

 这句,你想表达什么?

 

If (dr("_FontName") Or dr("_FontSize") Or dr("_FontStyle")) Is Nothing Then

 

 判断是否为空这样写

 

If dr.IsNull("_FontName") OrElse dr.IsNull("_FontSize") Then


--  作者:jiangxun
--  发布时间:2015/1/6 15:43:00
--  
dr("_FontSize") 的值为--宋体 dr("_FontStyle") 的值为fontstyle.regular
--  作者:Bin
--  发布时间:2015/1/6 15:45:00
--  
dr("_FontSize") 的值为--宋体  这个应该是字体大小 应该是数值类型,    这时候当然会报错

dr("_FontStyle") 的值为fontstyle.regular   这玩意是个枚举,实际值是个数值   以字符串形式显示 fontstyle.regular  也是不对的

--  作者:jiangxun
--  发布时间:2015/1/6 15:54:00
--  
                    Dim fnt As Object

                    If dr.IsNull("_FontName") OrElse dr.IsNull("_FontSize") OrElse dr.Isnull("_FontSize") Then
                    fnt.name ="宋体"
                    fnt.Size = 9
                    fnt.FontStyle = FontStyle.Regular
                    ctl_Label.Font = fnt
                    Else
                    fnt.name =dr("_FontName")
                    fnt.Size = dr("_FontSize")
                    fnt.FontStyle = dr("_FontStyle")

                    ctl_Label.Font = fnt
                    End If

错误提示:未设置对象变量或With块变量


--  作者:有点甜
--  发布时间:2015/1/6 16:00:00
--  

fnt没有赋值

 

Dim fnt As New font("宋体", 9, FontStyle.Regular)


--  作者:Bin
--  发布时间:2015/1/6 16:00:00
--  
你某个变量是空值.
--  作者:jiangxun
--  发布时间:2015/1/6 16:02:00
--  
这个是在一个循环于语句里,每次重复赋值可能不行,我也没有好的办法所以就这样了
--  作者:有点甜
--  发布时间:2015/1/6 16:09:00
--  

 赋值这样做啊

 

Dim fnt As New font("宋体", 9, [Enum].Parse(Gettype(FontStyle), "Regular"))