none
Convert Pixels to IControl form width RRS feed

  • Question

  • Hi All,

    I have a form control (custom control) on a form region which I need to control the size. So I have an integer width property (pixels) that I need to set width of the control. So for example if I have to set a width of 170 pixels, and that has to be converted to a floating point value, or an integer value,  for that control and I seem not to be able to get the correct conversion. Does any body know the correct conversion for this parameter? I have tried several conversions and I am not getting a correct value. 

    Here are the functions

     
    struct __declspec(uuid("04598fc6-866c-11cf-ab7c-00aa00c08fcf"))
    IControl : IDispatch
    {
    
    .
    .
    .     
    virtual HRESULT __stdcall _SetWidth (
            /*[in]*/ long Width ) = 0;
          
    irtual HRESULT __stdcall _GetWidth (
            /*[out]*/ long * Width ) = 0;
          
    virtual HRESULT __stdcall put_Width (
            /*[in]*/ float Width ) = 0;
          
    virtual HRESULT __stdcall get_Width (
            /*[out,retval]*/ float * Width ) = 0;
    

    I have been trying to convert pixels to one of these units and I have failed miserably. Does anybody have an idea of what the correct conversion is?

    Thanks,

    Tom

    Tuesday, July 17, 2018 9:41 PM

All replies

  • I'm not sure what you are asking here.

    The data types float and int are not units of measurement.  These data types store numeric values but have different characteristics -- see Data Type Ranges

    So you can assign a numeric constant of 170 to an int variable or to a float variable or pass it as a parameter to a method. 

    Tuesday, July 17, 2018 10:44 PM
  • Hello Thomas,

    Why do you need to change the size of controls on a form region? What is your final goal?

    Anyway, I'd suggest placing controls into layout panels where your controls can be docked, so when you resize the form region the size of your controls will be changed appropriately. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Wednesday, July 18, 2018 10:22 AM
  • Hi,

    Sorry, let me clarify. If I call the function put_Width with a value of 170 (pixels), the actual width of the control, after calling that function, will be much less than 170 pixels and more equivalent to an actual size of like 20 pixels. I have tried all kinds of conversions to set the actual size based upon the device context, but it seems no matter which method I used, I am a wee bit off. 

    I believe I am going try to map the dialog (MapDialogRect) and see if I can figure out the conversion. I must have a calculation error somewhere.

    Thanks,

    Tom

    Wednesday, July 18, 2018 12:15 PM
  • Thanks for the reply Eugene.

    It is a pretty complicated form and many items are determined at run time and display time. In addition I have several custom controls (ActiveX controls). So resizing is problematic. I have even thought about capturing events and disabling resize, but I do not want to do that. To be completely honest, the custom controls are the problem children that are causing most of my issues.

    Thanks,

    Tom

    Wednesday, July 18, 2018 12:22 PM
  • Layout panels make the resizing process easier. You just need to dock controls properly

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Wednesday, July 18, 2018 3:35 PM