你可以用Net自带的工具帮你封装.
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.DesignerSerializationVisibility (System.ComponentModel.DesignerSerializationVisibility.Hidden)]
[System.Runtime.InteropServices.DispIdAttribute(-512)]
[System.Runtime.InteropServices.ComAliasNameAttribut("stdole.IFontDisp")]
public override System.Drawing.Font Font {
get {
if (((this.ocx != null)
&&
(this.PropsValid() == true))) {
return GetFontFromIFont(this.ocx.Font);
}
else
{
return base.Font;
}
}
set {
base.Font = value;
if ((this.ocx != null)) {
this.ocx.Font = ((stdole.IFontDisp)(GetIFontFromFont (value)));
}
}
}
如果想由自己控制,你可能参考上面的方法,但别想直接调用AxHost.GetIFontFromFont虽然它是static,但也是
protected
[C#]
protected static object GetIFontFromFont(Font font);
protected static object GetIFontDispFromFont(Font font)
但幸好AxHost是public,并且是abstract,摆名了让你继承,所以可以这样使用它们.
using System.Drawing;
public class FontHost:AxHost
{
public FontHost():base(""){
}
public static stdole.IFontDisp SubGetIFontFromFont(Font font){
return (stdole.IFontDisp)GetIFontFromFont(font);
}
}
所有Com接口都可对应object类型,返回强制转换成(stdole.IFontDisp);
如果还想低层点控制可以引入stdole命名空间,stdole命名空间位于stdole.dll里,
而stdole.dll位于
X:/Program Files/Microsoft.NET/Primary Interop Assemblies/下,在stdole中也有一个类StdFontClass实现了IFont接口.