Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Listing out items (fonts) displaying them in the correct format.

Posted on 2004-11-30
21
Medium Priority
?
265 Views
Last Modified: 2013-12-03
I have 3397 fonts installed on my computer and have a hard time trying to find the font I am looking for. I wrote a simple program where I can quickly go thru all the fonts installed by clicking down on the drop down menu. It all works fine but I want to improve it some. Right now it looks like this....
http://www.eznetideas.com/brad/fonts-1.gif

and I want it to look like this..
http://www.eznetideas.com/brad/fonts-2.gif

This way it will list out all the fonts in a row where I can scroll down and see more then one font per a page. I am not sure how this would be done so can you help me get started?
0
Comment
Question by:redbrad0
  • 11
  • 10
21 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12709733
You could use an owner drawn listbox to show the fonts:

Change the Style of a Control / Owner Drawn Controls
http://www.thescarms.com/vbasic/OwnerDrawn.asp
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12709756
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 1200 total points
ID: 12710110
The control from VBAccelerator is actually pretty easy to use.  Set the style to ecsListBox and the work is done!

Option Explicit

Private Sub Form_Load()

Dim f As StdFont
Dim i As Long
Dim height As Single

Set f = Me.Font

For i = 0 To Screen.FontCount - 1

    f.Size = 12
    f.Name = Screen.Fonts(i)
    f.Bold = False
    f.Italic = False
   
    height = TextHeight("|_^") / Screen.TwipsPerPixelY
   
    OwnerDrawComboList1.AddItemAndData f.Name, , , , , , , height, , , f

Next


End Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:redbrad0
ID: 12711435
Is VBAccelerator a component to add into visual basic 6?
0
 

Author Comment

by:redbrad0
ID: 12711845
Sorry for being such a idiot but I am not a VB6 programmer just a ASP one. I added the vbalODCL6.ocx (VBAccelerator) component but was unsure what I needed to do with that additional file that is needed to run (the .dll file)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12712296
Ok, place vbalODCL6.ocx and ssubtmr6.dll  into your Windows\system32 directory.

Open the command window (Start->Run "cmd")

Then register the components at the command prompt, one at a time with the following commands:

regsvr32 vbalODCL6.ocx

=and then=

regsvr32 ssubtmr6.dll

if all goes well, you can then add the component to your VB form.  Project->Components then check "vbaccelerator Owner Draw Combo..."

That's it!  Let me know if you have any questions.
0
 

Author Comment

by:redbrad0
ID: 12716889
Erick,

Thanks a ton that helped so much.... Can you just let me know what this line of code is doing?

height = TextHeight("|_^") / Screen.TwipsPerPixelY
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12717434
That's a good question.

TextHeight is a member function of the form which returns the height of the string passed in in Scale units.  The default scalemode for the form is Twips, so to convert to pixels we need to divide by Screen.TwipsPerPixelY (usually 15).

The string can be anything, "abc", "XYZ", "|_^", etc...

There is a problem with my code and I'm glad you asked the question.  The function uses the font currently selected in the form, so in the example above it does not get the height of each font in the loop.  To correct this, you need to set the form's font:

For i = 0 To Screen.FontCount - 1

    f.Size = 12
    f.Name = Screen.Fonts(i)
    f.Bold = False
    f.Italic = False
   
    Set Me.Font = f '<<---  Set the form font before calling TextHeight    

    height = TextHeight("abc") / Screen.TwipsPerPixelY
   
    OwnerDrawComboList1.AddItemAndData f.Name, , , , , , , height, , , f

Next

This is all optional, you can just hardcode the value of height if you like, and it will probably run a bit faster as well.

Hupe it helps!
0
 

Author Comment

by:redbrad0
ID: 12717859
Well it works exactly as I wanted it to except I can not figure out just a few things..... When the item is selected it does not show in the correct font, size or style. I really want it listed out like the previous list shows where you can see them without having to use a drop down menu. Then I want to be able to change the font size or make all the fonts bold if I want to. Sorry I am making this such a pain :(
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12718015
"I really want it listed out... " 

Set the style to ecsListBox.

"I want to be able to change the font size or make all the fonts bold ..."

Change the font properties in the loop before adding the fonts to the list:

f.Size = 12
f.Name = Screen.Fonts(i)
f.Bold = False
f.Italic = False
0
 

Author Comment

by:redbrad0
ID: 12718752
perfect on the listing out... sorry i should of been more clear but changing the font size after it is all loaded up with my fonts without having to reload them.
0
 

Author Comment

by:redbrad0
ID: 12718757
Do you have a paypal address that I can donate some money to you for being so helpful?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12718825
You cannot change the size or style without reloading them.  Perhaps you can use a preview window to display variations of the font currently selected from the list.

Points will suffice :)
0
 

Author Comment

by:redbrad0
ID: 12719371
Ok I think I almost have it then......
I read the two pages you put on here and it did not say anything about columns. I tried to set the property to 2 columns and then nothing would display. Is there a different content to add items into column1 & column2?

More points added for you :-)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12719832
To use columns, set the Column property to 2 and you also have to set the column widths in code:

OwnerDrawComboList1.ColWidth(1) = 100 'pixels
OwnerDrawComboList1.ColWidth(2) = 200
OwnerDrawComboList1.ColType(1) = ectTextString
OwnerDrawComboList1.ColType(2) = ectTextString

when you add the data, the tab character splits the text into the columns:

OwnerDrawComboList1.AddItemAndData "Column 1 Text" & vbTab & "Column 2 Text"
0
 

Author Comment

by:redbrad0
ID: 12720232
I tried to do this but I am trying to have it where its in one column and then becomes two. So what I did was add two boxes and just hide the 1 column when I need the two column. I know its showing the two column box but it just is still only adding one column and not the second one. Here is a link to the zip file if it helps (source code)

Brad

http://www.eznetideas.com/brad/ShowFont.zip
0
 

Author Comment

by:redbrad0
ID: 12721779
nevermind looks like i figured that part out
0
 

Author Comment

by:redbrad0
ID: 12722221
I tried to run the exe file on another PC and the ocx file was not registered. Is there a way to have it included in the VB Project?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12722308
You have to run Package and Deployment Wizard to make a Setup for your program.  That way, all the dependencies that your program needs are distributed and installed properly on the target machine.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/setpwz98/html/vbconsetupwizardoverview.asp
0
 

Author Comment

by:redbrad0
ID: 12722351
Thanks for all your help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month15 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question