none
VSTO sizing of controls off by one pixel? RRS feed

  • Question

  • Hello all,

    If you take a close look at the image below you'll notice that white lines appear on the bottom and right sides of each control. I've changed the background color and zoomed in to make it obvious. These controls were added to a sheet in a workbook project and were chosen at random from the toolbox.

    Zoomed in controls

    The lines become quite obvious when trying to line up controls with cell borders, matching up background colors, etc.

    Is there any way to fix this so that the control fills the entire control site?  I've tried working around it with the Resize event but that causes other issues.  

    The project above was created with Visual Studio 2010/Excel 2010 on Windows 7. 

    Many thanks,

    Rob

    Thursday, May 24, 2012 5:19 AM

All replies

  • Hi Rob

    FWIW I think what you're seeing is the "Border" property, that makes the control look "real" rather than "flat". Your only other choice is to set the Border property to "None" (part of "FlatStyle" for some controls, rather than Border).


    Cindy Meister, VSTO/Word MVP

    Thursday, May 24, 2012 12:25 PM
    Moderator
  • Hi Cindy,

    Thanks for your reply.  Let me provide another example.  Here are labels, displayed in VSTO with a BorderStyle of None and FixedSingle.

    Excel Labels

    Here are labels with similar property settings displayed in a WinForm:

    Any ideas on how to fix the VSTO display behavior so that it matches that in WinForms?

    Rob

    Friday, May 25, 2012 1:37 AM
  • Hi Rob

    I don't think so. The WinForms controls are "packed" into ActiveX controls that are managed by the Office application as graphical objects. What you're seeing is probably this ActiveX control container.

    If you right-click on the control you can access the graphics formatting commands. These affect the "container", not the actual control, although it will seem to, at first. so go to the Picture tab and crop the control from the bottom and the right. Everything will seem to be fine, but if you then press F5 to debug the workbook you'll see that the settings made in graphics mode won't change the way VSTO presents the control in its container - it's all hard-wired: that container is part of the control and you need to allow for it.


    Cindy Meister, VSTO/Word MVP

    Friday, May 25, 2012 5:32 AM
    Moderator
  • Hi Cindy,

    Yes, I think you're right that it's the ActiveX container. Your comments about the graphics formatting commands gave me an idea. I changed the fill color to red via the right-click menu with the following result:

    Label with red border

    So here are my observations:
    - I have been able to "trick" VSTO into letting my custom control fill the entire container by adding 1 to the height and width during the Resize event. Unfortunately, this causes performance issues as the container checks the size of my control each time it renders it and attempts to change the size back.
    - Given the above result and the fact that the fill color can be seen above, it seems that the area is clearly available to be filled (it's not a hard-wired border, etc.)
    - I can see in the stack trace that VSTO is setting the size of the container/control

    I can't imagine that this is intended behavior.  I'm guessing that it hasn't been noticed before simply due to the fact that the default cell and container fill colors are both white. 

    Could this be reported as a bug?

    Thanks,
    Rob
    Monday, May 28, 2012 12:54 AM
  • Hi Rob

    <<Could this be reported as a bug?>>

    I doubt very much whether you'd get any action on this after the "feature" has been around for more than seven years. But that's just my guess, based on experience. You can certainly try reporting it on Connect as a bug and see what the product group says.


    Cindy Meister, VSTO/Word MVP

    Monday, May 28, 2012 6:41 AM
    Moderator