This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Minimum size for RectangleRubberband

Is there a way to set the minimum size of a RectangleRubberband. Any code samples would be appreciated. Thanks in advance for any help.
Hello,

Yes, of course. Here is small code snippet which illustrates the way:
private int _minWidth = 200;
private int _minHeight = 200;
private int _lastGoodX;
private int _lastGoodY;

private void InitializeRubberband(object sender, EventArgs e)
{
	_bitmapViewer.Bitmap.Load(@"E:\Pictures\TestSamples\FromWebDepartment\Aviation\0708793.jpg");
	_bitmapViewer.Rubberband = _rubberband;
	_rubberband.Rectangle = new System.Drawing.Rectangle(40, 40, _minWidth, _minHeight);

	_rubberband.RectangleChanged += new Aurigma.GraphicsMill.WinControls.RectangleEventHandler(RectangleChangedHandler);
	_rubberband.RectangleChanging += new Aurigma.GraphicsMill.WinControls.RectangleEventHandler(RectangleChangingHandler);
}

void RectangleChangingHandler(object sender, Aurigma.GraphicsMill.WinControls.RectangleEventArgs e)
{			
	if (e.ChangeMode != Aurigma.GraphicsMill.WinControls.RectangleChangeMode.Resizing)
		return;

	System.Drawing.Rectangle newRect = e.Rectangle;

	if (newRect.Width < _minWidth)
	{
		newRect.X = _lastGoodX;
		newRect.Width = _minWidth;
	}

	if (e.Rectangle.Height < _minHeight)
	{
		newRect.Y = _lastGoodY;
		newRect.Height = _minHeight;
	}

	e.Rectangle = newRect;
}

void RectangleChangedHandler(object sender, Aurigma.GraphicsMill.WinControls.RectangleEventArgs e)
{
	_lastGoodX = e.Rectangle.X;
	_lastGoodY = e.Rectangle.Y;
}
That worked great. Thanks for your help.
While this would work great on a WinForm, is there a way to set a minimum crop size when using the WebControl version of the RubberBand?

I know that the same event exists, but I definately don't want to incur a postback, just to enforce a minimum size.
Hello, PowerWare.

Here is a small JavaScript snippet for AjaxControls. (if you are using obsolete WebControls the implementation will be similar).

If you will have some problems with the sample please feel free to contact us.

Sys.Application.add_load(function() {
			
	var _minWidth = 200;
	var _minHeight = 200;
	var _lastGoodX = 40;
	var _lastGoodY = 40;
	
	var rr = $find("RectangleRubberband1");
	rr.set_rectangle(new GraphicsMill.Rectangle(40, 40, _minWidth, _minHeight))
		
	function on_changing() {
	
		var r = rr.get_rectangle();
		if (r.width < _minWidth) {
			r.width = _minWidth;
			r.x = _lastGoodX;
		}
		if (r.height < _minHeight) {
			r.height = _minHeight;
			r.y = _lastGoodY;
		}
		rr.set_rectangle(r);
		
		_lastGoodX = rr.get_rectangle().x;
		_lastGoodY = rr.get_rectangle().y;
	}
		
	rr.add_rectangleChanging(on_changing);
});