Hide

SftTree/OCX 7.5 - ActiveX Tree Control

Display
Print

ListFont Sample (C#)

This sample illustrates cell fonts.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - CSharp\ListFont\Form1.cs or C:\Program Files\Softelvdm\SftTree OCX 7.5\Samples\Visual Studio - CSharp\ListFont\Form1.cs (on 32-bit Windows versions).


        private void closeButton_Click(object sender, System.EventArgs e) {
            Application.Exit();
        }

        private void axSftTree1_ItemDblClick(object sender, AxSftTreeLib75._DSftTreeEvents_ItemDblClickEvent e) {
            if (e.areaType == (short) SftTreeAreaTypeConstants.constSftTreeColumnRes) {
                axSftTree1.get_Column(e.colIndex).MakeOptimal();
                axSftTree1.Items.RecalcHorizontalExtent();
            }
        }

        private void Form1_Load(object sender, System.EventArgs e) {
            axSftTree1.BulkUpdate = true;

            // Add all screen fonts to the tree control
            int ScreenIndex = axSftTree1.Items.Add("Fonts");
            axSftTree1.get_Item(ScreenIndex).Level = 0;
            // display fonts

            int counter = 0;
            foreach (FontFamily ff in System.Drawing.FontFamily.Families) {
                // add font name
                Font newFont = null;
                try {
                    newFont = new Font(ff.Name, 8);
                } catch {
                    newFont = null;
                }
                if (newFont != null) {
                    if (++counter > 50)  // only add up to 50
                        break;
                    int itemIndex = axSftTree1.Items.Add(ff.Name);
                    axSftTree1.get_Item(itemIndex).Level = 1;
                    // set the font
                    axSftTree1.get_Cell(itemIndex, 0).Font = OLECvt.ToIFontDisp(newFont);
                    // set the font name in column 1
                    axSftTree1.get_Cell(itemIndex, 1).Text = ff.Name;
                }
            }

            axSftTree1.BulkUpdate = false;
            // make column widths optimal
            axSftTree1.ColumnsObj.MakeOptimal();
            // allow horizontal scrolling
            axSftTree1.Items.RecalcHorizontalExtent();
        }
    }
}

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