c# - Strange location of panels -


i have program kind of tests. in test, have function addquestion adds 1 panel question. place these panels 1 one, have variable loc saves location of next panel. first 2 panel's questions adds correct, next ones located wrong(far away @ bottom). can be?

public void addquestion(int number, question quest)         {             panel p = new panel();             p.name = "panel" + (number);             p.size = new size(550, 400);             p.location = new point(40, loc);             p.backcolor = system.drawing.color.bisque;             p.autoscroll = true;             panel pict_block = new panel();             pict_block.size = new size(480, 200);             pict_block.location = new point(10, 10);             picturebox pict = new picturebox();             pict.image = quest.image;             pict.size = new size(240, 180);             pict.sizemode = pictureboxsizemode.stretchimage;             pict.location = new point(130, 1);             pict_block.controls.add(pict);             p.controls.add(pict_block);              label number_text = new label(); //номер питання             number_text.text = "Питання № " + number ;             number_text.font = new font("aria", 8, fontstyle.bold);             number_text.autosize = false;             number_text.location = new point(400, 210);             p.controls.add(number_text);              label q_text = new label(); // текст питання             q_text.text = quest.question_text;             q_text.font = new font("aria", 9, fontstyle.bold);             q_text.autosize = false;             q_text.size = new size(400, 50);             q_text.location = new point(5, 220);             p.controls.add(q_text);             int iter = q_text.location.y + 60;             if (checkifmuliple(number))             {                 foreach (string key in quest.answers.keys)                 {                     checkbox rb = new checkbox();                     rb.text = key;                     rb.autosize = true;                     rb.size = new size(300, 25);                     rb.location = new point(q_text.location.x + 15, iter);                     iter += 30;                     p.controls.add(rb);                 }              }             else                 {                     foreach (string key in quest.answers.keys)                     {                         radiobutton rb = new radiobutton();                         rb.text = key;                         rb.size = new size(300, 25);                         rb.autosize = true;                         rb.location = new point(q_text.location.x + 10, iter);                         iter += 30;                         p.controls.add(rb);                     }                 }             questions_panel.controls.add(p);             loc += 450;          } 

good location: enter image description here

bad location: enter image description here

also noticed when add panels, scrool @ middle of form , add new question, it's not located @ bottom, somewhere @ center. next screenshot, 6 question , 15 question: enter image description here

getting right manually difficult.

i suggest change questions_panel tablelayoutpanel. takes care of positioning new controls automatically you.

tablelayoutpanel

represents panel dynamically lays out contents in grid composed of rows , columns.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -