以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 还原字体的简便方法  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=77105)

--  作者:lsy
--  发布时间:2015/11/11 10:08:00
--  [求助] 还原字体的简便方法
Dim str As String = CurrentTable.Font.Name & "|" & CurrentTable.Font.Size & "|" & CurrentTable.Font.Style
Output.Show(str)  \'str = "宋体|9|0"

CurrentTable.Font = New Font(str.Split("|")(0),CInt(str.Split("|")(1)),CInt(str.Split("|")(2)))

红色部分报错。

可以用动态函数解决问题,但是太啰嗦:
Dim fntstyle() As String = {"FontStyle.Regular","FontStyle.Bold","FontStyle.Italic","FontStyle.Bold Or FontStyle.Italic","FontStyle.Regular Or FontStyle.Underline","FontStyle.Bold Or FontStyle.Underline", _
"FontStyle.Italic Or FontStyle.Underline","FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline","FontStyle.Regular Or FontStyle.Strikeout","FontStyle.Bold Or FontStyle.Strikeout", _
"FontStyle.Italic Or FontStyle.Strikeout","FontStyle.Bold Or FontStyle.Italic Or FontStyle.Strikeout","FontStyle.Regular Or FontStyle.Strikeout Or FontStyle.Underline", _
"FontStyle.Bold Or FontStyle.Strikeout Or FontStyle.Underline","FontStyle.Italic Or FontStyle.Strikeout Or FontStyle.Underline","FontStyle.Bold Or FontStyle.Italic Or FontStyle.Strikeout Or FontStyle.Underline"}

Dim code As String
Code = "Dim fnt As Font = New Font(""" & str.Split("|")(0) & """," & CInt(str.Split("|")(1)) & "," & fntstyle(str.Split("|")(2)) & ")" & vbcrlf
Code = Code & "Return fnt"
Functions.Remove("字体")
Functions.Add("字体",Code)
Functions.Complie()
CurrentTable.Font = Functions.Execute("字体")

有没有简便的方法,还原字体?

--  作者:大红袍
--  发布时间:2015/11/11 10:12:00
--  

直接保存其值

 

msgbox(FontStyle.Bold Or FontStyle.Italic)
Dim f As FontStyle = 3
CurrentTable.Font = New Font("宋体",20, f)


--  作者:lsy
--  发布时间:2015/11/11 10:24:00
--  
原来如此,谢谢。
Dim str As String = CurrentTable.Font.Name & "|" & CurrentTable.Font.Size & "|" & CurrentTable.Font.Style
Dim style As FontStyle = CInt(str.Split("|")(2))
CurrentTable.Font = New Font(str.Split("|")(0),CInt(str.Split("|")(1)),style)

--  作者:逛逛
--  发布时间:2015/11/11 10:25:00
--  
CurrentTable.Font = CurrentTable.Grid.DefaultFont
--  作者:lsy
--  发布时间:2015/11/11 10:34:00
--  
以下是引用逛逛在2015/11/11 10:25:00的发言:
CurrentTable.Font = CurrentTable.Grid.DefaultFont


存储字体值,和还原字体值,是两个场景。
存储是以文本的形式,还原不是重现数据表的现有的字体,是以前某个时点存储的字体。

[此贴子已经被作者于2015/11/11 10:36:43编辑过]

--  作者:jspta
--  发布时间:2015/11/11 12:53:00
--  
这种最好写一个类实现比较好,函数还是有太多局限性了
--  作者:逛逛
--  发布时间:2015/11/11 14:45:00
--  

 

 

理解错了?

 

 

 

1、  字体和文本互换

 

\'获取字体并转文本

Dim f As font = CurrentTable.Font

Dim fc As FontConverter = New FontConverter()

Dim strf As String = fc.ConvertToInvariantString(f)

Output.show( strf)

 

\'文本转字体

 

Dim str As String = "宋体-PUA, 12pt, style=Bold, Italic"

Dim fc As FontConverter = New FontConverter()           

Dim f As Font = fc.ConvertFromString(str)

CurrentTable.Font = f


--  作者:lsy
--  发布时间:2015/11/11 15:46:00
--  
以下是引用逛逛在2015/11/11 14:45:00的发言:

 

 

理解错了?

 

 

 

1、  字体和文本互换<!--?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /-->

 

\'获取字体并转文本

Dim f As font = CurrentTable.Font

Dim fc As FontConverter = New FontConverter()

Dim strf As String = fc.ConvertToInvariantString(f)

Output.show( strf)

 

\'文本转字体

 

Dim str As String = "宋体-PUA, 12pt, style=Bold, Italic"

Dim fc As FontConverter = New FontConverter()           

Dim f As Font = fc.ConvertFromString(str)

CurrentTable.Font = f



是个很好的方法。

谢谢!