c# - How do i edit existing info with winforms -
i developing calendar/appointment application , when double click on appointment while application running want open form information typed before , edit all.(with streamwriter , streamreader)!
private void edittoolstripmenuitem_click(object sender, eventargs e) { // raised selecting edit on content menu // todo - need complete method. // _selectedappointment set instance of appointment edited }
i have main form 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 background of panel g.fillrectangle(new solidbrush(color.linen), 0, 0, paintwidth, paintheight); paneltoprow = vscrollbar.value; if (_selectedrow >= paneltoprow && _selectedrow <= paneltoprow + displayedrowcount) { // if selected time displayed, mark g.fillrectangle(new solidbrush(color.darkkhaki), 0, (_selectedrow - paneltoprow) * panelrowheight, paintwidth, panelrowheight); } // display times @ start of rows , // lines separating rows nextrow = paneltoprow; (int = 0; <= 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, * panelrowheight, paintwidth, * panelrowheight); } // fill in appointments foreach (iappointment appointment in _todaysappointments) { apptstartrow = utility.converttimetorow(appointment.start); apptlength = utility.convertlengthtorows(appointment.length); // see if appointment inside part of day displayed on panel if (((apptstartrow >= paneltoprow) && (apptstartrow <= paneltoprow + displayedrowcount)) || (apptstartrow + apptlength > paneltoprow)) { // calculate area of panel occupied // 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 block of light blue g.fillrectangle(appointmentbrush, apptrectangle); // draw black line around g.drawrectangle(pens.black, apptrectangle); if (utility.converttimetorow(appointment.start) >= paneltoprow) { // if top line of appointment displayed, // write out subject , location. temporarily // reduce clip area graphics object ensure // text not extend beyond 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
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 form, appointment form , recurring appointment form. want when appointment showing on panel , double click it, edit it. if appointment appointment form should load, or if recurring appointment, recurring appointment form should load , edit it.
handle mousedoubleclick
-event, select appointment/recurring appointment coords , open corresponding editor.
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 part, need remember, placed appointments. example if have list each appointment stored, on x,y-coord , size has, can iterate on list in order find rectangle, contains click-coords.
Comments
Post a Comment