Click here to Skip to main content
15,907,493 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing a calendar/appointment application and when i double click on the appointment while the application is running i want it to open the form with the information typed before and edit all.

C#
private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
     // Raised by selecting Edit on the content menu

     // TODO - You need to complete this method.
     // _SelectedAppointment is set to the instance of the appointment to be edited

}


I have a main form with a month calendar

C#
private void monthCalendar_DateChanged(object sender, DateRangeEventArgs e)
        {
       labelDisplayedDate.Text=monthCalendar.SelectionRange.Start.ToLongDateString();
            GetAppointmentsOnSelectedDate(monthCalendar.SelectionRange.Start);
            // Force repaint of daily view panel
            panelDailyView.Invalidate();
        }


a panel

C#
private void panelDailyView_Paint(object sender, PaintEventArgs e)
        {
            int paintWidth = panelDailyView.ClientRectangle.Size.Width - vScrollBar.Width;
            int paintHeight = panelDailyView.ClientRectangle.Size.Height;
            int displayedRowCount = paintHeight / PanelRowHeight;
            int panelTopRow;
            int nextRow;
            int apptStartRow;
            int apptLength;
            string dispTime; 
            
            Font font = new Font("Arial", 10);
            Brush drawBrush = new SolidBrush(Color.DarkBlue);
            Brush appointmentBrush = new SolidBrush(Color.LightBlue);

            Graphics g = e.Graphics;
            // Fill the background of the panel
            g.FillRectangle(new SolidBrush(Color.Linen), 0, 0, paintWidth, paintHeight);
            panelTopRow = vScrollBar.Value;
            if (_SelectedRow >= panelTopRow &&
                _SelectedRow <= panelTopRow + displayedRowCount)
            {
                // If the selected time is displayed, mark it
                g.FillRectangle(new SolidBrush(Color.DarkKhaki), 
                                0, 
                                (_SelectedRow - panelTopRow) * PanelRowHeight,
                                paintWidth,
                                PanelRowHeight);
            }
            // Display the times at the start of the rows and
            // the lines separating the rows
            nextRow = panelTopRow;
            for (int i = 0; i <= displayedRowCount; i++)
            {
                dispTime = (nextRow / 2).ToString("0#") + (nextRow % 2 == 0 ? ":00" : ":30");
                nextRow++;
                g.DrawString(dispTime, font, drawBrush, 2, (i * PanelRowHeight + 4));
                g.DrawLine(Pens.DarkBlue, 0, i * PanelRowHeight, paintWidth, i * PanelRowHeight);
            }
            // Now fill in the appointments
            foreach (IAppointment appointment in _TodaysAppointments)
            {
                apptStartRow = Utility.ConvertTimeToRow(appointment.Start);
                apptLength = Utility.ConvertLengthToRows(appointment.Length);
                // See if the appointment is inside the part of the day displayed on the panel
                if (((apptStartRow >= panelTopRow) && 
                     (apptStartRow <= panelTopRow + displayedRowCount)) ||
                    (apptStartRow + apptLength > panelTopRow))
                {
                    // Calculate the area of the panel occupied by
                    // the appointment
                    if (apptStartRow < panelTopRow)
                    {
                        apptLength = apptLength - (panelTopRow - apptStartRow);
                        apptStartRow = panelTopRow;
                    }
                    int apptDispStart = (apptStartRow - panelTopRow) * PanelRowHeight;
                    int apptDispLength = apptLength * PanelRowHeight;
                    if (apptDispStart + apptDispLength > paintHeight)  
                    {
                        apptDispLength = paintHeight - apptDispStart;
                    }
                    Rectangle apptRectangle = new Rectangle(ApptOffset,
                                                            apptDispStart,
                                                            paintWidth - (ApptOffset * 2),
                                                            apptDispLength);
                    // Draw the block of light blue
                    g.FillRectangle(appointmentBrush,
                                    apptRectangle);
                    // Draw the black line around it
                    g.DrawRectangle(Pens.Black, apptRectangle);
                    if (Utility.ConvertTimeToRow(appointment.Start) >= panelTopRow)
                    {
                        // If the top line of the appointment is displayed,
                        // write out the subject and location.  Temporarily
                        // reduce the clip area for the graphics object to ensure
                        // that the text does not extend beyond the rectangle
                        Region oldClip = g.Clip;
                        g.Clip = new Region(apptRectangle);
                        g.DrawString(appointment.DisplayableDescription,
                                     font,
                                     drawBrush,
                                     ApptOffset + 6,
                                     apptDispStart + 4);
                        g.Clip = oldClip;
                    }
                }
            }
        }


and 2 buttons

C#
private void buttonNewAppt_Click(object sender, EventArgs e)
        {
            NewAppointment();
            NewAppointment form2 = new NewAppointment();
            form2.ShowDialog();
        }


C#
private void buttonNewReccuringAppt_Click(object sender, EventArgs e)
        {
            NewRecurringAppointment();
            RecurringAppointmentForm form3 = new RecurringAppointmentForm();
            form3.ShowDialog();
        }



each button loads a form, the appointment form and the recurring appointment form. what i want is when an appointment is showing on the panel and double click it, to edit it. if it is an appointment the appointment form should load, or if it is recurring appointment, the recurring appointment form should load and edit it.
Posted
Updated 28-Apr-15 11:38am
v4
Comments
virusstorm 28-Apr-15 16:22pm    
Are you able to provide any code? We need to know what kind of controls you are using to help explain how to achieve your goal.
Member 11649865 28-Apr-15 16:29pm    
yes i just updated my question.
Richard MacCutchan 28-Apr-15 16:55pm    
Yes, but you forgot any of the useful code.
Member 11649865 28-Apr-15 17:12pm    
Like what kind of code? my main problem is that i cant complete that action
Richard MacCutchan 28-Apr-15 17:16pm    
Well all you have told us is that you want to "when i double click on the appointment while the application is running i want it to open the form with the information typed before and edit all."

But that tells us nothing about where this information is held, what form needs to be opened, how the information is structured so it can be edited, etc.

1 solution

You open the form by calling frm.Show or frm.ShowDialog where frm is an instance of your form. You can pass the data one by one through properties, through constructor or custom data class that holds all the data you want to edit.

When it closes, you check if the closing was positive (DialogResult.OK or some other way) and then copy changed data to your calendar.

If your form saves to the database, you could simply refresh your view.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900