sabeesh
asked on
Resolution independent Resizing of controls in a .net winform
Hi Experts
In my winform application i am using infragistics control for UI design.I want to implement resize functionality in my winforms. ie. resolution independent resizing of all the controls inside the form. i dont want to use any third party for this. Could any one please give me some code sample for this.
Note:
Docking and Anchoring is not a solution for this
In my winform application i am using infragistics control for UI design.I want to implement resize functionality in my winforms. ie. resolution independent resizing of all the controls inside the form. i dont want to use any third party for this. Could any one please give me some code sample for this.
Note:
Docking and Anchoring is not a solution for this
ASKER
Got the soluton!
Hashtable hash = new Hashtable();
//## save default location of buttons into a
//## hash table
public void InitDefLoc()
{
foreach(Control cl in Controls)
{
if ((cl is Button) ^ (cl is TextBox))
{
DefLocation dl = new DefLocation();
dl.setDefW(cl.Width);
dl.setDefH(cl.Height);
dl.setDefCX(cl.Location.X) ;
dl.setDefCY(cl.Location.Y) ;
hash.Add(cl,dl);
}
}
}
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
InitDefLoc();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private void Form1_Resize(object sender, System.EventArgs e)
{
foreach (Control ctl in Controls)
{
if ((ctl is Button)^(ctl is TextBox))
{
int widthRatio = ClientRectangle.Width * 100 / startW;
int heightRatio = ClientRectangle.Height * 100 / startH;
DefLocation dl2 = (DefLocation)hash[ctl];
Point pnt = new Point((dl2.getDefCX() * widthRatio / 100),(dl2.getDefCY() * heightRatio / 100));
ctl.Width = dl2.getDefW() * widthRatio / 100;
ctl.Height = dl2.getDefH() * heightRatio / 100;
ctl.Location = pnt;
}
}
}
public class DefLocation
{
int defW,defH,defCX,defCY;
public void setDefW(int dw){
defW = dw;
}
public void setDefH(int dh){
defH = dh;
}
public void setDefCX(int dcx){
defCX = dcx;
}
public void setDefCY(int dcy){
defCY = dcy;
}
public int getDefW(){return defW;}
public int getDefH(){return defH;}
public int getDefCX(){return defCX;}
public int getDefCY(){return defCY;}
}
Hashtable hash = new Hashtable();
//## save default location of buttons into a
//## hash table
public void InitDefLoc()
{
foreach(Control cl in Controls)
{
if ((cl is Button) ^ (cl is TextBox))
{
DefLocation dl = new DefLocation();
dl.setDefW(cl.Width);
dl.setDefH(cl.Height);
dl.setDefCX(cl.Location.X)
dl.setDefCY(cl.Location.Y)
hash.Add(cl,dl);
}
}
}
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
InitDefLoc();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private void Form1_Resize(object sender, System.EventArgs e)
{
foreach (Control ctl in Controls)
{
if ((ctl is Button)^(ctl is TextBox))
{
int widthRatio = ClientRectangle.Width * 100 / startW;
int heightRatio = ClientRectangle.Height * 100 / startH;
DefLocation dl2 = (DefLocation)hash[ctl];
Point pnt = new Point((dl2.getDefCX() * widthRatio / 100),(dl2.getDefCY() * heightRatio / 100));
ctl.Width = dl2.getDefW() * widthRatio / 100;
ctl.Height = dl2.getDefH() * heightRatio / 100;
ctl.Location = pnt;
}
}
}
public class DefLocation
{
int defW,defH,defCX,defCY;
public void setDefW(int dw){
defW = dw;
}
public void setDefH(int dh){
defH = dh;
}
public void setDefCX(int dcx){
defCX = dcx;
}
public void setDefCY(int dcy){
defCY = dcy;
}
public int getDefW(){return defW;}
public int getDefH(){return defH;}
public int getDefCX(){return defCX;}
public int getDefCY(){return defCY;}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The actual code to do this will depend on what controls you have on your form and how you want them laid out.