Excelのようにセルに斜線を引けますか?
対象製品
SPREAD for Windows Forms 7.0J
詳細
製品ではセルに斜線を引く機能をサポートしておりませんが、既存のセル型を継承し、独自にセルを描画することで実現が可能です。
  メモ
◎サンプルコード(VB)
◎サンプルコード(C#)
  メモ
- Excelファイルのインポートおよびエクスポートには対応していません。
◎サンプルコード(VB)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.Cells(0, 0).CellType = New SlashCell()
End Sub
Public Class SlashCell
Inherits FarPoint.Win.Spread.CellType.GeneralCellType
Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
' 既定の処理
MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
' 左上から右下の斜線
g.DrawLine(New Pen(Color.Black, 1), New Point(r.Left, r.Top), New Point(r.Right, r.Bottom))
' 右上から左下の斜線
'g.DrawLine(New Pen(Color.Black, 1), New Point(r.Left, r.Bottom), New Point(r.Right, r.Top)) End Sub
End Class
FpSpread1.ActiveSheet.Cells(0, 0).CellType = New SlashCell()
End Sub
Public Class SlashCell
Inherits FarPoint.Win.Spread.CellType.GeneralCellType
Public Overrides Sub PaintCell(ByVal g As System.Drawing.Graphics, ByVal r As System.Drawing.Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
' 既定の処理
MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
' 左上から右下の斜線
g.DrawLine(New Pen(Color.Black, 1), New Point(r.Left, r.Top), New Point(r.Right, r.Bottom))
' 右上から左下の斜線
'g.DrawLine(New Pen(Color.Black, 1), New Point(r.Left, r.Bottom), New Point(r.Right, r.Top)) End Sub
End Class
◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
fpSpread1.ActiveSheet.Cells[0, 0].CellType = new SlashCell();
}
public class SlashCell : FarPoint.Win.Spread.CellType.GeneralCellType
{
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
// 既定の処理
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
// 左上から右下の斜線
g.DrawLine(new Pen(Color.Black, 1), new Point(r.Left, r.Top), new Point(r.Right, r.Bottom));
// 右上から左下の斜線
//g.DrawLine(new Pen(Color.Black, 1), new Point(r.Left, r.Bottom), new Point(r.Right, r.Top)); }
}
{
fpSpread1.ActiveSheet.Cells[0, 0].CellType = new SlashCell();
}
public class SlashCell : FarPoint.Win.Spread.CellType.GeneralCellType
{
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
// 既定の処理
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
// 左上から右下の斜線
g.DrawLine(new Pen(Color.Black, 1), new Point(r.Left, r.Top), new Point(r.Right, r.Bottom));
// 右上から左下の斜線
//g.DrawLine(new Pen(Color.Black, 1), new Point(r.Left, r.Bottom), new Point(r.Right, r.Top)); }
}
関連情報
- セルの文字を自動的に縮小し文字列全体を表示できますか?
- セル入力時に[Alt]+[Enter]キーで改行したい
- ショートカットキーをExcelと同じにしたい
- セルに文字列が入りきらない時に、文字列を「#####」で表示できますか?
キーワード
「Excel操作」