c# - Defined max. and min. size is somewhere overridden -
i developing gui content defined in specific xml file. have called widgets. these widgets have it's own implemented logic plus have defined width , height. both, minimum , maximum size, fix , cannot changed. widget usercontrol.
screenshot showing fix max. , min. size:
for right unknown reason size during runtime different. seen on following screenshot: 
beside designer file of singleplayerwidget own source code, of singeplayerwidget, following:
using system; using system.drawing; using system.windows.forms; using racetrack.controller; namespace racetrack.view.widgets { public partial class singleplayerwidget : usercontrol { private gamecontroller controller; public singleplayerwidget() { initializecomponent(); this.extendedtextboxplayername.setplaceholder("choose playername"); } public singleplayerwidget(gamecontroller controller) { initializecomponent(); this.controller = controller; this.extendedtextboxplayername.setplaceholder("choose playername"); this.colordialogcarcolor = new colordialog(); this.colordialogcarcolor.color = color.black; this.panelcarcolor.backcolor = this.colordialogcarcolor.color; } private void menubuttonchangecarcolor_click(object sender, eventargs e) { this.colordialogcarcolor.showdialog(); this.panelcarcolor.backcolor = this.colordialogcarcolor.color; } } } and designer source code:
namespace racetrack.view.widgets { partial class singleplayerwidget { /// <summary> /// required designer variable. /// </summary> private system.componentmodel.icontainer components = null; /// <summary> /// clean resources being used. /// </summary> /// <param name="disposing">true if managed resources should disposed; otherwise, false.</param> protected override void dispose(bool disposing) { if (disposing && (components != null)) { components.dispose(); } base.dispose(disposing); } #region component designer generated code /// <summary> /// required method designer support - not modify /// contents of method code editor. /// </summary> private void initializecomponent() { this.labelwidgetheadline = new system.windows.forms.label(); this.labelplayername = new system.windows.forms.label(); this.colordialogcarcolor = new system.windows.forms.colordialog(); this.labelcarcolor = new system.windows.forms.label(); this.panelcarcolor = new system.windows.forms.panel(); this.menubuttonchangecarcolor = new racetrack.view.forms.menubutton(); this.extendedtextboxplayername = new racetrack.view.forms.extendedtextbox(); this.suspendlayout(); // // labelwidgetheadline // this.labelwidgetheadline.anchor = system.windows.forms.anchorstyles.none; this.labelwidgetheadline.autosize = true; this.labelwidgetheadline.font = new system.drawing.font("microsoft sans serif", 13.8f, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ((byte)(0))); this.labelwidgetheadline.location = new system.drawing.point(14, 8); this.labelwidgetheadline.name = "labelwidgetheadline"; this.labelwidgetheadline.size = new system.drawing.size(188, 29); this.labelwidgetheadline.tabindex = 2; this.labelwidgetheadline.text = "your character"; // // labelplayername // this.labelplayername.anchor = system.windows.forms.anchorstyles.none; this.labelplayername.autosize = true; this.labelplayername.location = new system.drawing.point(17, 58); this.labelplayername.name = "labelplayername"; this.labelplayername.size = new system.drawing.size(87, 17); this.labelplayername.tabindex = 3; this.labelplayername.text = "playername:"; // // labelcarcolor // this.labelcarcolor.anchor = system.windows.forms.anchorstyles.none; this.labelcarcolor.autosize = true; this.labelcarcolor.location = new system.drawing.point(17, 120); this.labelcarcolor.name = "labelcarcolor"; this.labelcarcolor.size = new system.drawing.size(69, 17); this.labelcarcolor.tabindex = 5; this.labelcarcolor.text = "car color:"; // // panelcarcolor // this.panelcarcolor.anchor = system.windows.forms.anchorstyles.none; this.panelcarcolor.location = new system.drawing.point(20, 140); this.panelcarcolor.name = "panelcarcolor"; this.panelcarcolor.size = new system.drawing.size(80, 37); this.panelcarcolor.tabindex = 8; // // menubuttonchangecarcolor // this.menubuttonchangecarcolor.anchor = system.windows.forms.anchorstyles.none; this.menubuttonchangecarcolor.backcolor = system.drawing.systemcolors.gradientinactivecaption; this.menubuttonchangecarcolor.flatappearance.bordersize = 0; this.menubuttonchangecarcolor.flatstyle = system.windows.forms.flatstyle.flat; this.menubuttonchangecarcolor.location = new system.drawing.point(119, 140); this.menubuttonchangecarcolor.name = "menubuttonchangecarcolor"; this.menubuttonchangecarcolor.size = new system.drawing.size(75, 37); this.menubuttonchangecarcolor.tabindex = 9; this.menubuttonchangecarcolor.text = "change"; this.menubuttonchangecarcolor.usevisualstylebackcolor = false; this.menubuttonchangecarcolor.click += new system.eventhandler(this.menubuttonchangecarcolor_click); // // extendedtextboxplayername // this.extendedtextboxplayername.anchor = system.windows.forms.anchorstyles.none; this.extendedtextboxplayername.location = new system.drawing.point(19, 83); this.extendedtextboxplayername.name = "extendedtextboxplayername"; this.extendedtextboxplayername.size = new system.drawing.size(180, 22); this.extendedtextboxplayername.tabindex = 4; // // singleplayerwidget // this.autoscaledimensions = new system.drawing.sizef(8f, 16f); this.autoscalemode = system.windows.forms.autoscalemode.font; this.backcolor = system.drawing.systemcolors.window; this.borderstyle = system.windows.forms.borderstyle.fixedsingle; this.controls.add(this.menubuttonchangecarcolor); this.controls.add(this.panelcarcolor); this.controls.add(this.labelcarcolor); this.controls.add(this.extendedtextboxplayername); this.controls.add(this.labelplayername); this.controls.add(this.labelwidgetheadline); this.maximumsize = new system.drawing.size(225, 325); this.minimumsize = new system.drawing.size(225, 325); this.name = "singleplayerwidget"; this.size = new system.drawing.size(225, 325); this.resumelayout(false); this.performlayout(); } #endregion private system.windows.forms.label labelwidgetheadline; private system.windows.forms.label labelplayername; private system.windows.forms.colordialog colordialogcarcolor; private forms.extendedtextbox extendedtextboxplayername; private system.windows.forms.label labelcarcolor; private system.windows.forms.panel panelcarcolor; private forms.menubutton menubuttonchangecarcolor; } } my gameconfigurationview has autosize = false. widgets have same property value , source code (i exclude designer file of question length). i know source code needs cleaned later.
as can see following source code assign size well, when initializing new widget. not work either.
using system.drawing; using system.windows.forms; using system.xml; using racetrack.controller; using racetrack.view.widgets; namespace racetrack.view { public partial class gameconfigurationview : form { protected gamecontroller controller { get; set; } protected mapselectionwidget mapselectionwidget { get; set; } protected singleplayerwidget singleplayerwidget { get; set; } protected point guibuildernextlocation { get; set; } protected size guibuilderfinalsize { get; set; } protected int guibuildertallestelementincurrentrow { get; set; } protected int guibuilderwidthofcurrentrow { get; set; } public gameconfigurationview(gamecontroller controller) { initializecomponent(); this.controller = controller; this.guibuilder(); this.menubuttonstartgame.width = this.width; this.size = this.guibuilderfinalsize; } private void gameconfigurationview_formclosed(object sender, formclosedeventargs e) { this.controller.showstartview(); } /// <summary> /// builds gui based on configuration of selected gamevariant. /// </summary> protected void guibuilder() { xmlnodelist configuration = this.controller.selectedgamevariant.gameconfigurationview; this.guibuildernextlocation = new point(0, 0); this.guibuilderfinalsize = new size(0, 0); this.guibuildertallestelementincurrentrow = 0; (int = 0; < configuration.count; i++) { this.buildonerowfromgamevariantconfiguration(configuration[i].selectnodes("elements/element")); } } protected void buildonerowfromgamevariantconfiguration(xmlnodelist widgets) { this.guibuildernextlocation = new point( this.guibuildernextlocation.x - 1, this.guibuildernextlocation.y - 1 ); (int = 0; < widgets.count; i++) { this.guibuildernextlocation = new point( this.guibuildernextlocation.x - 1, this.guibuildernextlocation.y ); string elementtype = widgets[i].selectsinglenode("type").innertext; string elementwidth = widgets[i].selectsinglenode("width").innertext; switch (elementtype) { case "singleplayerwidget": this.addsingleplayerwidgettogui(); break; case "mapselectionwidget": this.addmapselectionwidgettogui(); break; case "multiplayerwidget": break; case "networkclientwidget": break; case "networkhostwidget": break; case "startbutton": break; } } // after row reset & update this.guibuildernextlocation = new point( 0, this.guibuildertallestelementincurrentrow + this.guibuildernextlocation.y ); if (this.guibuilderwidthofcurrentrow > this.guibuilderfinalsize.width) { this.guibuilderfinalsize = new size( this.guibuilderwidthofcurrentrow, this.guibuilderfinalsize.height + this.guibuildertallestelementincurrentrow ); } else { this.guibuilderfinalsize = new size( this.guibuilderfinalsize.width, this.guibuilderfinalsize.height + this.guibuildertallestelementincurrentrow ); } this.guibuildertallestelementincurrentrow = 0; this.guibuilderwidthofcurrentrow = 0; } protected void addsingleplayerwidgettogui() { // add gui this.singleplayerwidget = new singleplayerwidget(this.controller); this.singleplayerwidget.backcolor = systemcolors.buttonhighlight; this.singleplayerwidget.location = this.guibuildernextlocation; this.singleplayerwidget.name = "singleplayerwidget"; this.singleplayerwidget.size = new size(225, 325); this.singleplayerwidget.tabindex = 1; this.singleplayerwidget.show(); this.controls.add(this.singleplayerwidget); // update next location this.guibuildernextlocation = new point( this.singleplayerwidget.width + this.guibuildernextlocation.x, this.guibuildernextlocation.y ); if (this.singleplayerwidget.height > this.guibuildertallestelementincurrentrow) { this.guibuildertallestelementincurrentrow = this.singleplayerwidget.height; } this.guibuilderwidthofcurrentrow += this.singleplayerwidget.width + 1; } protected void addmapselectionwidgettogui() { // add gui this.mapselectionwidget = new mapselectionwidget(this.controller); this.mapselectionwidget.backcolor = systemcolors.buttonhighlight; this.mapselectionwidget.location = this.guibuildernextlocation; this.mapselectionwidget.name = "mapselectionwidget"; this.mapselectionwidget.size = new size(510, 325); this.mapselectionwidget.tabindex = 0; this.mapselectionwidget.show(); this.controls.add(this.mapselectionwidget); // update next location this.guibuildernextlocation = new point( this.mapselectionwidget.width + this.guibuildernextlocation.x, this.guibuildernextlocation.y ); if (this.mapselectionwidget.height > this.guibuildertallestelementincurrentrow) { this.guibuildertallestelementincurrentrow = this.mapselectionwidget.height; } this.guibuilderwidthofcurrentrow += this.mapselectionwidget.width + 1; } } } i appreciate :)
i have managed things working.
what did do? due oop have implemented basewidget containing label(s), configuration etc. available/required on every widget. basewidget has following settings:
autoscalemode = fontautosize = trueautosizemode = growonlysize = 275; 193though size overridden in respectivesubwidget
in each subwidget add forms anchor = anchorstyles.none
the gameconfigurationview defined follows:
autoscalemode = noneautosize = trueautosizemode = growonly
to honest not sure of these settings necessary have these settings , works. have more information edit answer.

Comments
Post a Comment