Re: Resolution changes with VS2005
- From: "Simon Hart" <srhartone@xxxxxxxxx>
- Date: Fri, 9 Dec 2005 14:35:54 -0000
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.
"Graham McKechnie" <gmknospam@xxxxxxxxxxxxxx> wrote in message
news:OsfLLjI$FHA.1288@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>
.
- Follow-Ups:
- Re: Resolution changes with VS2005
- From: Graham McKechnie
- Re: Resolution changes with VS2005
- References:
- Resolution changes with VS2005
- From: Graham McKechnie
- Resolution changes with VS2005
- Prev by Date: Re: Global blocking of input events
- Next by Date: Re: config MSMQ CF 2.0 on WM 5
- Previous by thread: Re: Resolution changes with VS2005
- Next by thread: Re: Resolution changes with VS2005
- Index(es):
Relevant Pages
|