如何编辑现有信息? [英] How Do I Edit Existing Info?

查看:85
本文介绍了如何编辑现有信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发日历/约会应用程序,当我在应用程序运行时双击约会时,我希望它打开包含之前输入的信息并编辑所有信息的表单。



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.

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

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面板





a panel

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;
                    }
                }
            }
        }





和2个按钮





and 2 buttons

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







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.

推荐答案

你打开表格调用frm.Show或frm.ShowDialog,其中frm是表单的一个实例。您可以通过属性,构造函数或自定义数据类逐个传递数据,该数据类包含您要编辑的所有数据。



当它关闭时,您检查是否结束是积极的(DialogResult.OK或其他方式),然后将更改的数据复制到您的日历。



如果您的表单保存到数据库,您只需刷新你的观点。
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.


这篇关于如何编辑现有信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆