Set the width of the Label or TextBox

Started by velasquez, May 09, 2011, 02:49:59 PM

Previous topic - Next topic

velasquez

You can set the width of the Label or TextBox with the length of the string.
eg: (strlen "ABCD") -> 4
I need to work with this function OnInitialize.

Fred Tomke

Hi, velasquez,

why don't you simply use the dcl_control_setpos method within OnInitialize?

Code (autolisp) Select
(defun c:myproj_myform_OnInitialize()
  (dcl_control_setcaption myproj_myform_mylabel strData)
  (dcl_Control_SetPos myproj_myform_mylabel
    (dcl_control_getleft myproj_myform_mylabel)
    (dcl_control_gettop myproj_myform_mylabel)
    (* (strlen strData) intFontSize)
    (dcl_control_getheight myproj_myform_mylabel))
); c:myproj_myform_OnInitialize


Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

velasquez

Quote from: Fred Tomke on May 09, 2011, 03:58:54 PM
Hi, velasquez,

why don't you simply use the dcl_control_setpos method within OnInitialize?

Code (autolisp) Select
(defun c:myproj_myform_OnInitialize()
  (dcl_control_setcaption myproj_myform_mylabel strData)
  (dcl_Control_SetPos myproj_myform_mylabel
    (dcl_control_getleft myproj_myform_mylabel)
    (dcl_control_gettop myproj_myform_mylabel)
    (* (strlen strData) intFontSize)
    (dcl_control_getheight myproj_myform_mylabel))
); c:myproj_myform_OnInitialize


Regards, Fred

Thanks Fred,
I used this method in OnInitialize but it did not work.
You can post a picture showing this?

Regards, Velasquez



Fred Tomke

Hi velasquez,

I've attached a sample for you.

Please have a look at the line where nSize is defined: the FontSize value may be negative depending on the fontscaling setting. Furthermore I used the width-to-height-ratio of 0.8. It may differ from other fonts. Please note that textlength of not-conditional fonts like Arial cannot simply computed by the number of characters.

Please have a look at the line where the new width is assigned: the 4 pixels are set for the border of the control.

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

velasquez

Quote from: Fred Tomke on May 11, 2011, 10:33:14 PM
Hi velasquez,

I've attached a sample for you.

Please have a look at the line where nSize is defined: the FontSize value may be negative depending on the fontscaling setting. Furthermore I used the width-to-height-ratio of 0.8. It may differ from other fonts. Please note that textlength of not-conditional fonts like Arial cannot simply computed by the number of characters.

Please have a look at the line where the new width is assigned: the 4 pixels are set for the border of the control.

Regards, Fred

Thank you for your work Fred.
He will help me a lot I will work with a fixed font.

Regards, Velasquez