It is often useful to zoom and scroll an image to fill the viewer on first load. The quick way of doing this is by using StretchMode and a few other properties.

DicomObjects.NET

 GetSelectedImage().StretchMode = DicomObjects.Enums.StretchModes.StretchCentred;

However if StretchMode is used it doesn’t allow the image to be scrolled or zoomed. To overcome this problem it is possible to save the scroll and zoom values used by the StretchMode , then remove the StretchMode and apply them to the image. This will leave an image in the viewer that is stretched to the full size of the viewer but zooming and scrolling are now available for use.

    
 int MouseDownX, MouseDownY;
 Point scrollPoint = new Point();
 private void Viewer_Click(object sender, EventArgs e)
 {
	if (Viewer.Images.Count == 0)
	{
	  Viewer.CurrentImage.StretchMode = DicomObjects.Enums.StretchModes.StretchCentred;
	  float Zm = DicomGlobal.Zoom(Viewer.CurrentImage.Matrix(Viewer));
	  Viewer.CurrentImage.StretchMode = DicomObjects.Enums.StretchModes.None;
	  Viewer.CurrentImage.Zoom = Zm; // apply the values used by the auto stretch to a non stretched image
	  Viewer.CurrentImage.Scroll = scrollPoint;
	}
 } 
    
 private void Viewer_MouseDown(object sender, MouseEventArgs e)
 {
	if ((e.Button == MouseButtons.Left) && (Viewer.Images.Count != 0))
	{
	  MouseDownX = e.X - Viewer.CurrentImage.Scroll.X;
	  MouseDownY = e.Y - Viewer.CurrentImage.Scroll.Y;
	  }          
 }
     
 private void Viewer_MouseMove(object sender, MouseEventArgs e)
 {
	Point P = new Point();
	if ((e.Button == MouseButtons.Left) && (Viewer.Images.Count != 0))
	{
	  P.X = e.X - MouseDownX;
	  P.Y = e.Y - MouseDownY;
	  Viewer.CurrentImage.Scroll = P;
	}
 }

DicomObjects.COM

 
 Viewer.CurrentImage.StretchMode = StretchCentred   
 Dim x As Single
 x = Viewer.CurrentImage.ActualScrollX
 
 Dim y As Single
 y = Viewer.CurrentImage.ActualScrollY
   
 Dim z As Single
 z = Viewer.CurrentImage.ActualZoom
   
 Viewer.CurrentImage.ScrollX = x
 Viewer.CurrentImage.ScrollY = y
 Viewer.CurrentImage.Zoom = z
   
 Viewer.CurrentImage.StretchMode = NoStretch