HeaderPane
Main
Hide
Share Link
Print

Colors Sample (C#)

This sample illustrates using SftBox/OCX for color selection.

The source code is located at C:\Program Files (x86)\Softelvdm\SftBox OCX 6.0\Samples\Visual Studio - CSharp\Colors\Form1.cs.


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

        private void AddColor(AxSftBoxLib60.AxSftBox box, string Text, Color color)
        {
            SftBoxLib60.SftBoxCell oneCell;
    
            int addColor = box.Items.Add(Text);     // add a new item
            oneCell = box.get_Cell(addColor, 0);    // get the first cell
            oneCell.Image.Height = 13;
            oneCell.Image.Width = 13;
            if (box == SftBox2)
                oneCell.Image.Width = 26;
            else
                oneCell.Image.Width = 13;
            oneCell.Image.SetColorSample(OLECvt.ToOleColor(color), OLECvt.ToOleColor(Color.Black)); // set the cell's color sample
            // We'll save the color value in the cell's Data property so
            // we can use the Items.FindCellData method if needed
            oneCell.Data = ColorTranslator.ToWin32(color);
        }

        private void AddColors(AxSftBoxLib60.AxSftBox box)
        {
            AddColor(box, "Black", Color.Black);
            AddColor(box, "Blue", Color.Blue);
            AddColor(box, "Cyan", Color.Cyan);
            AddColor(box, "Green", Color.Green);
            AddColor(box, "Magenta", Color.Magenta);
            AddColor(box, "Red", Color.Red);
            AddColor(box, "White", Color.White);
            AddColor(box, "Yellow", Color.Yellow);
            AddColor(box, "Scroll bar color", Color.FromKnownColor(KnownColor.ScrollBar));
            AddColor(box, "Desktop color", Color.FromKnownColor(KnownColor.Desktop));
            AddColor(box, "Color of the title bar for the active window", Color.FromKnownColor(KnownColor.ActiveCaption));
            AddColor(box, "Color of the title bar for the inactive window", Color.FromKnownColor(KnownColor.InactiveCaption));

            AddColor(box, "Menu background color", Color.FromKnownColor(KnownColor.Menu));
            AddColor(box, "Window background color", Color.FromKnownColor(KnownColor.Window));
            AddColor(box, "Window frame color", Color.FromKnownColor(KnownColor.WindowFrame));
            AddColor(box, "Color of text on menus", Color.FromKnownColor(KnownColor.MenuText));
            AddColor(box, "Color of text in windows", Color.FromKnownColor(KnownColor.WindowText));
            AddColor(box, "Color of text in caption, size box, and scroll arrow", Color.FromKnownColor(KnownColor.ActiveCaptionText));
            AddColor(box, "Border color of active window", Color.FromKnownColor(KnownColor.ActiveBorder));
            AddColor(box, "Border color of inactive window", Color.FromKnownColor(KnownColor.InactiveBorder));

            AddColor(box, "Background color of multiple-document interface (MDI) applications", Color.FromKnownColor(KnownColor.AppWorkspace));
            AddColor(box, "Background color of items selected in a control", Color.FromKnownColor(KnownColor.Highlight));
            AddColor(box, "Text color of items selected in a control", Color.FromKnownColor(KnownColor.HighlightText));
            AddColor(box, "Color of shading on the face of command buttons", Color.FromKnownColor(KnownColor.Control));
            AddColor(box, "Color of shading on the edge of command buttons", Color.FromKnownColor(KnownColor.ControlDark));
            AddColor(box, "Grayed (disabled) text", Color.FromKnownColor(KnownColor.GrayText));
            AddColor(box, "Text color on push buttons", Color.FromKnownColor(KnownColor.ControlText));

            AddColor(box, "Color of text in an inactive caption", Color.FromKnownColor(KnownColor.InactiveCaptionText));
            AddColor(box, "Highlight color for 3D display elements", Color.FromKnownColor(KnownColor.ControlLightLight));
            AddColor(box, "Darkest shadow color for 3D display elements", Color.FromKnownColor(KnownColor.ControlDarkDark));
            AddColor(box, "Second lightest of the 3D colors", Color.FromKnownColor(KnownColor.ControlLight));
            AddColor(box, "Color of text face", Color.FromKnownColor(KnownColor.Control));
            AddColor(box, "Color of text shadow", Color.FromKnownColor(KnownColor.ControlDark));
            AddColor(box, "Color of text in ToolTips", Color.FromKnownColor(KnownColor.InfoText));

            AddColor(box, "Background color of ToolTips", Color.FromKnownColor(KnownColor.Info));
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            foreach (Control c in Controls) {
                AxSftBoxLib60.AxSftBox box = c as AxSftBoxLib60.AxSftBox;
                if (box != null) {
                    box.DarkMode = SftBoxLib60.SftBoxDarkModeConstants.darkSftBoxAuto; // follow the Windows dark mode setting
                    box.HighContrastMode = SftBoxLib60.SftBoxHighContrastConstants.highContrastSftBoxAuto; // follow the Windows High Contrast setting
                }
            }

            int index;
            short column;
    
            AddColors(SftBox1);
            // Select "Red"
            SftBox1.Items.FindCellData(ColorTranslator.ToWin32(Color.Red), 0, -1, (short) 0, out index, out column);
            SftBox1.Items.Selection = index;
            // make sure we get a horizontal scroll bar
            SftBox1.Items.RecalcHorizontalExtent(0);

            AddColors(SftBox2);
            // Select "Red"
            SftBox2.Items.FindCellData(ColorTranslator.ToWin32(Color.Red), 0, -1, 0, out index, out column);
            SftBox2.Items.Selection = index;
            // make sure we get a horizontal scroll bar
            SftBox2.Items.RecalcHorizontalExtent(0);

            AddColors(SftBox3);
            // Select "Red"
            SftBox3.Items.FindCellData(ColorTranslator.ToWin32(Color.Red), 0, -1, 0, out index, out column);
            SftBox3.Items.Selection = index;
            // make sure we get a horizontal scroll bar
            SftBox3.Items.RecalcHorizontalExtent(0);
        }
	}
}

Last Updated 11/22/2026 - (email)
© 2026 Softel vdm, Inc.