find a bug to Lebans's AutoSizeTextBox

R

riccifs

Hi Stephen,

Recently, I used on my form a your example, http://www.lebans.com/autosize_textbox.htm,
to resize automatically the width of text box to fit its content.
Of course it works great and I am very happy about it.
But If I try to insert this symbol &, the box doesn't fit any more the
text in it!
I tried even with your example, if I add a new record and write on any
text box ''Dog & Cat''. It doen't works but if I try with ''Dog and
Cat'' it works great.
Why!!

Please let me known any idea about that!
Many thanks
Stefano
 
R

ruralguy via AccessMonster.com

I haven't tried it but have you tried doubling up the ampersand? "&&"
 
S

Stefano

yes I have... there is no way, if yuo insert the & or &&, the code stop to
works.
thanks the same...
Stefano.
 
S

Stephen Lebans

Here is the info direct from MSDN on the DrawText API call I use in that
solution:
http://msdn2.microsoft.com/en-us/library/ms533909.aspx
Turns off processing of prefix characters. Normally, DrawText interprets the
mnemonic-prefix character & as a directive to underscore the character that
follows, and the mnemonic-prefix characters && as a directive to print a
single &. By specifying DT_NOPREFIX, this processing is turned off. For
example,
input string: "A&bc&&d"
normal: "Abc&d"
DT_NOPREFIX: "A&bc&&d"Compare with DT_HIDEPREFIX and DT_PREFIXONLY.





So at the top of the modfAutosizeMultiCode module add the following
declaration:

Private Const DT_NOPREFIX = &H800



Now scroll down to the DrawText call itself and change it from the existing:

lngRet = apiDrawText(hdc, ctl.Value, -1, sRect, DT_CALCRECT + DT_TOP +
DT_LEFT)

to

lngRet = apiDrawText(hdc, ctl.Value, -1, sRect, DT_CALCRECT or DT_TOP or
DT_LEFT or DT_NOPREFIX )

' Please note I also changed the "+" to "Or" as you must Or the Flags
together when combining them. In this case you do not have to due to the
DrawText Flag values,




--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
R

riccifs

Here is the info direct from MSDN on the DrawText API call I use in that
solution:http://msdn2.microsoft.com/en-us/library/ms533909.aspx
Turns off processing of prefix characters. Normally, DrawText interprets the
mnemonic-prefix character & as a directive to underscore the character that
follows, and the mnemonic-prefix characters && as a directive to print a
single &. By specifying DT_NOPREFIX, this processing is turned off. For
example,
input string: "A&bc&&d"
normal: "Abc&d"
DT_NOPREFIX: "A&bc&&d"Compare with DT_HIDEPREFIX and DT_PREFIXONLY.

So at the top of the modfAutosizeMultiCode module add the following
declaration:

Private Const DT_NOPREFIX = &H800

Now scroll down to the DrawText call itself and change it from the existing:

lngRet = apiDrawText(hdc, ctl.Value, -1, sRect, DT_CALCRECT + DT_TOP +
DT_LEFT)

to

lngRet = apiDrawText(hdc, ctl.Value, -1, sRect, DT_CALCRECT or DT_TOP or
DT_LEFT or DT_NOPREFIX )

' Please note I also changed the "+" to "Or" as you must Or the Flags
together when combining them. In this case you do not have to due to the
DrawText Flag values,

--

HTH
Stephen Lebanshttp://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

Hi Stephen,
Many, many thanks again for your great help.... you fixed the
problem!!
Now your code is working very well!
Are you a genius or what...!?

Thanks a lot again,
Stefano.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top