如何使用winforms编辑现有信息

时间:2015-04-29 11:51:37

标签: c# forms winforms streamreader streamwriter

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

pipeline = [
    {"$match": {"user.statuses_count": {"$gte":100 }, "user.time_zone": "Brasilia"}},
    {"$group": {"_id": "$user.id","max_followers": { "$max": "$user.followers_count" },"data": { "$addToSet": "$$ROOT" }}},
    {"$unwind": "$data"},   
    {"$project": {"_id": "$data._id","followers": "$max_followers","screen_name": "$data.user.screen_name","tweets": "$data.user.statuses_count"}}, 
    {"$sort": { "followers": -1 }},
    {"$limit" : 1}
]

我有一个带有月历的主表单

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

}

小组

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

和2个按钮

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

每个按钮都会加载表单,约会表单和定期约会表单。我想要的是当面板上显示约会并双击它,编辑它。如果是约会,则应加载约会表格,或如果是定期约会,则定期约会表格应加载并编辑。

1 个答案:

答案 0 :(得分:1)

处理MouseDoubleClick - 事件,通过坐标选择约会/定期约会并打开相应的编辑器。

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

对于这部分,您需要记住您放置约会的位置。例如,如果您有一个列表,其中存储了每个约会,x,y-coord是什么以及它具有的大小,您可以迭代该列表以查找包含您的click-coords的矩形。 / p>