C# Font Property

236 views
Skip to first unread message

Charles Layman

unread,
Sep 28, 2015, 3:22:46 PM9/28/15
to IADS
Problem is the "set" does not get called at startup, so any changes saved are not recovered.  Tried using the C# System.Drawing.Font, but the 'property does not show in the IADS property page.  After startup, using the IADS property page, using the font selector to change the font has the expect result, 'set' and 'get' are called, dirty flag is set.  At logout prompt to save data, 'get' is called, using Visual Studio to examine 'fnt' it has the expected data.  Restarting IADS, the 'set' is again not called.

The gridFont is a System.Drawing.Font used by C# DataGrid.  The 'fnt' is a stdole.IFontDisp font object.


public stdole.IFontDisp Grid_Font
{
   get { return fnt; }
   set
      {
      gridFont = new System.Drawing.Font(value.Name, (float)(value.Size));
      fnt = value;
      isDirty = true;
      }
}

Any idea what I am missing to get the 'set' to be called at startup?

James Bretz

unread,
Sep 28, 2015, 4:57:02 PM9/28/15
to IADS
Hi Charles,
 
If I remember correctly from past discussions, there is some sort of problem between COM and C# where the dirty flag state is not sent to the interface (IPersistPropertyBag). The problem used to be that the display was always deemed “dirty” no matter what you did programmatically. It appears as though it might still be broken, but in the opposite direction (just a guess).
 
We did create a ‘back door’ to solve this issue. You might be able to use it and get results. If Iads sees a public property called “Dirty”, it will call that property to get the state of the dirty flag. Add one to your control and see if it helps.
 
Let us know how it goes,
Jim
--
You received this message because you are subscribed to the Google Groups "IADS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iads+uns...@googlegroups.com.
To post to this group, send email to ia...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iads/65f4efe6-08f9-4177-8ff2-7f17337c7de8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charles Layman

unread,
Sep 28, 2015, 6:06:37 PM9/28/15
to IADS


I should have mentioned that I have other properties with 'get/set' functions, those all get called at startup.  Also, I do have a "Dirty" property with a 'get' function.  From Tim Lafoons' thread on the Dirty flag, that is what/how I implemented mine.

James Bretz

unread,
Sep 28, 2015, 6:14:36 PM9/28/15
to IADS
Ok Charles. I understand now.
 
So apparently the system is only failing this stdole.IFontDisp type. I’ll have to build a control and step through the code.
 
I’ll let you know when I find something out,
Jim
 
Sent: Monday, September 28, 2015 3:06 PM
To: IADS
--
You received this message because you are subscribed to the Google Groups "IADS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iads+uns...@googlegroups.com.
To post to this group, send email to ia...@googlegroups.com.

James Bretz

unread,
Sep 29, 2015, 4:00:42 PM9/29/15
to IADS
Charles,
 
Sorry for the delay.
 
I ran this scenario in the debugger. It appears as though the C# interop isn’t attempting to persist the stdole.IFontDisp type property through our chosen interface IPersistPropertyBag. This is the persist interface for all custom user controls. All the other basic types (string, int, float, etc) seem to persist just fine through this interface. I’m guessing that they deemed that non essential in the interop (to our determent).
 
One way around this might be to split the stdole.IFontDisp into two other properties: fontName and fontSize. For the ‘get’ method of this property, return the ‘fnt.Name’ and the other ‘fnt.Size’. Even though the Grid_Font property won’t persist itself, the fontName and fontSize should and you’ll be able to reconstruct the gridFont variable and perhaps the fnt variable. I haven’t tried it yet, but it seems doable.
 
Also, in C++ you can set a property to ‘hidden’ to keep it from being shown in the properties sheet. You might want to try and set these two properties (fontName/fontSize) to hidden, so the user can’t set them by hand. From my quick research, this might be the [Browsable(false)] attribute in C#.
 
Hope this helps,
Jim
 
Sent: Monday, September 28, 2015 3:06 PM
To: IADS
Subject: [IADS] Re: C# Font Property
 

I should have mentioned that I have other properties with 'get/set' functions, those all get called at startup.  Also, I do have a "Dirty" property with a 'get' function.  From Tim Lafoons' thread on the Dirty flag, that is what/how I implemented mine.

Charles Layman

unread,
Sep 30, 2015, 9:22:56 AM9/30/15
to IADS
I added 2 new properties:

        [ComVisible(false)]
        string Grid_Font_Name { set; get; }
        [ComVisible(false)]
        float Grid_Font_Size { set; get; }

clever names, huh.  They work as expected.  Thanks for the suggestion.  Was not sure if it would be as easy as it turned out to be to mark them as hidden, another reason to like C#.

Originally the property stdole.IFontDisp Grid_Font { set; get; } was a System.Drawing.Font since that is the type used by the DataGridView, but that type did not show in the IADS property page.  That was the reason for using the stdole.IFontDisp type, if there is another font type that works correctly I can use that, since I am going to have to do some conversion between what is saved and what is used anyway.

James Bretz

unread,
Sep 30, 2015, 12:12:05 PM9/30/15
to IADS
Ok good news. It’s interesting that you can set the properties to ComVisible false and they still ‘persist’ through the COM interface. A bit strange, but glad it worked ;)
 
The standard COM font type is either IFont or IFontDisp. The System.Drawing.Font is probably a C# only font. It seems there’s already a function to convert between the two types: https://msdn.microsoft.com/en-us/library/system.windows.forms.axhost.getifontfromfont(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
 
Jim
 
Sent: Wednesday, September 30, 2015 6:22 AM
To: IADS
Subject: [IADS] Re: C# Font Property
--
You received this message because you are subscribed to the Google Groups "IADS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iads+uns...@googlegroups.com.
To post to this group, send email to ia...@googlegroups.com.

Charles Layman

unread,
Sep 30, 2015, 4:02:30 PM9/30/15
to IADS
You are correct, System.Drawing.Font is the C#(.Net) font.  Since I am using the IFontDisp, should use the GetIFontDispFromFont to convert the C# Font to a stdole.IFontDisp.  In either case, both are 'protected' 'static' functions, as such additional hoops to jump through to use them.  I

fnt being a stdole.IFontDisp.  Only need 'fnt' to have the values of the current gridFont when the font selector is posted, since the stdole.IFontDisp is not being saved.

Instead I took a simpler solution:

fnt.Name = gridFont.FontFamily.Name;
fnt.Size = (decimal)gridFont.Size;
fnt.Bold = gridFont.Bold;
fnt.Italic = gridFont.Italic;
fnt.Strikethrough = gridFont.Strikeout;
fnt.Underline = gridFont.Underline;


So all done now, thanks for the help

James Bretz

unread,
Sep 30, 2015, 4:55:44 PM9/30/15
to IADS
Thanks for the update. Glad it’s all working now and the answer posted for everyone else working on this issue.
 
Let us know if you have any other questions,
Jim
 
Sent: Wednesday, September 30, 2015 1:02 PM
To: IADS
Subject: [IADS] Re: C# Font Property
 
--
You received this message because you are subscribed to the Google Groups "IADS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iads+uns...@googlegroups.com.
To post to this group, send email to ia...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages