私のプログラムについて助けが必要です。カスタムDayView コントロールを使用して VB.NET プログラムを実行すると、このエラーが発生します。
************** 例外テキスト ************** System.NullReferenceException: オブジェクト参照がオブジェクトのインスタンスに設定されていません。SeaCow.Main.DayView1_ResolveAppointments (オブジェクト送信者、ResolveAppointmentsEventArgs args) で C:\Users\Daniel\My Programs\Visual Basic\SeaCow\SeaCow\SeaCow\Main.vb:Calendar.DayView.OnResolveAppointments(ResolveAppointmentsEventArgs args) で 120 行System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e、Int16 レイヤー) の Calendar.DayView.OnPaint(PaintEventArgs e) System.Windows.Forms.Control.WmPaint(Message& m) の System.Windows.Forms.Control.WndProc (Message& m) System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) で
エラー コードによると、以下の「for each」ループが NullReferenceException エラーを引き起こしています。デフォルトでは、「予定」リストは何も割り当てられておらず、ResolveAppointments 関数が呼び出されている場所を見つけることができません。
Private Sub DayView1_ResolveAppointments(ByVal sender As Object, ByVal args As Calendar.ResolveAppointmentsEventArgs) Handles DayView1.ResolveAppointments
Dim m_Apps As New List(Of Calendar.Appointment)
For Each m_App As Calendar.Appointment In appointments
If (m_App.StartDate >= args.StartDate) AndAlso (m_App.StartDate <= args.EndDate) Then
m_Apps.Add(m_App)
End If
Next
args.Appointments = m_Apps
End Sub
DayView.csコントロール ファイルの OnResolveAppointments 関数と ResolveAppointment 関数を次に示します。
public event EventHandler<ResolveAppointmentsEventArgs> OnResolveAppointments;
protected virtual void ResolveAppointments(ResolveAppointmentsEventArgs args)
{
System.Diagnostics.Debug.WriteLine("Resolve app");
if (OnResolveAppointments != null)
OnResolveAppointments(this, args);
this.allDayEventsHeaderHeight = 0;
// cache resolved appointments in hashtable by days.
cachedAppointments.Clear();
if ((selectedAppointmentIsNew) && (selectedAppointment != null))
{
if ((selectedAppointment.StartDate > args.StartDate) && (selectedAppointment.StartDate < args.EndDate))
{
args.Appointments.Add(selectedAppointment);
}
}
foreach (Appointment appointment in args.Appointments)
{
int key = -1;
AppointmentList list;
if (appointment.StartDate.Day == appointment.EndDate.Day && appointment.AllDayEvent == false)
{
key = appointment.StartDate.Day;
}
else
{
key = -1;
}
list = (AppointmentList)cachedAppointments[key];
if (list == null)
{
list = new AppointmentList();
cachedAppointments[key] = list;
}
list.Add(appointment);
}
}
また、ここにOnPaintメソッドがあります
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// resolve appointments on visible date range.
ResolveAppointmentsEventArgs args = new ResolveAppointmentsEventArgs(this.StartDate, this.StartDate.AddDays(daysToShow));
ResolveAppointments(args);
using (SolidBrush backBrush = new SolidBrush(renderer.BackColor))
e.Graphics.FillRectangle(backBrush, this.ClientRectangle);
// Visible Rectangle
Rectangle rectangle = new Rectangle(0, 0, this.Width - VScrollBarWith, this.Height);
DrawDays(ref e, rectangle);
DrawHourLabels(ref e, rectangle);
DrawDayHeaders(ref e, rectangle);
}
誰にも提案はありますか?