作成日: 2018/01/17 最終更新日: 2018/01/17
文書種別
使用方法
詳細
FlexGridにはラジオボタンを表示する機能は用意されていませんが、代替案として、セルに標準のRadioButtonコントロールをホストする方法が考えられます。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Public Class Form1
Private _al As ArrayList = New ArrayList()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim radiobutton1 As New RadioButton
Dim radiobutton2 As New RadioButton
Dim radiobutton3 As New RadioButton
radiobutton1.Text = "ラジオボタン1"
radiobutton2.Text = "ラジオボタン2"
radiobutton3.Text = "ラジオボタン3"
_al.Add(New HostedControl(C1FlexGrid1, radiobutton1, 1, 1))
_al.Add(New HostedControl(C1FlexGrid1, radiobutton2, 2, 1))
_al.Add(New HostedControl(C1FlexGrid1, radiobutton3, 3, 1))
End Sub
Private Sub C1FlexGrid1_Paint(sender As Object, e As PaintEventArgs) Handles C1FlexGrid1.Paint
For Each hosted As HostedControl In _al
hosted.UpdatePosition()
Next hosted
End Sub
End Class
Friend Class HostedControl
Friend _flex As C1.Win.C1FlexGrid.C1FlexGrid
Friend _ctl As Control
Friend _row As C1.Win.C1FlexGrid.Row
Friend _col As C1.Win.C1FlexGrid.Column
Friend Sub New(ByVal flex As C1.Win.C1FlexGrid.C1FlexGrid, ByVal hosted As Control, ByVal row As Integer, ByVal col As Integer)
_flex = flex
_ctl = hosted
_row = flex.Rows(row)
_col = flex.Cols(col)
_flex.Controls.Add(_ctl)
End Sub
Friend Function UpdatePosition() As Boolean
Dim r As Integer = _row.Index
Dim c As Integer = _col.Index
If r < 0 OrElse c < 0 Then
Return False
End If
Dim rc As Rectangle = _flex.GetCellRect(r, c, False)
If rc.Width <= 0 OrElse rc.Height <= 0 OrElse (Not rc.IntersectsWith(_flex.ClientRectangle)) Then
_ctl.Visible = False
Return True
End If
_ctl.Bounds = rc
_ctl.Visible = True
Return True
End Function
End Class
Private _al As ArrayList = New ArrayList()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim radiobutton1 As New RadioButton
Dim radiobutton2 As New RadioButton
Dim radiobutton3 As New RadioButton
radiobutton1.Text = "ラジオボタン1"
radiobutton2.Text = "ラジオボタン2"
radiobutton3.Text = "ラジオボタン3"
_al.Add(New HostedControl(C1FlexGrid1, radiobutton1, 1, 1))
_al.Add(New HostedControl(C1FlexGrid1, radiobutton2, 2, 1))
_al.Add(New HostedControl(C1FlexGrid1, radiobutton3, 3, 1))
End Sub
Private Sub C1FlexGrid1_Paint(sender As Object, e As PaintEventArgs) Handles C1FlexGrid1.Paint
For Each hosted As HostedControl In _al
hosted.UpdatePosition()
Next hosted
End Sub
End Class
Friend Class HostedControl
Friend _flex As C1.Win.C1FlexGrid.C1FlexGrid
Friend _ctl As Control
Friend _row As C1.Win.C1FlexGrid.Row
Friend _col As C1.Win.C1FlexGrid.Column
Friend Sub New(ByVal flex As C1.Win.C1FlexGrid.C1FlexGrid, ByVal hosted As Control, ByVal row As Integer, ByVal col As Integer)
_flex = flex
_ctl = hosted
_row = flex.Rows(row)
_col = flex.Cols(col)
_flex.Controls.Add(_ctl)
End Sub
Friend Function UpdatePosition() As Boolean
Dim r As Integer = _row.Index
Dim c As Integer = _col.Index
If r < 0 OrElse c < 0 Then
Return False
End If
Dim rc As Rectangle = _flex.GetCellRect(r, c, False)
If rc.Width <= 0 OrElse rc.Height <= 0 OrElse (Not rc.IntersectsWith(_flex.ClientRectangle)) Then
_ctl.Visible = False
Return True
End If
_ctl.Bounds = rc
_ctl.Visible = True
Return True
End Function
End Class
◎サンプルコード(C#)
namespace prj_C1FlexGrid
{
public partial class Form1 : Form
{
System.Collections.ArrayList _al = new System.Collections.ArrayList();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
RadioButton radiobutton1 = new RadioButton();
RadioButton radiobutton2 = new RadioButton();
RadioButton radiobutton3 = new RadioButton();
radiobutton1.Text = "ラジオボタン1";
radiobutton2.Text = "ラジオボタン2";
radiobutton3.Text = "ラジオボタン3";
_al.Add(new HostedControl(c1FlexGrid1, radiobutton1, 1, 1));
_al.Add(new HostedControl(c1FlexGrid1, radiobutton2, 2, 1));
_al.Add(new HostedControl(c1FlexGrid1, radiobutton3, 3, 1));
}
private void c1FlexGrid1_Paint(object sender, PaintEventArgs e)
{
foreach (HostedControl hosted in _al)
{
hosted.UpdatePosition();
}
}
}
class HostedControl
{
internal C1.Win.C1FlexGrid.C1FlexGrid _flex;
internal Control _ctl;
internal C1.Win.C1FlexGrid.Row _row;
internal C1.Win.C1FlexGrid.Column _col;
internal HostedControl(C1.Win.C1FlexGrid.C1FlexGrid flex, Control hosted, int row, int col)
{
_flex = flex;
_ctl = hosted;
_row = flex.Rows[row];
_col = flex.Cols[col];
_flex.Controls.Add(_ctl);
}
internal bool UpdatePosition()
{
int r = _row.Index;
int c = _col.Index;
if (((r < 0)
|| (c < 0)))
{
return false;
}
Rectangle rc = _flex.GetCellRect(r, c, false);
if (((rc.Width <= 0)
|| ((rc.Height <= 0)
|| !rc.IntersectsWith(_flex.ClientRectangle))))
{
_ctl.Visible = false;
return true;
}
_ctl.Bounds = rc;
_ctl.Visible = true;
return true;
}
}
}
{
public partial class Form1 : Form
{
System.Collections.ArrayList _al = new System.Collections.ArrayList();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
RadioButton radiobutton1 = new RadioButton();
RadioButton radiobutton2 = new RadioButton();
RadioButton radiobutton3 = new RadioButton();
radiobutton1.Text = "ラジオボタン1";
radiobutton2.Text = "ラジオボタン2";
radiobutton3.Text = "ラジオボタン3";
_al.Add(new HostedControl(c1FlexGrid1, radiobutton1, 1, 1));
_al.Add(new HostedControl(c1FlexGrid1, radiobutton2, 2, 1));
_al.Add(new HostedControl(c1FlexGrid1, radiobutton3, 3, 1));
}
private void c1FlexGrid1_Paint(object sender, PaintEventArgs e)
{
foreach (HostedControl hosted in _al)
{
hosted.UpdatePosition();
}
}
}
class HostedControl
{
internal C1.Win.C1FlexGrid.C1FlexGrid _flex;
internal Control _ctl;
internal C1.Win.C1FlexGrid.Row _row;
internal C1.Win.C1FlexGrid.Column _col;
internal HostedControl(C1.Win.C1FlexGrid.C1FlexGrid flex, Control hosted, int row, int col)
{
_flex = flex;
_ctl = hosted;
_row = flex.Rows[row];
_col = flex.Cols[col];
_flex.Controls.Add(_ctl);
}
internal bool UpdatePosition()
{
int r = _row.Index;
int c = _col.Index;
if (((r < 0)
|| (c < 0)))
{
return false;
}
Rectangle rc = _flex.GetCellRect(r, c, false);
if (((rc.Width <= 0)
|| ((rc.Height <= 0)
|| !rc.IntersectsWith(_flex.ClientRectangle))))
{
_ctl.Visible = false;
return true;
}
_ctl.Bounds = rc;
_ctl.Visible = true;
return true;
}
}
}
旧文書番号
82507