Imports GrapeCity.Win.CalendarGrid
Private _contextMenu As ContextMenuStrip
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_contextMenu = New ContextMenuStrip()
Dim menuItem1 = New ToolStripMenuItem("項目1")
Dim menuItem2 = New ToolStripMenuItem("項目2")
_contextMenu.Items.AddRange(New ToolStripItem() {menuItem1, menuItem2})
GcCalendarGrid1.Content(DateTime.Today).CellStyle.BackColor = Color.Azure
GcCalendarGrid1.ScrollIntoView(DateTime.Today)
End Sub
Private Sub GcCalendarGrid1_MouseDown(sender As Object, e As MouseEventArgs) Handles GcCalendarGrid1.MouseDown
If e.Button = MouseButtons.Right Then
Dim gcCalendarGrid As GcCalendarGrid = DirectCast(sender, GcCalendarGrid)
Dim hitTestInfo = gcCalendarGrid.HitTest(e.Location)
If hitTestInfo.CellPosition.Date = DateTime.Today Then
_contextMenu.Show(gcCalendarGrid, e.Location)
End If
End If
End Sub
using GrapeCity.Win.CalendarGrid;
ContextMenuStrip _contextMenu;
private void Form1_Load(object sender, EventArgs e)
{
_contextMenu = new ContextMenuStrip();
var menuItem1 = new ToolStripMenuItem("項目1");
var menuItem2 = new ToolStripMenuItem("項目2");
_contextMenu.Items.AddRange(new ToolStripItem[] { menuItem1, menuItem2 });
gcCalendarGrid1.Content[DateTime.Today].CellStyle.BackColor = Color.Azure;
gcCalendarGrid1.ScrollIntoView(DateTime.Today);
gcCalendarGrid1.MouseDown += gcCalendarGrid1_MouseDown;
}
private void gcCalendarGrid1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
GcCalendarGrid gcCalendarGrid = sender as GcCalendarGrid;
CalendarHitTestInfo hitTestInfo = gcCalendarGrid.HitTest(e.Location);
if (hitTestInfo.CellPosition.Date == DateTime.Today)
{
_contextMenu.Show(gcCalendarGrid, e.Location);
}
}
}