WinForms (.NET 2) вопрос:
Есть ли способ держать элементы на пропорциональном расстоянии при изменении размера родительской формы (или панели)?
Могу ли я использовать Graphics.TransformPoints
или Graphics.TransformVectors
для этой области? Как.
альтернативный текст http://lh5.ggpht.com/_1TPOP7DzY1E/S_-QWNbBoqI/AAAAAAAADN8/cNSRTfxLEoI/s800/Capture3.gif
EDIT:
TableLayoutPanel не будет работать, поскольку наложенные элементы должны быть приняты.
EDIT2:
Это мой код:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Microsoft.VisualBasic.PowerPacks;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<Point> points;
List<Point> shapePoints;
Matrix m;
float dx, dy;
public Form1()
{
InitializeComponent();
points = new List<Point>();
shapePoints = new List<Point>();
foreach (Control c in this.Controls)
{
points.Add(c.Location);
}
foreach (Shape s in this.shapeContainer1.Shapes)
{
if (s is SimpleShape)
{
shapePoints.Add((s as SimpleShape).Location);
}
else if (s is LineShape)
{
shapePoints.Add((s as LineShape).StartPoint);
}
}
m = new Matrix();
dx = this.Width;
dy = this.Height;
// this code will allow(?) do not move this control
this.shapeContainer1.Dock = DockStyle.Fill;
}
protected override void OnSizeChanged(EventArgs e)
{
dx = this.Width / dx;
dy = this.Height / dy;
ApplyScale(dx, dy);
dx = this.Width;
dy = this.Height;
base.OnSizeChanged(e);
}
private void ApplyScale(float dx, float dy)
{
//m.Reset();
m.Scale(dx, dy);
Point[] locations = points.ToArray();
m.TransformVectors(locations);
for (int i = 0; i < this.Controls.Count; i++)
{
this.Controls[i].Location = locations[i];
}
Point[] shapeLocations = shapePoints.ToArray();
m.TransformVectors(shapeLocations);
for (int i = 0; i < this.shapeContainer1.Shapes.Count; i++)
{
SimpleShape ss = this.shapeContainer1.Shapes.get_Item(i)
as SimpleShape;
if (ss != null)
{
ss.Location = locations[i];
continue;
}
LineShape ls = this.shapeContainer1.Shapes.get_Item(i)
as LineShape;
if (ls != null)
{
ls.StartPoint = locations[i];
ls.Scale(new SizeF(dx, dy));
}
}
}
}
}
Вот что я получаю:
альтернативный текст http://lh4.ggpht.com/_1TPOP7DzY1E/TAOYg9fh5EI/AAAAAAAADOE/IPCdAFw-NFo/s800/Untitled-1.png