Dax Fohl
Dax Fohl

Reputation: 10781

How to make a WinForms tri-state checkbox state display check/X/empty?

I'm writing an app to replace some paper-based testing forms. These forms have checkboxes that the tester marks with either a check or an X depending on the test result. How would I go about getting this visual feel from a winforms checkbox?

Upvotes: 2

Views: 4959

Answers (1)

JYelton
JYelton

Reputation: 36522

Enable the ThreeState property.

If for the "Indeterminate" state, you would rather have an "X", you can paint this yourself (using the control's paint event). One example:

private void checkBox1_Paint(object sender, PaintEventArgs e)
{
    CheckBox s = (CheckBox)sender;
    if (s.CheckState == CheckState.Indeterminate)
        e.Graphics.DrawString("X", s.Font, Brushes.Black, new Point(1, 1));
}

You can of course draw some lines or something more graphical. Cheers!

Upvotes: 8

Related Questions