user741319
user741319

Reputation: 625

change text size of checkbox via c# code

I create many checkboxes dynamically in c# ( windows forms ). I want to assign the sizes of the checkboxes' texts. But I couldn't find a way. I want something like that :

CheckBox[] chk = new CheckBox[ff.documentColumnCount];     
chk[i].Font.Size = 8.5; // but of course this line doesn't work

what can I do about this,thanks for helping..

Upvotes: 3

Views: 4993

Answers (3)

Default Writer
Default Writer

Reputation: 2566

You did not initialized the array. You just declared that there is an array chk of size ff.DocumentCount

Try fix it to the following:

CheckBox[] chk = new CheckBox[ff.documentColumnCount];     
for(int i=0; i < ff.documentColumnCount; i++)
{
    chk[i] = new CheckBox() { Location = new Point(0, i * 50), Font = new Font(FontFamily.GenericSansSerif, 8.5f) };
}

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532505

The Font property is immutable (see Remarks). You have to assign the Font property a new instance of the Font class with the properties that you want.

chk[i].Font = new Font( chk[i].Font.FontFamily, 8.5 ); 

Upvotes: 2

DeCaf
DeCaf

Reputation: 6096

Something like this perhaps:

chk[i].Font = new Font(chk[i].Font.FontFamily, 8.5f);

Upvotes: 5

Related Questions