Solved

Resolution independent Resizing of controls in a .net winform

Posted on 2006-11-23
4
1,893 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:sabeesh
4 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 18006371
Bind a delegate to the resize event of your form and resize and relayout your controls when this event is fired.
The actual code to do this will depend on what controls you have on your form and how you want them laid out.
0
 
LVL 8

Author Comment

by:sabeesh
ID: 18017155
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;}
      }
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18191951
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hey Audio! 9 45
VB.NET 2008 Winforms Signing 13 33
Dynamics CRM Plugin Query TotalRecordCount returning -1 13 45
IEnumerable<T> to a List<T> 8 40
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question