Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

ImageViewer canvas does not resize when the ImageViewer control is resized .NET

I have an image viewer within a table layout in a windows form. Once I start image acquisition, the white & beige cavas holding the image will not resize with the ImageViewer control. Increasing the size of the window, which causes the ImageViewer to increase in size, leaves whitespace around the original white & beige canvas. Only the original area is used. Zooming doesn't solve the whitespace issue.

 

Likewise decreasing the size of the control will not decrease the size of the canvas.

 

If I resize the form before acquisition starts, the canvas will be created at the correct size, but the same problem still occurs if I want to resize again.

 

It looks like the ImageViewer isn't fully handling the OnSize event. Is there a remedy for this?

Message 1 of 3
(3,920 Views)

Hi Jared,

 

This is a known issue with .NET and the ImageViewer, and has been filed as CAR 188008.  You can check in future releases of NI-Vision to see if this has been resolved.  There isn't currently a workaround for this issue. 

 

Regards, 

Marti C
Applications Engineer
National Instruments
NI Medical
Message 2 of 3
(3,894 Views)

The work around that I have been using is the following.

 

Add the following methods and assign MainForm_Resize to the Resized  event of the main form that contains the ImageViewer:

 

 

private void MainForm_Resize(object sender, EventArgs e)
{
    Console.WriteLine("size changed to {0}, {1}", this.Size.Width, this.Size.Height);
    ResizeViewer(this.Size.Width - VIEWER_WIDTH_OFFSET, this.Size.Height - VIEWER_HEIGHT_OFFSET);
}
        

private void ResizeViewer(int width, int height)
{
    VisionImage tempImage = this.imageViewer.Image; 
    this.Controls.Remove(this.imageViewer);

    //
    // imageViewer
    //
    this.imageViewer = new NationalInstruments.Vision.WindowsForms.ImageViewer();
    this.imageViewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    this.imageViewer.ContextMenuStrip = this.contextViewerMenu;
    this.imageViewer.Location = new System.Drawing.Point(9, 34);
    this.imageViewer.Name = "imageViewer";
    this.imageViewer.NonTearingDisplay = true;
    this.imageViewer.ShowImageInfo = true;
    this.imageViewer.ShowToolbar = true;
    this.imageViewer.Size = new System.Drawing.Size(width, height);
    this.imageViewer.TabIndex = 9;
    this.imageViewer.ZoomToFit = false;

    this.imageViewer.Attach(tempImage);
    this.Controls.Add(this.imageViewer);
}

 

 

You will need to customize the ImageViewer properties  to fit your needs.

VIEWER_WIDTH_OFFSET and VIEWER_HEIGHT_OFFSET are just constants to leave a gap between the ImageViewer and the edge of the form.

 

Depending on your how powerful your PC is this may be too choppy, but it  is better than not being able to resize the ImageViewer at all.

 

-Tom

 

 

Message 3 of 3
(3,734 Views)