ReAzN 님, 안녕하세요.
그레이프시티입니다.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.Columns(0).CellType = New CustomCellType(FpSpread1)
End Sub
Public Class CustomCellType
Inherits FarPoint.Win.Spread.CellType.GeneralCellType
Private _spread As FarPoint.Win.Spread.FpSpread
Public Sub New(ByVal spread As FarPoint.Win.Spread.FpSpread)
_spread = spread
End Sub
Private Function GetButtonWidth(ByVal g As Graphics, ByVal zoomFactor As Single) As Integer
Return CInt((SystemInformation.VerticalScrollBarWidth * zoomFactor * 96 / g.DpiX))
End Function
Public Overrides Sub PaintCell(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)
Dim buttonWidth As Integer = GetButtonWidth(g, zoomFactor)
g.FillRectangle(Brushes.LightGray, r.Right - buttonWidth, r.Y, buttonWidth, r.Height)
Dim buttonRect As Rectangle = New Rectangle(r.Right - buttonWidth, r.Y, buttonWidth, r.Height)
Dim element = System.Windows.Forms.VisualStyles.VisualStyleElement.Button.PushButton.[Default]
If System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(element) Then
Dim renderer As System.Windows.Forms.VisualStyles.VisualStyleRenderer = New System.Windows.Forms.VisualStyles.VisualStyleRenderer(element)
Dim clipBounds As Rectangle = Rectangle.Round(g.ClipBounds)
renderer.DrawBackground(g, buttonRect, clipBounds)
Else
ControlPaint.DrawButton(g, buttonRect, ButtonState.Normal)
End If
r.Width -= buttonWidth
MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
End Sub
Public Overrides Function IsReservedLocation(ByVal g As Graphics, ByVal x As Integer, ByVal y As Integer, ByVal rc As Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal zoomFactor As Single) As Object
If rc.Contains(x, y) AndAlso x >= rc.Right - GetButtonWidth(g, zoomFactor) Then
Return Me
End If
Return MyBase.IsReservedLocation(g, x, y, rc, appearance, value, zoomFactor)
End Function
Public Overrides Sub StartEditing(ByVal e As EventArgs, ByVal selectAll As Boolean, ByVal autoClipboard As Boolean)
Dim mouseEvent As MouseEventArgs = e
If TypeOf e Is MouseEventArgs And CType(e, MouseEventArgs).Clicks = 1 Then
Dim result = MessageBox.Show("Click OK to set ""Test"" to cell.", "", MessageBoxButtons.OKCancel)
If result = DialogResult.OK Then
_spread.CancelCellEditing()
_spread.ActiveSheet.ActiveCell.Value = "Test"
End If
Return
End If
MyBase.StartEditing(e, selectAll, autoClipboard)
End Sub
End Class
End Class