When I select Auto option in zoom drop-down list the image will not be resized to fit available space. The only way to auto-fit the image is to type "Auto" in drop-down list. Also, when editor form is resized while "Auto" option is selected the zoom will not be updated.
Additional methods OnResize and DropDownList_SelectedIndexChanged are required to update the zoom, because in DropDownList_TextChanged event handler this.dropDownList.SelectedIndex is always set to -1 when any option is selected with mouse, and will be different from -1 only when a text matching an option is entered with keyboard.
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
this
.radImageEditor1.LoadAsync(@
"..\..\test-image.png"
);
this
.radImageEditor1.Resize +=
this
.RadImageEditor1_Resize;
this
.radImageEditor1.ImageEditorElement.ZoomElement.DropDownList.SelectedIndexChanged +=
this
.DropDownList_SelectedIndexChanged;
}
private
void
RadImageEditor1_Resize(
object
sender, EventArgs e)
{
if
(
this
.radImageEditor1.ImageEditorElement.ZoomElement.DropDownList.SelectedIndex == 0)
{
this
.UpdateAutoZoom();
}
}
private
void
DropDownList_SelectedIndexChanged(
object
sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if
(
this
.radImageEditor1.ImageEditorElement.ZoomElement.DropDownList.SelectedIndex == 0)
{
this
.UpdateAutoZoom();
}
}
private
void
UpdateAutoZoom()
{
float
factorX = (
float
)(
this
.radImageEditor1.ImageEditorElement.Size.Width -
this
.radImageEditor1.ImageEditorElement.CommandsElementWidth) / (
float
)
this
.radImageEditor1.ImageEditorElement.CurrentBitmap.Width;
float
factorY = (
float
)(
this
.radImageEditor1.ImageEditorElement.Size.Height -
this
.radImageEditor1.ImageEditorElement.ZoomElementHeight) / (
float
)
this
.radImageEditor1.ImageEditorElement.CurrentBitmap.Height;
float
factor = Math.Min(factorX, factorY);
this
.radImageEditor1.ImageEditorElement.ZoomFactor =
new
SizeF(factor, factor);
}
}