FontConverter fc = new FontConverter(); //转换为文本形式 string strf= fc.ConvertToInvariantString(button1.Font); Console.WriteLine("字符形式的Font:" + strf); //从文本到字体 Font f = (Font)fc.ConvertFromString(strf); button2.Font = f;C#中好象这个。
嗯,虽然回答你的答案看来像是“转成啥结果”, 但是依著这个原理,其实就是回答了你“如何转换”。比如: function FontToStr(Font: TFont); begin ....... result:=<font name="宋体" size="12" underline="true" bold="false" />; end;procedure SetFontByStr(Font: TFont; Str: String); var xml: TXML; begin xml:=parsexml(str); font.name:=xml.name; font.size:=xml.size; ...... end;有了以上二个函数/程序,只要就可以用 str:=FontToStr(Font); 和 SetFontByStr(Font, Str); 来转换了。相比于你举的C#是要多写几行代码,但确实是朝“如何转换”回答。
例如 font.toString 的结果为 <font name="宋体" size="12" underline="true" bold="false" />。
但是依著这个原理,其实就是回答了你“如何转换”。比如:
function FontToStr(Font: TFont);
begin
.......
result:=<font name="宋体" size="12" underline="true" bold="false" />;
end;procedure SetFontByStr(Font: TFont; Str: String);
var
xml: TXML;
begin
xml:=parsexml(str);
font.name:=xml.name;
font.size:=xml.size;
......
end;有了以上二个函数/程序,只要就可以用
str:=FontToStr(Font);
和
SetFontByStr(Font, Str);
来转换了。相比于你举的C#是要多写几行代码,但确实是朝“如何转换”回答。
结贴。