Fromatting question.

  • Thread starter Thread starter Shawn
  • Start date Start date
S

Shawn

If I want to get the number of characters returned from a database query and
then set the width of a control, what is a good formula or good practice to
do this? I have been using things like,

Dim result as Integer = Query.Length
label1.width = result * 10

But of course, the longer the text returned from the query, the wider the
control.
 
I would imagine you would need to set some sort of fixed length for Label1.
Why not check the maximum values of the column you are seeking in the
database table, then set a bendhmark maximum sixe you will allow your labelto
become. If the length of the lebel exceeds your benchmark maximum showa
message a resize it to something more realistic within the boundaries of your
application.
 
Shawn said:
If I want to get the number of characters returned from a database query and
then set the width of a control, what is a good formula or good practice to
do this? I have been using things like,

Dim result as Integer = Query.Length
label1.width = result * 10

But of course, the longer the text returned from the query, the wider the
control.

You need to use the measurestring method of a graphics object. AFAIK,
You'll need the graphics object from control you are going to put the
text in.

Hope this helps.
Chris
 
Shawn said:
If I want to get the number of characters returned from a database query
and then set the width of a control, what is a good formula or good
practice to do this? I have been using things like,

Dim result as Integer = Query.Length
label1.width = result * 10

But of course, the longer the text returned from the query, the wider the
control.

Check out 'Graphics.MeasureString'.
 

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

Back
Top