Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

SftBoxItems.AddFontStyles Method

Adds a list of available font styles.

Syntax

VB.NETCount = object.AddFontStyles(ByVal FontName As String, ByVal hDCPrinter As Integer, ByVal StylesText As String, ByVal ItalicText As String) As Integer
VBCount = object.AddFontStyles(ByVal FontName As String, ByVal hDCPrinter As Long, ByVal StylesText As String, ByVal ItalicText As String) As Long
C#.NETint Count = object.AddFontStyles(string FontName, int hDCPrinter, string StylesText, string ItalicText);
VC++long Count = object->AddFontStyles(_bstr_t FontName, long hDCPrinter, _bstr_t StylesText, _bstr_t ItalicText);
CHRESULT object->raw_AddFontStyles(BSTR FontName, long hDCPrinter, BSTR StylesText, BSTR ItalicText, long* Count);

object

A SftBoxItems object.

FontName

The name of the font whose available styles are to be added to the control.

hDCPrinter

Specify a valid printer device context handle if the font FontName is a printer font. Specify 0 for screen fonts.

StylesText

The font style text for each possible font style. Supply comma-delimited styles for each of the following font weights. The font weights are listed in ascending weight, lightest to darkest:

Font WeightDescription
FW_THINvery light font
FW_EXTRALIGHT
FW_LIGHT
FW_NORMALnormal font
FW_MEDIUM
FW_SEMIBOLD
FW_BOLDbold font
FW_EXTRABOLD
FW_HEAVYvery heavy font

As fonts are enumerated by the control, the font weight returned by Windows is replaced by the substring supplied in StylesText for the corresponding weight. The font weights are documented in the Windows API reference, see the LOGFONT structure. If an empty string (0, null, NULL) is specified for this parameter, the default string "Normal,Normal,Normal,Normal,Bold,Bold,Bold,Bold,Bold" is used.

ItalicText

The string appended to the font style if a font has the italic attribute. If an empty string (0, null, NULL) is specified for this parameter, the default string ", Italic" is used.

Count

Returns the number of font styles added to the control.

Comments

The AddFontStyles method adds a list of available font styles.

The AddFontStyles method adds all available font styles of the font FontName to the combo box as items. The combo box is cleared first.

Font styles are added in ascending order, according to the font's weight.

The Cell.Data property of the cell in column 0 of each item will contain the font weight. The high order bit is set if the font style is italic.

The drop down portion is automatically hidden when the combo box contents are changed using this method. The DropDown.SuppressOn method can be used to suppress hiding the drop down portion when adding/inserting items.

Examples

VB.NET

    fontNames.Columns.MakeOptimal(0)
    fontNames.Items.RecalcHorizontalExtent(0)
End Sub

Private Sub UpdateFontStyles()
    ' add all styles for the current font name
    If fontNames.Items.Selection >= 0 Then
        Dim OldText As String = fontStyles.Edit.Text
        fontStyles.Items.AddFontStyles(fontNames.get_Cell(fontNames.Items.Selection, 0).Text, 0, "", "")
        Dim index As Integer = fontStyles.Items.Find(OldText, 0, 0, False, True, True)
        If index < 0 Then index = 0
        fontStyles.Items.Selection = index
    Else
        fontStyles.Items.Clear()
    End If
    PerformSort(fontStyles, SftBoxSortConstants.sortSftBoxAscending)

VB6

    End If
End Sub

Private Sub UpdateStyles()
    Dim OldText As String, Index As Long
    ' add all styles for the current font name
    If FontNames.Items.Selection >= 0 Then
        OldText = FontStyles.Edit.Text
        FontStyles.Items.AddFontStyles FontNames.Cell(FontNames.Items.Selection, 0).Text, 0, "", ""
        Index = FontStyles.Items.Find(OldText, 0, 0, False, True, True)
        If Index < 0 Then Index = 0
        FontStyles.Items.Selection = Index
    Else
        FontStyles.Items.Clear
    End If
    PerformSort FontStyles

C#

    fontNames.Items.RecalcHorizontalExtent(0);
}

private void UpdateFontStyles()
{
    // add all styles for the current font name
    if (fontNames.Items.Selection >= 0) {
        string OldText = fontStyles.Edit.Text;
        fontStyles.Items.AddFontStyles(fontNames.get_Cell(fontNames.Items.Selection,0).Text, 0, "", "");
        int index = fontStyles.Items.Find(OldText, 0, 0, false, true, true);
        if (index < 0) index = 0;
        fontStyles.Items.Selection = index;
    } else
        fontStyles.Items.Clear();
    PerformSort(fontStyles, SftBoxSortConstants.sortSftBoxAscending);
    fontStyles.Columns.MakeOptimal(0);

C++

void CFontDlgDlg::UpdateFontStyles()
{
    // add all styles for the current font name
    ISftBoxPtr vFontNames = m_FontNames.GetControlUnknown();
    ISftBoxPtr vFontStyles = m_FontStyles.GetControlUnknown();

    if (vFontNames->Items->Selection >= 0) {
        CString OldText((LPCTSTR) vFontStyles->Edit->Text);
        vFontStyles->Items->AddFontStyles(vFontNames->Cell[vFontNames->Items->Selection][0]->Text, 0, "", "");
        long index;
        vFontStyles->Items->raw_Find((_bstr_t)OldText, 0, 0, VARIANT_FALSE, VARIANT_TRUE, VARIANT_TRUE, &index);
        if (index < 0) index = 0;
        vFontStyles->Items->Selection = index;
    } else
        vFontStyles->Items->Clear();
    PerformSort(vFontStyles, sortSftBoxAscending);

See Also SftBoxItems Object | Object Hierarchy


Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.