출처 : 본인
처음 로드시에 list를 만든 뒤 resize 할 때 마다 좌표를 계속 바꿔준다.
public class PanelMarker : Panel
{
internal List<OnMarker> list = new List<OnMarker>();
public PanelMarker() : base()
{
this.DoubleBuffered = true;
this.ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (list.Count < 1)
{
foreach (Control c in this.Controls)
{
if (c is Panel)
{
OnMarker o = new OnMarker();
c.Anchor = AnchorStyles.None;
o.Control = c;
o.SizeRatioWidth = (float)c.Width / this.Width;
o.SizeRatioHeight = (float)c.Height / this.Height;
o.LocationRatioX = (float)(c.Left + c.Width / 2) / this.Width;
o.LocationRatioY = (float)(c.Top + c.Height / 2) / this.Height;
list.Add(o);
}
}
}
}
protected override void OnResize(EventArgs eventargs)
{
base.OnResize(eventargs);
//리스트를 불러와서 다시 그린다.
foreach (OnMarker o in list)
{
o.Control.Width = (int)(this.Size.Width * o.SizeRatioWidth);
o.Control.Height = (int)(this.Size.Height * o.SizeRatioHeight);
o.Control.Left = (int)(this.Size.Width * o.LocationRatioX) - (o.Control.Width / 2);
o.Control.Top = (int)(this.Size.Height * o.LocationRatioY) - (o.Control.Height / 2);
}
}
internal struct OnMarker
{
internal Control Control { get; set; }
internal float LocationRatioX { get; set; }
internal float LocationRatioY { get; set; }
internal float SizeRatioWidth { get; set; }
internal float SizeRatioHeight { get; set; }
}
}