Spread Windows Forms 8.0 Product Documentation
AddControl(Control,Int32,Int32,Int32,Int32) Method
Example 


Child control to add
Row index at which to add child control
Column index at which to add child control
Number of horizontal pixels to offset from the specified column index
Number of vertical pixels to offset from the specified row index
Adds a child control to the control container for the sheet at the specified row and column, with specified pixel offsets.
Syntax
'Declaration
 
Public Overloads Overridable Sub AddControl( _
   ByVal control As Control, _
   ByVal row As Integer, _
   ByVal column As Integer, _
   ByVal offsetX As Integer, _
   ByVal offsetY As Integer _
) 
'Usage
 
Dim instance As SheetView
Dim control As Control
Dim row As Integer
Dim column As Integer
Dim offsetX As Integer
Dim offsetY As Integer
 
instance.AddControl(control, row, column, offsetX, offsetY)
public virtual void AddControl( 
   Control control,
   int row,
   int column,
   int offsetX,
   int offsetY
)

Parameters

control
Child control to add
row
Row index at which to add child control
column
Column index at which to add child control
offsetX
Number of horizontal pixels to offset from the specified column index
offsetY
Number of vertical pixels to offset from the specified row index
Example
This example adds a text box control to the sheet.
public class SpreadTextBox : TextBox, FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport 
{ 
 private FarPoint.Win.Spread.DrawingSpace.Moving moving = Moving.None; 
 private FarPoint.Win.Spread.DrawingSpace.Sizing sizing = Sizing.None; 
 private FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy activation = ChildActivationPolicy.DoubleClick; 

 public virtual FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy ActivationPolicy { 
   get { 
     return activation; 
   } 
   set { 
   } 
 } 

 public virtual FarPoint.Win.Spread.DrawingSpace.Moving CanMove { 
   get { 
     return moving; 
   } 
   set { 
     moving = value; 
   } 
 } 

 public virtual FarPoint.Win.Spread.DrawingSpace.Sizing CanSize { 
   get { 
     return sizing; 
   } 
   set { 
     sizing = value; 
   } 
 } 

 public void ControlPaint(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected,
bool isLocked, float zoomFactor) 
 { 
   g.SetClip(r, CombineMode.Intersect); 
   g.FillRectangle(new SolidBrush(this.BackColor), r); 
   g.DrawString(this.Text, Font, new SolidBrush(this.ForeColor), r.X, r.Y); 
   this.TextChanged += new EventHandler(MeTextChanged); 
 } 

 public void MeTextChanged(object sender, EventArgs e) 
 { 
   this.BackColor = Color.Beige; 
 } 
}

SpreadTextBox tb = new SpreadTextBox();
tb.Name = "TB";
fpSpread1.ActiveSheet.AddControl(tb, 2, 2, 10, 10);
Public Class SpreadTextBox
   Inherits TextBox
   Implements FarPoint.Win.Spread.DrawingSpace.IEmbeddedControlSupport

   Private moving As FarPoint.Win.Spread.DrawingSpace.Moving = Moving.None
   Private sizing As FarPoint.Win.Spread.DrawingSpace.Sizing = Sizing.None
   Private activation As FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy = ChildActivationPolicy.DoubleClick

   Public Overridable Property ActivationPolicy() As FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy Implements IEmbeddedControlSupport.ActivationPolicy
   Get
     Return activation
   End Get
   Set(ByVal Value As FarPoint.Win.Spread.DrawingSpace.ChildActivationPolicy)
     ' activation = Value
   End Set
   End Property

   Public Overridable Property CanMove() As FarPoint.Win.Spread.DrawingSpace.Moving Implements IEmbeddedControlSupport.CanMove
   Get
     Return moving
   End Get
   Set(ByVal Value As FarPoint.Win.Spread.DrawingSpace.Moving)
     moving = Value
   End Set
   End Property

   Public Overridable Property CanSize() As FarPoint.Win.Spread.DrawingSpace.Sizing Implements IEmbeddedControlSupport.CanSize
   Get
     Return sizing
   End Get
   Set(ByVal Value As FarPoint.Win.Spread.DrawingSpace.Sizing)
     sizing = Value
   End Set
   End Property


   Public Sub ControlPaint(ByVal g As Graphics, ByVal r As Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance,
ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single) Implements IEmbeddedControlSupport.ControlPaint
    g.SetClip(r, CombineMode.Intersect)
    g.FillRectangle(New SolidBrush(Me.BackColor), r)
    'g.FillRectangle(New SolidBrush(Me.BackColor), r.X - 120, r.Y - 120, r.Width, r.Height)
    g.DrawString(Me.Text, Font, New SolidBrush(Me.ForeColor), r.X, r.Y)
   AddHandler Me.TextChanged, AddressOf MeTextChanged

  End Sub

Public Sub MeTextChanged(ByVal sender As Object, ByVal e As EventArgs)
Me.BackColor = Color.Beige
End Sub
End Class

Dim tb As New SpreadTextBox()
tb.Name = "TB"
FpSpread1.ActiveSheet.AddControl(tb, 2, 2, 10, 10)
Requirements

Target Platforms: Windows 2000 Professional (SP4), Windows 2000 Server, Windows 2003 Server (SP1), Windows 2008, Windows XP (SP2), Windows Vista, Windows 7, Windows 8

See Also

Reference

SheetView Class
SheetView Members
Overload List

 

 


Copyright © GrapeCity, inc. All rights reserved.