sree
sree

Reputation: 601

How to set form sizes using properties

i have 2 forms in my project, i want to write a common class library for this two forms in that class library i want to write a property so that it can be accessed by both the forms and set their sizes, background color etc, in future my project may contain more than 10 forms with the same size, color etc..so i will use the above class library for maintaining the same color size etc for these forms.. Can any one help me?? I am struct with this problem for many days. I am new to DotNet.. Thank you in advance

Upvotes: 0

Views: 122

Answers (2)

Liam
Liam

Reputation: 29674

Declare a base class that inherits Form and contains protected properties

public class BaseClass : Form
    {
     //list common properties here
     protected int size  = 1;
    }

both forms now have access to the size property

public class form1 : BaseClass
{


   public form1()
   {
      //newsize = 1
      int newsize = size;   
   }
}

public class form2 : BaseClass
{
   public form2()
   {
       //newsize = 1
       int newsize = size;
    }
}

Or if you want to set properties of the Form class in the base class do this in the constructor of your base class

public class BaseClass : Form
        {
         public BaseClass()
         {
            //set color etc. here
         }
        }

Upvotes: 1

Jonathan
Jonathan

Reputation: 585

I'm not sure this is what you want but

class FormList{
 public List<System.Windows.Forms.Form> MyForms=new List<System.Windows.Forms.Form>();

 public void UpdateSomething(Color cols){
    foreach(Form ThisForm in MyForms){
        ThisForm.Color=cols
    }
 }
 //etc...
}

Upvotes: 0

Related Questions