Click here to Skip to main content
15,907,183 members
Articles / Programming Languages / C#
Tip/Trick

Resolution Free application using ResolutionFreePanel

Rate me:
Please Sign up or sign in to vote.
3.75/5 (3 votes)
12 Mar 2012CPOL1 min read 9.4K   465   8   1
This Panel is developed as a Custom Control. Place whatever the control on this panel, if resolution is changed then the controls position and the size is changed w.r.to resolution

Introduction

This control is developed form a Panel, but with some added functionality. This control provides Resolution free feature. Whatever the resolution user wants to see an application is provided by this control, the resolution is nothing but the monitor resolution. My monitors working range is 800*600 to 1600*1200. By using this control, I had tested by application and it is with standings for all the Resolution options. 

How it Works

The ResolutionFreePanel is derived from Panel class and it is developed as a User Control. I had used the SystemEvents.DisplaySettingsChanged event to modify the Size and Location of each controls which are placed on the ResolutiionFreePanel. For this control

DataBind(decimal dFactorWidth, decimal
dFactorHeight, Control objControl)
is the main function which performs all the Resolution free functionality.  First a  dummy Label object created. For this Label object modified the width, height, location values. Next used the DataBindings Property of the control to change the width, height, resolution of each control which is on the ResolutionFreePanel.

C#
private void DataBind(decimal dFactorWidth, decimal dFactorHeight, Control objControl)
{
    if (objControl.Controls.Count > 0)
    {
        foreach (Control objCtrl in objControl.Controls)
        {
            objLabel.Width = (int)((decimal)objCtrl.Width * dFactorWidth);
            objLabel.Height = (int)((decimal)objCtrl.Height * dFactorHeight);
            objLabel.Location = new System.Drawing.Point((
                int)((decimal)objCtrl.Location.X * dFactorWidth),
                (int)((decimal)objCtrl.Location.Y * dFactorHeight));
 
            objCtrl.DataBindings.Clear();
            if (objCtrl.GetType() != typeof(System.Windows.Forms.SplitterPanel))
            {
                objCtrl.DataBindings.Add("Width", objLabel, "Width");
                objCtrl.DataBindings.Add("Height", objLabel, "Height");
                objCtrl.DataBindings.Add("Location", objLabel, "Location");
                objCtrl.DataBindings.Clear();
            }
 
            if (objCtrl.Controls.Count > 0)
            {
                DataBind(dFactorWidth, dFactorHeight, objCtrl);
            }
        }
    }

    else
    {
        return;
    }
}

Using for Applications

This ResolutionFreePanel is provided as User Control.  When started your development, first place this control on the Form, then place whatever the control you want for your application. For testing purpose I had developed a form with n number of controls.

First screen is with 1600*1200 resolutions.

Image 1

Next screen is with 1280*1024 resolutions.

Image 2

Next screen is with 1024*768 resolutions.

Image 3

And we can test the application by clicking the minimize and maximize  options of the Form also.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Sanjeeb3812-Feb-13 1:37
Sanjeeb3812-Feb-13 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.