Мне нужна помощь с моей программой. Я получаю эту ошибку при запуске моей программы VB.NET с пользовательским элементом управления DayView .
************** Exception Text **************
System.NullReferenceException: ссылка на объект не установлена на экземпляр объекта.
в SeaCow.Main.DayView1_ResolveAppointments (Отправитель объекта, аргументы ResolveAppointmentsEventArgs) в C: \ Users \ Daniel \ Мои программы \ Visual Basic \ SeaCow \ SeaCow \ SeaCow \ SeaCow \ Main.vb: строка 120
в Calendar.DayView.OnResolveAppointments (ResolveAppointmentsEventArgs args)
на Calendar.DayView.OnPaint (PaintEventArgs e)
в System.Windows.Forms.Control.PaintWithErrorHandling (PaintEventArgs e, слой Int16)
в System.Windows.Forms.Control.WmPaint (Сообщение & m)
в System.Windows.Forms.Control.WndProc (сообщение & m)
в System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
В соответствии с кодом ошибки приведенный ниже цикл «для каждого» вызывает ошибку 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
Вот функции OnResolveAppointments и ResolveAppointment из управляющего файла DayView.cs.
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);
}
У кого-нибудь есть предложения?