Reputation: 625
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
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
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
Reputation: 6096
Something like this perhaps:
chk[i].Font = new Font(chk[i].Font.FontFamily, 8.5f);
Upvotes: 5