カスタムサブエディタの表示位置を変更したい
対象製品
SPREAD for Windows Forms 8.0J
詳細
編集可能なセル(テキスト型セルなど)には独自のサブエディタを設定することが可能です。カスタムサブエディタを作成する場合にはISubEditorインタフェースを利用しますが、このISubEditorメンバであるGetLocationメソッド呼び出しにより表示位置を調整することができます。
◎サンプルコード(VB)
◎サンプルコード(C#)
※サンプルコードを実行する場合、以下のプロジェクト形態が必要です
・新規プロジェクトに「Form1」 「Form2」を追加します
・「Form1」上にSPREADコントロール、「Form2」上にテキストボックスを貼り付けます
※カスタムサブエディタは定義したセルにフォーカスが存在する状態での[F4]押下、または編集中セルのダブルクリックによって表示されます
・新規プロジェクトに「Form1」 「Form2」を追加します
・「Form1」上にSPREADコントロール、「Form2」上にテキストボックスを貼り付けます
※カスタムサブエディタは定義したセルにフォーカスが存在する状態での[F4]押下、または編集中セルのダブルクリックによって表示されます
◎サンプルコード(VB)
【Form1】への実装
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'テキスト型セルを定義しForm2をサブエディタとします
Dim t As New FarPoint.Win.Spread.CellType.TextCellType
t.SubEditor = New Form2
FpSpread1.ActiveSheet.Cells(0, 0).CellType = t
FpSpread1.ActiveSheet.SetText(0, 0, "aaa")
End Sub
【Form2】への実装
Public Class Form2
Inherits System.Windows.Forms.Form
Implements FarPoint.Win.Spread.CellType.ISubEditor
Public Event ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements FarPoint.Win.Spread.CellType.ISubEditor.ValueChanged
Public Event CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Implements FarPoint.Win.Spread.CellType.ISubEditor.CloseUp
Public Function GetLocation(ByVal rect As System.Drawing.Rectangle) As System.Drawing.Point Implements FarPoint.Win.Spread.CellType.ISubEditor.GetLocation
'フォームの表示位置を微調整します。
Dim pt As New Point(rect.X + 10, rect.Y + 20)
Return pt
End Function
Public Shadows Function GetPreferredSize() As System.Drawing.Size Implements FarPoint.Win.Spread.CellType.ISubEditor.GetPreferredSize
'フォームのサイズを設定します。
Return New Size(368, 254)
End Function
Public Function GetSubEditorControl() As System.Windows.Forms.Control Implements FarPoint.Win.Spread.CellType.ISubEditor.GetSubEditorControl
' このフォームを返します。
Return Me
End Function
Public Function GetValue() As Object Implements FarPoint.Win.Spread.CellType.ISubEditor.GetValue
'テキストボックスの値を返します
Return TextBox1.Text
End Function
Public Sub SetValue(ByVal value As Object) Implements FarPoint.Win.Spread.CellType.ISubEditor.SetValue
'テキストボックスの値を設定します
TextBox1.Text = value
End Sub
Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
'フォーム終了時にイベントを発生させます
RaiseEvent ValueChanged(Me, EventArgs.Empty)
RaiseEvent CloseUp(Me, EventArgs.Empty)
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'テキスト型セルを定義しForm2をサブエディタとします
Dim t As New FarPoint.Win.Spread.CellType.TextCellType
t.SubEditor = New Form2
FpSpread1.ActiveSheet.Cells(0, 0).CellType = t
FpSpread1.ActiveSheet.SetText(0, 0, "aaa")
End Sub
【Form2】への実装
Public Class Form2
Inherits System.Windows.Forms.Form
Implements FarPoint.Win.Spread.CellType.ISubEditor
Public Event ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements FarPoint.Win.Spread.CellType.ISubEditor.ValueChanged
Public Event CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Implements FarPoint.Win.Spread.CellType.ISubEditor.CloseUp
Public Function GetLocation(ByVal rect As System.Drawing.Rectangle) As System.Drawing.Point Implements FarPoint.Win.Spread.CellType.ISubEditor.GetLocation
'フォームの表示位置を微調整します。
Dim pt As New Point(rect.X + 10, rect.Y + 20)
Return pt
End Function
Public Shadows Function GetPreferredSize() As System.Drawing.Size Implements FarPoint.Win.Spread.CellType.ISubEditor.GetPreferredSize
'フォームのサイズを設定します。
Return New Size(368, 254)
End Function
Public Function GetSubEditorControl() As System.Windows.Forms.Control Implements FarPoint.Win.Spread.CellType.ISubEditor.GetSubEditorControl
' このフォームを返します。
Return Me
End Function
Public Function GetValue() As Object Implements FarPoint.Win.Spread.CellType.ISubEditor.GetValue
'テキストボックスの値を返します
Return TextBox1.Text
End Function
Public Sub SetValue(ByVal value As Object) Implements FarPoint.Win.Spread.CellType.ISubEditor.SetValue
'テキストボックスの値を設定します
TextBox1.Text = value
End Sub
Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
'フォーム終了時にイベントを発生させます
RaiseEvent ValueChanged(Me, EventArgs.Empty)
RaiseEvent CloseUp(Me, EventArgs.Empty)
End Sub
End Class
◎サンプルコード(C#)
【Form1】への実装
private void Form1_Load(object sender, System.EventArgs e)
{
//テキスト型セルを定義しForm2をサブエディタとします
FarPoint.Win.Spread.CellType.TextCellType t = new FarPoint.Win.Spread.CellType.TextCellType();
t.SubEditor = new Form2();
fpSpread1.ActiveSheet.Cells[0,0].CellType = t;
fpSpread1.ActiveSheet.SetText(0, 0, "aaa");
}
【Form2】への実装
public partial class Form2 : Form, FarPoint.Win.Spread.CellType.ISubEditor
{
public event EventHandler CloseUp;
public event EventHandler ValueChanged;
public Form2()
{
InitializeComponent();
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_Closing);
}
public Point GetLocation(Rectangle rect)
{
//フォームの表示位置を微調整します。
return new Point(rect.X + 10, rect.Y + 20);
}
public Size GetPreferredSize()
{
//フォームのサイズを設定します。
return new Size(368, 254);
}
public Control GetSubEditorControl()
{
//このフォームを返します。
return this;
}
public object GetValue()
{
//テキストボックスの値を返します
return textBox1.Text;
}
public void SetValue(object value)
{
//テキストボックスの値を設定します
textBox1.Text = value.ToString();
}
private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//フォーム終了時にイベントを発生させます
ValueChanged(this, EventArgs.Empty);
CloseUp(this, EventArgs.Empty);
if (ValueChanged != null)
ValueChanged(this, EventArgs.Empty);
if (CloseUp != null)
CloseUp(this, EventArgs.Empty);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
//テキスト型セルを定義しForm2をサブエディタとします
FarPoint.Win.Spread.CellType.TextCellType t = new FarPoint.Win.Spread.CellType.TextCellType();
t.SubEditor = new Form2();
fpSpread1.ActiveSheet.Cells[0,0].CellType = t;
fpSpread1.ActiveSheet.SetText(0, 0, "aaa");
}
【Form2】への実装
public partial class Form2 : Form, FarPoint.Win.Spread.CellType.ISubEditor
{
public event EventHandler CloseUp;
public event EventHandler ValueChanged;
public Form2()
{
InitializeComponent();
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form2_Closing);
}
public Point GetLocation(Rectangle rect)
{
//フォームの表示位置を微調整します。
return new Point(rect.X + 10, rect.Y + 20);
}
public Size GetPreferredSize()
{
//フォームのサイズを設定します。
return new Size(368, 254);
}
public Control GetSubEditorControl()
{
//このフォームを返します。
return this;
}
public object GetValue()
{
//テキストボックスの値を返します
return textBox1.Text;
}
public void SetValue(object value)
{
//テキストボックスの値を設定します
textBox1.Text = value.ToString();
}
private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//フォーム終了時にイベントを発生させます
ValueChanged(this, EventArgs.Empty);
CloseUp(this, EventArgs.Empty);
if (ValueChanged != null)
ValueChanged(this, EventArgs.Empty);
if (CloseUp != null)
CloseUp(this, EventArgs.Empty);
}
}
キーワード
セル型