locked
how can i get the font of an text box RRS feed

  • Question

  • is there anyway for me to get the font of a textbox using in C# (using infopath 2010) ?
    the font data does not show up in the xml.
    • Edited by UDFT Wednesday, December 21, 2011 9:01 PM
    Wednesday, December 21, 2011 8:54 PM

Answers

  • The font data won't be stored in the XML, the font information would be stored in the form template, the XML will only show the data. More specifically the font information is stored against the control which would display the data, because you could actually show the same data several times with different fonts.

    The obvious exception to this would be a rich text field where font information may be a part of the data, but I believe only if the user specifies a particular font, otherwise it will just use the font set in the template.

    For a standard text field, I'm not sure it is possible to get this from C# code in the form, but the font should only change if you change it in the template

     

    Tuesday, January 3, 2012 12:47 PM
  • Hi UDFT,

    You cannot retrieve the font of a textbox via managed code.  You do not have programmatic access to the control itself, only the XML node in which that control represents.  As you discovered, this data is not stored.

    I just double checked, and like Steven Mulkerrins mentioned, the font information will only be stored in the InnerXml of a Rich Text Box if it had been changed to something other than default.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Ian Kavanagh
    Microsoft Online Community Support

    Wednesday, January 4, 2012 6:57 PM

All replies

  • The font data won't be stored in the XML, the font information would be stored in the form template, the XML will only show the data. More specifically the font information is stored against the control which would display the data, because you could actually show the same data several times with different fonts.

    The obvious exception to this would be a rich text field where font information may be a part of the data, but I believe only if the user specifies a particular font, otherwise it will just use the font set in the template.

    For a standard text field, I'm not sure it is possible to get this from C# code in the form, but the font should only change if you change it in the template

     

    Tuesday, January 3, 2012 12:47 PM
  • Hi, You can also use a conditional formatting into the field in the form template in order to change your textbox font. For example if you are placing a conditional formatting into the textbox : If(field1 is empty) => put my font to red. It is possible to do this simply without code. Hope this helps.
    Visit my blog : http://rmatayron.blogspot.com/
    Wednesday, January 4, 2012 7:39 AM
  • Hi UDFT,

    You cannot retrieve the font of a textbox via managed code.  You do not have programmatic access to the control itself, only the XML node in which that control represents.  As you discovered, this data is not stored.

    I just double checked, and like Steven Mulkerrins mentioned, the font information will only be stored in the InnerXml of a Rich Text Box if it had been changed to something other than default.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Ian Kavanagh
    Microsoft Online Community Support

    Wednesday, January 4, 2012 6:57 PM