{"id":5993,"date":"2007-06-04T19:55:00","date_gmt":"2007-06-04T19:55:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2007\/06\/04\/interopforms-2-0-tip-1-font-property\/"},"modified":"2024-07-05T14:45:36","modified_gmt":"2024-07-05T21:45:36","slug":"interopforms-2-0-tip-1-font-property","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/interopforms-2-0-tip-1-font-property\/","title":{"rendered":"InteropForms 2.0 Tip #1 &#8211; Font Property"},"content":{"rendered":"<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">(Starting today, we&#8217;ll be highlighting various tips that might help you when using the InteropForms 2.0 toolkit.&nbsp;&nbsp; With the latest release of the toolkit, you can do some fairly impressive upgrades to your existing VB6 applications.&nbsp; Don&#8217;t believe me?&nbsp; Check <a class=\"\" href=\"http:\/\/www.codeproject.com\/useritems\/VB6InteropToolkit2.asp\">this<\/a> out as one cool example&nbsp; &#8211; WPF in VB6 anyone?!)<\/p>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">If you don&#8217;t have it, you can download the toolkit <a class=\"\" title=\"here\" href=\"http:\/\/msdn2.microsoft.com\/en-us\/vbasic\/bb419144.aspx\">here<\/a>.<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<strong>&nbsp;<\/strong><\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\"><strong>Adding Font Property:<\/strong><\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">Here&#8217;s a tip on extending Interop Usercontrols that some of you might find useful.&nbsp;&nbsp; Most usercontrols have a &#8220;font&#8221; property associated with them which can inherit its values from its container and defines what font is used for the controls that it contains.&nbsp;&nbsp; If you want to add this support to your control, here&#8217;s what you can do.<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">1) From your VB6 Interop Usercontrol project, goto the references dialog on your project and add a reference to &#8220;stdole&#8221;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">2) Open up your interopusercontrol control and in the &#8220;VB6 Properties&#8221; region, add this code:<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<blockquote class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">\n<div><font color=\"#0000ff\" size=\"2\">Public<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shadows<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Property<\/font><font size=\"2\"> ControlFont() <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> stdole.IFontDisp<\/font><\/div>\n<div>\n<p><font color=\"#0000ff\" size=\"2\">Get<\/font><\/p>\n<p><font size=\"2\"><\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Dim<\/font><font size=\"2\"> fntTmp <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">New<\/font><font size=\"2\"> Drawing.Font(<\/font><font color=\"#0000ff\" size=\"2\">MyBase<\/font><font size=\"2\">.Font.Name, <\/font><font color=\"#0000ff\" size=\"2\">MyBase<\/font><font size=\"2\">.Font.Size, <\/font><font color=\"#0000ff\" size=\"2\">MyBase<\/font><font size=\"2\">.Font.Style, _<\/p>\n<p>System.Drawing.GraphicsUnit.Point, <\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">CType<\/font><font size=\"2\">(0, <\/font><font color=\"#0000ff\" size=\"2\">Byte<\/font><font size=\"2\">))<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Return<\/font><font size=\"2\"> ActiveXControlHelpers.GetIFontDispFromFont(fntTmp)<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">End<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Get<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\">Set<\/font><font size=\"2\">(<\/font><font color=\"#0000ff\" size=\"2\">ByVal<\/font><font size=\"2\"> value <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> stdole.IFontDisp)<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\">MyBase<\/font><font size=\"2\">.Font = ActiveXControlHelpers.GetFontFromIFontDisp(value)<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\">End<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Set<\/font><\/p>\n<p><font size=\"2\"><\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">End<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Property<\/font><\/div>\n<\/blockquote>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">3) Open up ActiveXControlHelpers.vb and add this code to the activeXControlHelpers class<\/div>\n<blockquote class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">\n<div><font size=\"2\"><\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Friend<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shared<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shadows<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Function<\/font><font size=\"2\"> GetFontFromIFontDisp(<\/font><font color=\"#0000ff\" size=\"2\">ByVal<\/font><font size=\"2\"> obj <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Object<\/font><font size=\"2\">) <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> Font<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Return<\/font><font size=\"2\"> AxHost.GetFontFromIFontDisp(obj)<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">End<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Function<\/font><font size=\"2\"><\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Friend<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shared<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shadows<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Function<\/font><font size=\"2\"> GetFontFromIFont(<\/font><font color=\"#0000ff\" size=\"2\">ByVal<\/font><font size=\"2\"> obj <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Object<\/font><font size=\"2\">) <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> Font<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Return<\/font><font size=\"2\"> AxHost.GetFontFromIFont(obj)<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">End<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Function<\/font><font size=\"2\"><\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Friend<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shared<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Shadows<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Function<\/font><font size=\"2\"> GetIFontDispFromFont(<\/font><font color=\"#0000ff\" size=\"2\">ByVal<\/font><font size=\"2\"> font <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> Font) <\/font><font color=\"#0000ff\" size=\"2\">As<\/font><font size=\"2\"> stdole.IFontDisp<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">Return<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">TryCast<\/font><font size=\"2\">(AxHost.GetIFontDispFromFont(font), stdole.IFontDisp)<\/p>\n<p><\/font><font color=\"#0000ff\" size=\"2\">End<\/font><font size=\"2\"> <\/font><font color=\"#0000ff\" size=\"2\">Function<\/font><\/div>\n<\/blockquote>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">4) You can then compile your project and reference it from VB6 and set the &#8220;controlfont&#8221; property appropriately.<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">&nbsp;<\/div>\n<div class=\"ExternalClassA5FE57680D7B44F58E5A062B55282A50\">This property was not included in the InteropForms 2.0 release since we didn&#8217;t feel like it was that common of a scenario and it can make deploying the control in the general case a bit trickier.&nbsp;&nbsp; Specifically, you need to ensure that stdole.dll is deployed in the GAC which you can install by running a setup called vs_piaredist.exe which should be installed on your machine that has VS (typically in a program filescommon filesmerge modules directory).&nbsp;&nbsp; It&#8217;s a silent install, so it&#8217;s pretty easy to deploy.&nbsp;&nbsp; However, you may find that all your clients have this installed and you don&#8217;t need to worry about this.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>(Starting today, we&#8217;ll be highlighting various tips that might help you when using the InteropForms 2.0 toolkit.&nbsp;&nbsp; With the latest release of the toolkit, you can do some fairly impressive upgrades to your existing VB6 applications.&nbsp; Don&#8217;t believe me?&nbsp; Check this out as one cool example&nbsp; &#8211; WPF in VB6 anyone?!) &nbsp; If you don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[192,195],"tags":[155,170],"class_list":["post-5993","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-visual-basic","tag-todd-apley","tag-vb6_migrationinterop"],"acf":[],"blog_post_summary":"<p>(Starting today, we&#8217;ll be highlighting various tips that might help you when using the InteropForms 2.0 toolkit.&nbsp;&nbsp; With the latest release of the toolkit, you can do some fairly impressive upgrades to your existing VB6 applications.&nbsp; Don&#8217;t believe me?&nbsp; Check this out as one cool example&nbsp; &#8211; WPF in VB6 anyone?!) &nbsp; If you don&#8217;t [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/5993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=5993"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/5993\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=5993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=5993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=5993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}