Spread Windows Forms 11.0 Product Documentation
GetPreferredSize Method (IRenderer)
Example 


FarPoint.Win.Spread Assembly > FarPoint.Win.Spread.CellType Namespace > IRenderer Interface : GetPreferredSize Method
Graphics device interface for painting the cell
Preferred or maximum required size
Appearance settings of the renderer control
Object that contains the name of the renderer control
Numeric value for scaling the display of the renderer control
Gets the preferred (maximum required) size of the cell for the renderer control.
Syntax
'Declaration
 
Function GetPreferredSize( _
   ByVal g As Graphics, _
   ByVal size As Size, _
   ByVal appearance As Appearance, _
   ByVal value As Object, _
   ByVal zoomFactor As Single _
) As Size
'Usage
 
Dim instance As IRenderer
Dim g As Graphics
Dim size As Size
Dim appearance As Appearance
Dim value As Object
Dim zoomFactor As Single
Dim value As Size
 
value = instance.GetPreferredSize(g, size, appearance, value, zoomFactor)
Size GetPreferredSize( 
   Graphics g,
   Size size,
   Appearance appearance,
   object value,
   float zoomFactor
)

Parameters

g
Graphics device interface for painting the cell
size
Preferred or maximum required size
appearance
Appearance settings of the renderer control
value
Object that contains the name of the renderer control
zoomFactor
Numeric value for scaling the display of the renderer control

Return Value

Size object containing the preferred size (maximum needed size) of the cell for the renderer control
Remarks

If you have set up the cells to format the text with multiple lines (GeneralCellType with WordWrap equal to true, or TextCellType with Multiline or WordWrap or both equal to true), then this method returns the optimal height to show all of the text in the cell with the current row height. For text cells or header cells with text, be sure that you turn off word wrapping by setting the WordWrap property for that text cell or header cell to false.

For limits on the zoomFactor parameter, refer to the ZoomFactor property for the sheet.

Example
This example subclasses the IRenderer class and creates a custom renderer for the first cell in the spreadsheet to illustrate the use of the methods and events.
public static CheckBox ck = new CheckBox();

class myRenderer : FarPoint.Win.Spread.CellType.IRenderer
{
  public bool CanOverflow()
  {
      return true;
  }
  public bool CanBeOverflown()
  {
      return true;
  }
  public Size GetPreferredSize(Graphics g, Size s, FarPoint.Win.Spread.Appearance appr, object value, float zoom)
 {
      s = new Size(50, 50);
      return s;
  }
  public void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appr, object value, bool issel, bool islocked,
float zoom) 
  {
      string s;
      ck.CheckState = CheckState.Checked;
      s = ck.CheckState.ToString();
      Font f = new Font("MS Sans Serif", 10);
      appr.BackColor = Color.Red;
      appr.ForeColor = Color.Yellow;
      appr.Font = f;
      Brush b, b1;
      b = new SolidBrush(appr.BackColor);
      b1 = new SolidBrush(appr.ForeColor);
      g.FillRectangle(b, r);
      g.DrawString(s, appr.Font, b1, r);
      b.Dispose();
      b1.Dispose();
      }
}

private void Form1_Load(object sender, System.EventArgs e)
{
      fpSpread1.ActiveSheet.Cells[0, 0].Renderer = new myRenderer();
}
Shared ck As New CheckBox()

Public Class myRenderer
Implements FarPoint.Win.Spread.CellType.IRenderer

Public Function CanBeOverflown() As Boolean Implements FarPoint.Win.Spread.CellType.IRenderer.CanBeOverflown
      Return True
End Function

Public Function CanOverflow() As Boolean Implements FarPoint.Win.Spread.CellType.IRenderer.CanOverflow
      Return True
End Function

Public Function GetPreferredSize(ByVal g As Graphics, ByVal s As Size, ByVal appr As FarPoint.Win.Spread.Appearance, ByVal
value As Object, ByVal zoom As Single) As Size Implements FarPoint.Win.Spread.CellType.IRenderer.GetPreferredSize
      s = New Size(50, 50)
      Return s
End Function

Public Sub PaintCell(ByVal g As Graphics, ByVal r As Rectangle, ByVal appr As FarPoint.Win.Spread.Appearance, ByVal Value
As Object, ByVal issel As Boolean, ByVal islocked As Boolean, ByVal zoom As Single) Implements FarPoint.Win.Spread.CellType.IRenderer.PaintCell
      Dim s As String
      ck.CheckState = CheckState.Checked
      s = ck.CheckState.ToString()
      Dim f As New Font("MS Sans Serif", 10)
      appr.BackColor = Color.Red
      appr.ForeColor = Color.Yellow
      appr.Font = f
      Dim b, b1 As Brush
      b = New SolidBrush(appr.BackColor)
      b1 = New SolidBrush(appr.ForeColor)
      g.FillRectangle(b, r)
      g.DrawString(s, appr.Font, b1, r.X, r.Y)
      b.Dispose()
      b1.Dispose()
End Sub

End Class

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      FpSpread1.ActiveSheet.Cells(0, 0).Renderer = New myRenderer()
End Sub
See Also

Reference

IRenderer Interface
IRenderer Members