INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

ComboBox and Font List

ComboBox and Font List

(OP)
Hi All,
I've implemented a container into a ribbon bar that has RTF editing controls for fonts in it. I have a drop-down box for font name and font size, which populates from system fonts. In the INIT of the control in the container I have:

CODE

DIMENSION lcFontList[1]
*
=AFONT(lcFontList)
*
FOR lnLoopCount = 1 TO ALEN(lcFontList)
	THIS.AddItem(lcFontList[lnLoopCount])
ENDFOR
*
This.Value = lcFontList(190) && Set initial Font value to Populate Font Size List
This.DisplayValue = This.Value
*
THIS.Parent.CboRTFFontSize.FillList(THIS.Value) 

But the dropdown is always blank. I can pick an item from the dropdown list, and then it is displayed, but I can't get it to set an initial value.
RowSource is set to none, and RowSourceType is set to 0 on the control. I've tried setting this to 5 - Array, and setting the RowSource to lcFontList, but that ends in an error that crashes VFP.

Any idea how to fix this?

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

Why are you using a constant (190) here (are there 190 fonts):

CODE

This.Value = lcFontList(190) 

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: ComboBox and Font List

(OP)
Hi Grif,
I had it set to 1 (which didn't display anything) but the first item in the list is @Arial Unicode MS, not exactly a default I want. Segoe UI is my default font, so I wanted that one to come up, and it's #190 in my list. It was more for a test than to keep that one there, I meant to set that back to 1 before I posted the code, but it does not have an impact either way, as there are well over 200 elements in the array...

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

I think then it is possible that setting the default you want might be better in the form's or the container's INIT, rather than the listbox's.

I don't think it SHOULD make a difference, but listboxes are funny things and don't always play by the rules so to speak.

I think that is why some people use grids instead of listboxes?

Got to be worth a try.

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: ComboBox and Font List

You set the Listindex property to 190. Or rather do it this way in the combobx init, for example:

CODE

DIMENSION lcFontList[1]
*
=AFONT(lcFontList)
*
FOR lnLoopCount = 1 TO ALEN(lcFontList)
	THIS.AddItem(lcFontList[lnLoopCount])
	IF lcFontList[lnLoopCount] == "Segoe UI"
	   This.ListIndex = lnLoopCount
	Endif
ENDFOR 

Bye, Olaf.

RE: ComboBox and Font List

Set the .Style of the ListBox to 2 to set it as drop-down list.

Then, at the Init, this will do (taking from your code):

CODE --> VFP

DIMENSION lcFontList[1]
*
=AFONT(lcFontList)
*
FOR lnLoopCount = 1 TO ALEN(lcFontList)
	THIS.AddItem(ALLTRIM(lcFontList[lnLoopCount]))
ENDFOR
*
This.Value = "Segoe UI" && or something you stored elsewhere
*
THIS.Parent.CboRTFFontSize.FillList(THIS.Value) 

RE: ComboBox and Font List

(OP)
Hi Olaf,
Thanks, that's a much better way to set that default. I still didn't have any display values in font or size, but after looking around a bit I discovered that the control on the form had something in the object's INIT (but also had a DODEFAULT()) so it was interfering with the inherited behavior from the control's init. I reset it to default, and then it did just what I wanted (mostly).

So one other question now... I have the font in the box appear in the style of the font. It didn't occur to me that the fonts in the list would adopt the same style. I'm kind of aiming for the kind of font pick list you get in something like Word, where each item in the drop-down (in the array) appears in its font style. Is it possible to achieve this too?

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

I don't think you can do that in a combo/list box - you could have an example font next to the combo which changed as you selected the various items.

If you used a grid instead of a combo/list you could use the DynamicFontName to simulate what you are after.

Have a look here FAQ184-1891: How can I create a SuperCombo?


Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

RE: ComboBox and Font List

Actually, Scott, you can do this - although it doesn't look very pretty.

The trick is to first define a popup menu containing the fonts that you want to display, using DEFINE POPUP. That way, you can style each bar in the menu with whatever font, style, colour, etc., you like.

You then set your combo box's RowSourceType to 9 - POPUP, and set the RowSource to the name of the popup.

It might take a bit of experimenting to get it to look nice, but it should be do-able.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ComboBox and Font List

Scott,

Although I've suggested a way for you to diplay a font menu in the way you want, I have to ask if this is really a good idea. I know they do it in some Microsoft apps, but it's not always the best way to show the user what font they are getting. For one thing, the font name might not be readable in its own font - as is the case with Symbol, Wingdings, etc. And even if the font displays normal characters, it's not necessarily completely legible. Also, the font name is usually too short to show a reasonable sample of the font.

Do you have a reason for not using the standard Windows Font Picker dialogue - as per GETFONT()? Not only does that show you a sample of the font (albeit a fairly useless one), it also lets you pick the style and the size. That would seem to me to be a better solution to the problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ComboBox and Font List

If you want the font picker,why not use it? GETFONT()

Trying to redo that dialog just in part is just a nightmare.

Bye, Olaf.

RE: ComboBox and Font List

(OP)
Hi Mike,
It may or may not be a good idea. I had a feeling after seeing the first result that getting this to work was likely a bit messy. My "driver" for it is for my RTF boxes to have a nice interface, and I've really replicated the Font control in my ribbon bar to look exactly like that of Office, so it's a very familiar feeling to my users. I was just trying to extend the experience a bit further, to mimic the font dropdown (though personally, I hate having to scroll from A to S when I'm looking for a font deep in the list, for example). But I will try your idea, I can see how that can be set up and used as the control source. If it doesn't work out, that's ok, at least I gave it a shot.

Olaf,
In answer to your question, I actually didn't realize GETFONT() existed. I just did a quick trial with it in the command window, and that is REALLY cool. But I see it as a secondary option like it is in Office, but I will add this on the pullout menu of the Ribbon bar for extended control. Very cool... too bad it doesn't have all the other font controls like it does in Office, with the other properties like color, strikethrough, super/subscript, etc. But it's still a handy item! I never expected they had implemented such a thing. Sometimes it's a curse to have roots all the way back to FPD2.0.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

Scott,

If I was in your position, I would consider creating my own version of the standard Font Picker dialogue - the one you get with GETFONT().

My version would have the following enhancements:

- A more useful font sample: one that shows the entire alphabet plus a short bit of text that the user can customise;

- Ability to be resized, to allow the user to see the larger font sample, especially at larger point sizes;

- The ability to specify other attributes of the font, such colour, underline, strikethrough, etc.

I realise that doesn't fit in with your idea of a ribbon-style menu. I can't visualise exactly what you have in mind, but I wonder if a simple popup-style VFP menu wouldn't be the answer? In other words, as I suggested in my earlier post, but don't bother with the combo box; just display the menu.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ComboBox and Font List

(OP)
Hi Mike,
Your point is well taken. It may be worth taking a couple days to create a custom form that will mimic the results from the Office style expanded "Font" control. I like the idea of fast pick from a font list when you know what you want. But I think it's a good approach for what I want.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

Scott, if you do decide to create a custom font dialogue, there is another feature that might be worth considering. My suggestion is that you determine the (say) four fonts that are most often selected by the user, and place those at the very top of the list, perhaps with a horizontal bar below them.

But whether this would be a genuine time-saver, or whether it would only confuse the user, is something that you will have to decide for yourself.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ComboBox and Font List

I always think of seeing the font name in the font design as only partially helpful. It fails for obvious reasons on dingbats and it often is unreadable as a too small font size. You can't have a different font per combobox item, so that will become a thing for a custom grid making use of dynamic properties in some way to also set fontname.

Bye, Olaf.

RE: ComboBox and Font List

Quote:

You can't have a different font per combobox item

Well, yes you can - using the method I suggested (and which I think Scott said he would try).

But I agree that setting the font name in the font itself isn't always a good idea (for the reasons I stated earlier).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ComboBox and Font List

(OP)
Mike & Olaf,
Lots of great ideas here, and I'm working on the expanded font. So in my "short term", I have left the font in the drop-down as the default (Segoe UI) for all fonts, until I can work on the pop-up suggested by Mike (in the next day or two, I'm a little unwell today). I noticed that Microsoft Office team see what you see, and any font that doesn't result in an alphabet, gets set to some default, so for things like Wingdings and Dingbats, they will appear in name in the drop-down as Segoe UI, while others will display in their native appearances.

I like Mike's idea for a more advanced control, and that will be the second part. I again think this will be a day or two to develop. We're "slowly" moving toward more RTF controls, and as we do that, this becomes really useful. We have a lot of reports that will look more modern when we start applying RTF to them, which we tested last year, but I had to put aside for a while during a heavy work season (the kind that pays us, versus the kind where I sit and update our enterprise app. :)

Will post up a image once I've got it working.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

Scott,

I have this combobox selectfonts.vcx which may be usefull for you.
Please download from my blog: Link

Regards,

Koen

RE: ComboBox and Font List

(OP)
Thanks, Koen, there is some interesting stuff in that control, but also things like Publics, which I wish to avoid, but the code itself was very helpful.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox and Font List

Scott,
just in case you change / improve this code by eliminating the public arrays, I would like to see the newly created.
Regards,
Koen

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close