This is my issue:
I add labels to a form programmatically, including some properties to resize them on runtime by clicking and dragging them with the mouse right click event.
My situation is, that I add a label programmatically containing an image from a given file through OpenDialog, and I would like to resize this image to fill the label size as I stretch the label. Unfortunately, I cannot set the size on runtime by accessing the image.Size property in the label, since it's read only... any ideas?
This is the affected piece of code:
Point _oldPosition;
public static Label _ctrlActiveControl;
if (e.Button == MouseButtons.Right)
{
_ctrlActiveControl.Cursor = Cursors.SizeNWSE;
//Code to resize the control based on the mouse position
Point newPosition = new Point(e.X, e.Y);
_ctrlActiveControl.Width += (newPosition.X - _oldPosition.X);
_ctrlActiveControl.Height += (newPosition.Y - _oldPosition.Y);
//Some security to make sure I don't shrink the control too much
if (_ctrlActiveControl.Width < 10) _ctrlActiveControl.Width = 10;
if (_ctrlActiveControl.Height < 10) _ctrlActiveControl.Height = 10;
//Here I check if the label contains an image and, if so, I should resize
//The image to "Autofill" the label
if (_ctrlActiveControl.Image != null)
{
Image image = _ctrlActiveControl.Image;
image.Size = new Size(_ctrlActiveControl.Width, _ctrlActiveControl.Height);
}
_oldPosition = newPosition;
}
I wonder if there's any way to do this, or should I instead use other control type (I know I can use others, but I'd like to know if there's any available workaround before adding more variables).