Xceed Grid for WinForms v4.3 Documentation
ISupportIntegralResizing C# Implementation
Welcome to Xceed Grid for WinForms v4.3 > Advanced Concepts > Editors - Advanced Concepts > Implementing the ISupportIntegralResizing interface > ISupportIntegralResizing C# Implementation

The following code provides the C# implementation of the ISupportIntegralResizing interface.

C# Copy Code

using System;
using Xceed.Editors;
using System.Windows.Forms;
using System.Drawing;
using System.Collections; 

namespace Xceed.Editors.Samples
{
  public class PictureViewer : UserControl, ISupportIntegralResizing
  {
    public PictureViewer( ArrayList images )
    {
      this.SetStyle( ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | 
                     ControlStyles.UserPaint, true );
      m_images = images;       
    }
 
    public bool IntegralHeight
    {
      get{ return m_integralHeight; }
      set{ m_integralHeight = value; }
    }

    public bool IntegralWidth
    {
       get{ return m_integralWidth; }
       set{ m_integralWidth = value; }
    }

    public int GetPreferredHeight( int height )
    {
      return ( ( int )Math.Floor( ( double )height / m_imageSize ) ) * m_imageSize;
    }

    public int GetPreferredWidth( int width )
    {
      return ( ( int )Math.Floor( ( double )width / m_imageSize ) ) * m_imageSize;      
    }    

    protected override Size DefaultSize
    {
      get
      {
        return new Size( m_imageSize, m_imageSize );
      }
    }

    protected override void OnPaintBackground( PaintEventArgs pevent )
    {
      pevent.Graphics.FillRectangle( SystemBrushes.Control, this.ClientRectangle );

      int imageIndex = 0;
      for( int j = 0; j < this.Size.Height; j += m_imageSize )
      {
        for( int i = 0; i < this.Size.Width; i += m_imageSize )
        {
          pevent.Graphics.DrawImage( ( Image )m_images[ imageIndex ], i, j, m_imageSize, m_imageSize );
          imageIndex ++;
 
          if( imageIndex > m_images.Count - 1 )
            return;
        }       
      }             
    }

    private ArrayList m_images;
    private bool m_integralHeight = true;
    private bool m_integralWidth = true;
    private int m_imageSize = 100;
  }  
}