I had this problem, I can't add a control inside a class. More specifically the Controls.Add(Button);. Is this possible or do i missing something.
MyFunctions mf = new MyFunctions();
class MyFunctions
{
public int ButtonWidth(int number)
{
string a = "";
int ButtonWidth=0;
Button x = new Button();
x.Size = new Size(10, 40);//Initial Size
x.AutoSize = true;
x.AutoSizeMode = AutoSizeMode.GrowAndShrink;
Controls.Add(x);//Why i can't this one?
for(int i=1;i<=number;i++)
{
a += "X";
x.Text = a;
ButtonWidth = x.Width;
MessageBox.Show(i + "-" + a + "-" + ButtonWidth);
}
return ButtonWidth;
}
}`
I got an error message.
can't access a non-static member of outer type.
I made a trial to see if the button width is changing when button.text changes its length. but the button.width is held constant.