Xceed Grid for WinForms v4.3 Documentation
Welcome to Xceed Grid for WinForms v4.3 / Advanced Concepts / Editors - Advanced Concepts / Implementing the ISupportIntegralResizing interface / ISupportIntegralResizing VB.NET Implementation
In This Topic
    ISupportIntegralResizing VB.NET Implementation
    In This Topic

    The following code provides the VB.NET implementation of the ISupportIntegralResizing interface.

    VB.NET Copy Code

    Imports System
    Imports Xceed.Editors
    Imports System.Windows.Forms
    Imports System.Drawing
    Imports System.Collections 

    Namespace Xceed.Editors.Samples
      Public Class PictureViewer
         Inherits UserControl
         Implements ISupportIntegralResizing 

    Public Sub New(ByVal images As ArrayList)

    Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or _
                ControlStyles.UserPaint, True)

    m_images = images

    End Sub 

    Public Property IntegralHeight() As Boolean Implements ISupportIntegralResizing.IntegralHeight
      Get
        Return m_integralHeight
      End Get
      Set(ByVal Value As Boolean)
        m_integralHeight = Value
      End Set
    End Property 

    Public Property IntegralWidth() As Boolean Implements ISupportIntegralResizing.IntegralWidth
      Get
        Return m_integralWidth
      End Get
      Set(ByVal Value As Boolean)
        m_integralWidth = Value
      End Set
    End Property 

    Public Function GetPreferredHeight( ByVal height As Integer ) As Integer
                                   Implements ISupportIntegralResizing.GetPreferredHeight
      Return Math.Floor(height / m_imageSize) * m_imageSize
    End Function 

    Public Function GetPreferredWidth( ByVal width As Integer ) As Integer
                                   Implements ISupportIntegralResizing.GetPreferredWidth
      Return Math.Floor(width / m_imageSize) * m_imageSize
    End Function 

    Protected Overrides ReadOnly Property DefaultSize() As Size
      Get
        Return New Size( m_imageSize, m_imageSize )
      End Get
    End Property 

    Protected Overrides Sub OnPaintBackground( ByVal pevent As PaintEventArgs )
      pevent.Graphics.FillRectangle( SystemBrushes.Control, Me.ClientRectangle )

      Dim imageIndex As Integer = 0
      Dim j As Integer = 0

      While j < Me.Size.Height
        Dim i As Integer = 0

        While i < Me.Size.Width
          pevent.Graphics.DrawImage( CType( m_images( imageIndex ), Image ), i, j, m_imageSize, _
                                     m_imageSize )
          imageIndex += 1

          If imageIndex > m_images.Count - 1 Then
            Return
          End If
            i += m_imageSize
          End While

          j += m_imageSize
        End While
      End Sub 

    Private m_images As ArrayList
    Private m_integralHeight As Boolean = True
    Private m_integralWidth As Boolean = True
    Private m_imageSize As Integer = 100 

    End Class

    End Namespace