简体   繁体   English

如何使用Winforms编辑现有信息

[英]How do i edit existing info with winforms

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.(with streamwriter and streamreader)! 我正在开发一个日历/约会应用程序,当我在应用程序运行时双击约会时,我希望它使用之前键入的信息打开表格并进行全部编辑(使用streamwriter和streamreader)!

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

and 2 buttons 和2个按钮

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. 如果是约会,则应加载约会表单;如果是约会,则应加载并编辑重复约会表单。

Handle the MouseDoubleClick -event, select the appointment/recurring appointment by coords and open the corresponding editor. 处理MouseDoubleClick -event,通过坐标选择约会/重复约会并打开相应的编辑器。

private void panelDailyView_MouseDoubleClick(object sender, MouseEventArgs e)
{
    IAppointment appointment = CheckForAppointment(e.X, e.Y); 
    if (appointment != null) 
    { 
        if (appointment.IsRecurring)
        {
            using(RecurringAppointmentForm form3 = new RecurringAppointmentForm(appointment))
                form3.ShowDialog();
        }
        else
        {
            using(RecurringAppointmentForm form3 = new RecurringAppointmentForm(appointment))
                form3.ShowDialog();
        }
    } 
}

private void CheckForAppointment(int x, int y);

For this part, you need to remember, where you placed the appointments. 对于这一部分,您需要记住放置约会的位置。 For example if you have a list where for each appointment is stored, on which x,y-coord it is and which size it has, you can iterate over that list in order to find a rectangle, which contains your click-coords. 例如,如果您有一个用于存储每个约会的列表,它的x,y坐标为多少,尺寸为多少,则可以遍历该列表以找到一个矩形,其中包含单击坐标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM