Reputation: 73
Im creating a small map for a cemetery and I want to zoom in and zoom out to the map. So my idea is to resize all the content of the panel which is buttons. My code is here:
foreach (Control btn in this.panel3.Controls)
{
if ((btn) is Button)
{
btn.Width += 10;
btn.Height += 10;
}
}
is there any other way to do it? I am not satisfied because it doesn't look like zoom in or a way to may it more like zoom in. Thanks in advance.
Upvotes: 1
Views: 2870
Reputation: 28499
You can use the Scale
method of the Panel
to zoom in and out the contents of the panel.
private void buttonZoomIn_Click(object sender, EventArgs e)
{
cemetaryPanel.Scale(new SizeF(1.1f, 1.1f));
}
private void buttonZoomOut_Click(object sender, EventArgs e)
{
cemetaryPanel.Scale(new SizeF(0.9f, 0.9f));
}
Upvotes: 0
Reputation: 506
Your code only zooms in the buttons separately. What you may need is to stretch the whole area of buttons. Something like this (I haven't tested):
foreach (Button btn in panel3.Controls.Where(c => c is Button).Cast<Button>())
{
const double zoom = 1.1;
//increase position
btn.Left = Convert.ToInt32(btn.Left * zoom);
btn.Top = Convert.ToInt32(btn.Top * zoom);
//increase size
btn.Width = Convert.ToInt32(btn.Width * zoom);
btn.Height = Convert.ToInt32(btn.Height * zoom);
}
Upvotes: 1