Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-05-2004, 04:59 AM   #1
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
Visual Basic - Adjusting grid columns width

HI,

Grid column width is measured by pixels by default.
I want to set it by characters (after counting for each column the maximal length word that it would present)
But trying to use Me.ScaleMode = 4 (which supposed to be Characters mode) not works for me.
M.D. is offline   Reply With Quote
Old 10-07-2004, 09:01 AM   #2
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
Anyone can help me with this one please ???

I just want to show some table in gird. But dont want to make column width constant predefined, but instead set in runtime. Thus i count the words length, but how then i set the column with of the grid....
M.D. is offline   Reply With Quote
Old 10-07-2004, 09:25 AM   #3
Come in Ray...
 
faulkner132's Avatar
 
Join Date: Sep 2004
Posts: 1,668
An easy way to do this is assume each letter is X pixels long (I will use 10 for this example). After you have put the text in the box, simply readjust the size.

Psuedocode:
Code:
Const CHARPIXEL = 10
strData = "this is a test"

GridCell.Text = strData
GridCell.Width = Len(strData) * CHARPIXEL
Additionally, you will probably want to find the largest value before setting the width.
Not the most elegant, but it gets the job done.
faulkner132 is offline   Reply With Quote
Old 10-07-2004, 12:10 PM   #4
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
ye i search the maximal width.
and i even have function giving me exactly the values of the character pixels (height and width).

problem is it not works good enough on different sizes of words. i tried. in some point (large once) it swallows last letter and on small values it have more free space.

i mean there is probably different character sizes (depends by the letter) or it has spaces between them. i dont know.

it is possible to change scalmode, for example to characters but it not works either. or i just do something wrong...

try for 3 different words: kkk, kkkkkkk, kkkkkkkkkkk
and see the differences...
its not so good way.

but tnx anyway
M.D. is offline   Reply With Quote
Old 10-07-2004, 12:15 PM   #5
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
ScaleX(1, 4, 1) * len(gridcell.text) or Scale(len(gridcell.text), 4, 1)

scale will convert from chars to the form measurements.
M.D. is offline   Reply With Quote
Old 10-07-2004, 12:26 PM   #6
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Is the problem the fact that you are not using a fixed-width font? That would probably screw up simple character-to-pixel computations.
doctorgonzo is offline   Reply With Quote
Old 10-07-2004, 12:42 PM   #7
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
maybe maybe.
i use the default font which is: MS Sans Serif
does this font is not fixed-width? (i guess not) then what shall i use...

and i checked now when i use letters like 'q' or 'w' is screws it all cuz they are the longest.
M.D. is offline   Reply With Quote
Old 10-07-2004, 12:45 PM   #8
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Nope, that's not fixed width. Courier is, though.
doctorgonzo is offline   Reply With Quote
Old 10-07-2004, 01:16 PM   #9
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
There is Courier and Courier new.

Courier all font sizes are big - starts with 10. and when i use it all go above the calced text box size.

When i use font size 8 with Courier New, it still not improvement.

I think it has some deal with font size too.....

ScaleX( Len(text), 4, 1) prolly designed for specific font size
M.D. is offline   Reply With Quote
Old 10-09-2004, 02:20 PM   #10
Member (7 bit)
 
Join Date: Jun 2003
Location: Israel
Posts: 92
Send a message via ICQ to M.D.
HELP ME plz.

Courier is not fixed size, because when i use it, i still have too much space left afterwards..

And what about the font size..?
M.D. is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 06:54 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2