Resolution changes with VS2005

  • Thread starter Thread starter Graham McKechnie
  • Start date Start date
G

Graham McKechnie

Hi all,

A couple of days ago I started a thread "Resolution differences between
VS2003 and VS2005". I didn't get too many bites, but the following maybe of
interest.

It would appear the resolution changes required for all controls that are on
a existing form or are placed on a new form are automatically handled. Forms
designed in the designer have the following code automatically added in the
Formxx.Designer.cs part of the form.

this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;

This is the new mechanism that is used to kick off automatic scaling. See
article in help "Automatic Scaling in Windows Forms". So for standard
controls added via the IDE this will be enough (I haven't as yet tested
adding one of my custom controls through the IDE)

However if you are adding your own custom controls dynamically in code, you
will have have to control scaling of those controls. I've added the
following code to a couple of my controls and have now overcome my immediate
problem. The following is an example constructor.

public GPSMarkerBar(Form parent)
{
this.Size = new Size(204,107);
gpsMarkerCollection = new GPSMarkerCollection();
this.grayPen = new Pen(Color.SlateGray);
this.steelBlueBrush = new SolidBrush( Color.SteelBlue );
this.lightSteelBlueBrush = new SolidBrush( Color.LightSteelBlue);
this.whiteBrush = new SolidBrush(Color.White);
this.isInstantiated = true;

// new code for VS 2005
if (parent.AutoScaleDimensions.Width == 192f)
{
this.ScaleControl(new SizeF(2f, 2f), BoundsSpecified.All);
}
}

It's a bit crude as its only handling the resolution change, but it doing
the job for the moment
HTH
Graham
 
Hi Graham,

I'm glad you got it worked out, and thanks for reporting back.
 
Hi Graham,

This is true and a bit of a pain but you might find using the following code
example as this will support future higher resolution devices without code
change plus you need not "hard code" all coorinates for all controls:

const int DESIGNSIZE = 96; //The initial size was that form was designed
under.

/// <summary>

/// Helper method to draw unselected item.

/// </summary>

/// <param name="y">Y position where to start drawing the item.</param>

/// <param name="_tasklistItem">Instance of the tasklistitem object.</param>

private void DrawUnselectedItem(Graphics _grfx, int y, TaskListItem
_tasklistItem, bool paint_b)

{

if (_tasklistItem.Icon != null)

{

_grfx.DrawIcon(_tasklistItem.Icon, Convert.ToInt32(3 * _grfx.DpiY /
DESIGNSIZE), Convert.ToInt32(y + (3 * _grfx.DpiY / DESIGNSIZE)));

}

SolidBrush optionTitle_brush = new
SolidBrush(_tasklistItem.ForegroundColour);

_grfx.DrawString(_tasklistItem.Text, _tasklistItem.Font, optionTitle_brush,
27 * _grfx.DpiY / DESIGNSIZE,

y + (2 * _grfx.DpiY / DESIGNSIZE));

if (paint_b)

{

//repaint this item.

Invalidate(new Rectangle(0, y, Width, _tasklistItem.Height));

}

optionTitle_brush.Dispose();

}



Cheers

Simon.
 
Simon,

Thanks for the tip. I've used that in a couple of places - that rotated text
example helped as well.

This is hard work converting from 2003 to 2005, but I'm gradually getting
there - I just thought MS would have make this stuff easier.

Graham
 
Back
Top