Sunday, 15 April 2012

c# - When Screen Resolution Changes the Panel and its Child Control display inside the WinForm -



c# - When Screen Resolution Changes the Panel and its Child Control display inside the WinForm -

i trying develop windows form application having 3 panels

panel 1(filebrowsepanel):- contrains textbox , browse button

panel 2(searchcriteriapanel ) :- lable date , todate datetimepicker command date , date checkbox each datetimepicker command 2 textboxes , listbox 2 buttons search , reset

panel 3(displaydatapanel):- listview display info from browse file path

panel 4(deletecriteriapanel):- having datetimepicker command delete info listview , file delete button

actual problem when alter resolution of screen panels , command on panel goes out of form width , height code is

void loadwindowssetting() { this.suspendlayout(); int i_standardheight = 768;//developer desktop height form designed int i_standardwidth = 1024; ;//developer desktop width form designed int i_presentheight = screen.primaryscreen.workingarea.height- systeminformation.captionheight; int i_presentwidth = screen.primaryscreen.bounds.width; float f_heightratio = new float(); float f_widthratio = new float(); f_heightratio = (float)((float)i_presentheight / (float)i_standardheight); f_widthratio = (float)((float)i_presentwidth / (float)i_standardwidth); foreach (control c in this.controls) { if (c.gettype().tostring() == "system.windows.forms.panel") { // c.setbounds(convert.toint32(c.bounds.x * f_widthratio), convert.toint32(c.bounds.y * f_widthratio), convert.toint32(c.bounds.width * f_widthratio), convert.toint32(c.bounds.height * f_heightratio)); } if (c.haschildren) { foreach (control cchildren in c.controls) { cchildren.setbounds(convert.toint32(cchildren.bounds.x * f_widthratio), convert.toint32(cchildren.bounds.y * f_widthratio), convert.toint32(cchildren.bounds.width * f_widthratio), convert.toint32(cchildren.bounds.height * f_heightratio)); } c.setbounds(convert.toint32(c.bounds.x * f_widthratio), convert.toint32(c.bounds.y * f_widthratio), convert.toint32(c.bounds.width * f_widthratio), convert.toint32(c.bounds.height * f_heightratio)); } else { c.setbounds(convert.toint32(c.bounds.x * f_widthratio), convert.toint32(c.bounds.y * f_widthratio), convert.toint32(c.bounds.width * f_widthratio), convert.toint32(c.bounds.height * f_heightratio)); } } btnbrowse.height = txtbrowsefilepath.height + 1; btnsubmit.height = btnbrowse.height; btnreset.height = btnbrowse.height; panelsearch.height += listboxlogtype.height; int leftspacepanelbrowse = (this.width - panelbrowse.width) / 2; int leftspacepanelsearch = (this.width - panelsearch.width) / 2; int leftspacepanelloglist = (this.width - panelloglist.width) / 2; int leftspacepaneldeletelog = (this.width - paneldeletelog.width) / 2; panelbrowse.location = new system.drawing.point(leftspacepanelbrowse - 8, 25); panelsearch.location = new system.drawing.point(leftspacepanelsearch - 8, panelbrowse.height + 40); panelloglist.location = new system.drawing.point(leftspacepanelloglist - 8, panelsearch.height + 140); progressbarfileload.location = new system.drawing.point((this.width / 2) - 100, panelloglist.bounds.y + panelloglist.height + 5); paneldeletelog.location = new system.drawing.point(leftspacepaneldeletelog - 8, panelloglist.bounds.y + panelloglist.height + progressbarfileload.height + 20); this.resumelayout(false); invalidate(); focus(); }

so can prevent command when screen resolution changes

form form load event phone call resizeform() function in such way

resolution objformresizer = new resolution(); objformresizer.resizeform(this, 768, 1024); public class resolution { float heightratio = new float(); float widthratio = new float(); int standardheight, standardwidth; public void resizeform(form objform, int designerheight, int designerwidth) { standardheight = designerheight; standardwidth = designerwidth; int presentheight = screen.primaryscreen.workingarea.height;//.bounds.height; int presentwidth = screen.primaryscreen.bounds.width; heightratio = (float)((float)presentheight / (float)standardheight); widthratio = (float)((float)presentwidth / (float)standardwidth); objform.autoscalemode = autoscalemode.none; objform.scale(new sizef(widthratio, heightratio)); foreach (control c in objform.controls) { if (c.haschildren) { resizecontrolstore(c); } else { c.font = new font(c.font.fontfamily, c.font.size * heightratio, c.font.style, c.font.unit, ((byte)(0))); } } objform.font = new font(objform.font.fontfamily, objform.font.size * heightratio, objform.font.style, objform.font.unit, ((byte)(0))); } private void resizecontrolstore(control objctl) { if (objctl.haschildren) { foreach (control cchildren in objctl.controls) { if (cchildren.haschildren) { resizecontrolstore(cchildren); } else { cchildren.font = new font(cchildren.font.fontfamily, cchildren.font.size * heightratio, cchildren.font.style, cchildren.font.unit, ((byte)(0))); } } objctl.font = new font(objctl.font.fontfamily, objctl.font.size * heightratio, objctl.font.style, objctl.font.unit, ((byte)(0))); } else { objctl.font = new font(objctl.font.fontfamily, objctl.font.size * heightratio, objctl.font.style, objctl.font.unit, ((byte)(0))); } } }

this class slove issue.......hope enjoy happy coding

c# winforms

No comments:

Post a Comment