作成日: 2025/09/11 最終更新日: 2025/09/11
文書種別
使用方法
詳細
任意の行の下に横線を表示する機能は用意されていませんが、代替案として、PaintDayイベントごPaintイベントを使用し、Graphics.DrawLineメソッドを用いて手動で線を描画する方法が考えられます。
それには、最初にPaintDayイベントで線を引くべきセルの位置情報を取得し、次いで発生するPaintイベントにて、 該当行にDrawLineメソッドで手動で横線をひきます。
(ご注意)
※以下に記載するコードでは、行の位置を設定する際に、GanttViewで内部的に使用されているC1FlexGridにアクセスしています。このC1FlexGridは通常は公開されていませんので、コードの利用に際しては、動作を十分ご確認の上で、使用の可否をご検討ください。また、記載したコード以外のカスタマイズ方法などについて、ご提供できる情報はございませんのでご了承ください。
◎サンプルコード(VB)
Imports C1.Win.C1FlexGrid
Public Class Form1
Private _left As Integer = Integer.MaxValue
Private _right As Integer = Integer.MinValue
Private _bottom As Integer = 0
Private _draw As Boolean = False
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' タスクの設定
Dim wTask1 As C1.Win.C1GanttView.Task = C1GanttView1.Tasks(0)
wTask1.Name = "Task1"
wTask1.Start = DateTime.Today.AddDays(1)
wTask1.Finish = DateTime.Today.AddDays(7)
Dim wTask2 As C1.Win.C1GanttView.Task = C1GanttView1.Tasks(1)
wTask2.Name = "Task2"
wTask2.Start = DateTime.Today.AddDays(2)
wTask2.Finish = DateTime.Today.AddDays(8)
Dim wTask3 As C1.Win.C1GanttView.Task = C1GanttView1.Tasks(2)
wTask3.Name = "Task3"
wTask3.Start = DateTime.Today.AddDays(3)
wTask3.Finish = DateTime.Today.AddDays(9)
End Sub
Private Sub C1GanttView1_PaintDay(sender As Object, e As C1.Win.C1GanttView.PaintDayEventArgs) Handles C1GanttView1.PaintDay
' タスク名が "Task2" の行の位置情報を取得
If e.Task IsNot Nothing AndAlso e.Task.Name = "Task2" Then
_left = Math.Min(_left, e.Rectangle.Left)
_right = Math.Max(_right, e.Rectangle.Right)
_bottom = e.Rectangle.Bottom
_draw = True
End If
End Sub
Private Sub C1GanttView1_Paint(sender As Object, e As PaintEventArgs) Handles C1GanttView1.Paint
If Not _draw Then Return
_left += C1GanttView1.GridWidth
_right += C1GanttView1.GridWidth
_bottom += CType(C1GanttView1.Controls(0), C1FlexGrid).Top
' "Task2" の行の下端に 2px の青線を描画
Using pen As New Pen(Color.Violet, 2)
e.Graphics.DrawLine(pen, _left, _bottom - 1, _right, _bottom - 1)
End Using
_draw = False
_left = Integer.MaxValue
_right = Integer.MinValue
_bottom = 0
End Sub
End Class
◎サンプルコード(C#)
using C1.Win.C1FlexGrid;
namespace prj_C1GanttView
{
public partial class Form1 : Form
{
int _left = int.MaxValue;
int _right = int.MinValue;
int _bottom = 0;
bool _draw = false;
public Form1()
{
InitializeComponent();
// タスクの設定
C1.Win.C1GanttView.Task wTask1 = c1GanttView1.Tasks[0];
wTask1.Name = "Task1";
wTask1.Start = DateTime.Today.AddDays(1);
wTask1.Finish = DateTime.Today.AddDays(7);
C1.Win.C1GanttView.Task wTask2 = c1GanttView1.Tasks[1];
wTask2.Name = "Task2";
wTask2.Start = DateTime.Today.AddDays(2);
wTask2.Finish = DateTime.Today.AddDays(8);
C1.Win.C1GanttView.Task wTask3 = c1GanttView1.Tasks[2];
wTask3.Name = "Task3";
wTask3.Start = DateTime.Today.AddDays(3);
wTask3.Finish = DateTime.Today.AddDays(9);
}
private void c1GanttView1_PaintDay(object sender, C1.Win.C1GanttView.PaintDayEventArgs e)
{
// タスク名が "Task2" の行の位置情報を取得
if (e.Task != null && e.Task.Name == "Task2")
{
_left = Math.Min(_left, e.Rectangle.Left);
_right = Math.Max(_right, e.Rectangle.Right);
_bottom = e.Rectangle.Bottom;
_draw = true;
}
}
private void c1GanttView1_Paint(object sender, PaintEventArgs e)
{
if (!_draw) return;
_left += c1GanttView1.GridWidth;
_right += c1GanttView1.GridWidth;
_bottom += ((C1FlexGrid)c1GanttView1.Controls[0]).Top;
// "Task2" の行の下端に 2px の青線を描画
using (var pen = new Pen(Color.Violet, 2))
{
e.Graphics.DrawLine(
pen,
_left,
_bottom - 1,
_right,
_bottom - 1);
}
_draw = false;
_left = int.MaxValue;
_right = int.MinValue;
_bottom = 0;
}
}
}