Partager via


Identifying VGA resolution on WM devices.

Very often when developing managed applications you need to target both VGA (480x640) and the older QVGA (240x320) type of devices. If the AutoScaleMode property of your form is set to Dpi, your controls such as textboxes. labels, buttons etc... will be scaled automatically. However if your draw images yourself or utilizing the ImageList, the images are not going to be autoscaled for you. During the runtime you can easily identify the VGA resolution by using the following code:

  public static bool IsHighResolution(this Form form)

  {

       SizeF currentScreen = form.CurrentAutoScaleDimensions;

       if (currentScreen.Height == 192)

       {

            return true;

  }

       return false;

  }

This is an extension method which is a part of the ControlExtension class from the ListViewDemo project which you can download from here.

So how would you use that method. Here's a sample function that you can place in your form's code:

  private void HandleHiRes()

  {

       if (this.IsHighResolution())

       {

             this.imageList1.ImageSize = new Size(32 * 2, 32 * 2);

       }

  }

Enjoy...

Comments

  • Anonymous
    May 05, 2009
    What's about HTC Touch HD? This device have 480x800. Some devices have 320x320. Work your code for these devices?

  • Anonymous
    May 05, 2009
    All you are intersted in is if you have higher DPI, which dictates usage of a higher res screens. So it should work.

  • Anonymous
    May 06, 2009
    Извините, Алекс, что пишу на русском. Предположим, я хочу вывести ImageList по высоте экрана. базовый размер 320. С помощью вашего кода я умножаю на 2, получаю 640 для моделей 640х480. Но если экран 480х800, то получится пустое место внизу в 160 пикселов. Но dpi у них одинаковое - 192, если я ничего не путаю. И каждый новый форм-фактор добавляет головной боли программистам.

  • Anonymous
    May 06, 2009
    I agree about the headache, but main idea of my code is to correctly resize the images that you would want to display let's say in the ListView. In the case if you want to display the image full screen you can just easily get the current screen size and use that to draw it correctly.