Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code gives 2 errors
1)"The best overloaded method match for 'System.Drawing.Size.Size(System.Drawing.Point)' has some invalid arguments"
2) Argument '1': cannot convert from 'int' to 'System.Drawing.Point'
Argument '1' means the value passed to Size().
Is there any other way of increasing the font size of a dynamic label?Can we apply it on same way for the dynamic buttons also?Please can any one help me?

C#
Label[] lab = new Label[20];
int x = 240;
for (int i = 1; i <= 10; i++)
{
 lab[i] = new Label();
 lab[i].Text = Convert.ToString(i);
 lab[i].Location = new Point(70,x);
 lab[i].Font.Size = new Size(10); 
 lab[i].Size = new Size(35,13);
 x = x + 95;
}
this.Controls.AddRange(lab);


thanx!
Posted
Updated 6-Jul-11 12:45pm
v2
Comments
JOAT-MON 6-Jul-11 18:45pm    
EDIT - added code block tags
Sergey Alexandrovich Kryukov 7-Jul-11 2:47am    
Do you think there are non-dynamic labels? What is that then?
--SA

There is no reason on earth why a dynamic control would work any differently, so the issue must be with the core code.

Font size is a float, just like the error message says. You should use intellisense, or perhaps the docs, to work out exactly what a parameter requires, esp when it gives you an error to tell you that you got it wrong. Also, Size takes two parameters, not one. Just like you did for the overall Size.
 
Share this answer
 
v3
Yes, you need to replace it in its entirety, not just modify a property. See the various overloads of the Font constructors[^]:
C#
lab[i].Font = new Font ( lab[i].Font.FontFamily, 10 );
 
Share this answer
 
v3
Comments
Christian Graus 6-Jul-11 19:49pm    
What makes you think this is a web project ?
JOAT-MON 6-Jul-11 20:24pm    
That is a fantastic question. Looking back over the question, I think it was the attempt to assign the Size property of the Font, got me thinking he might be trying to do this in code behind, but now that you've brought it to my attention again, I don't see a reason. Hmm...
Member 7779792 7-Jul-11 0:11am    
thank you for the link.that's a good one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900