c# - Adding GUI controls dynamically -
i facing problem adding panel, 2 buttons in scrollable (through panel) group box. not in adding ui elements without designer, naturally, i've got cluttered interface doesn't work way intended.
here code:
private void client_downloadfilecompleted(object sender, system.componentmodel.asynccompletedeventargs e) { linksparser<track>.results.foreach<uri, track[]>( new action<uri, track[]>( // extension method delegate(uri key, track[] value) { groupbox gb = new groupbox() { text = key.absoluteuri, size = new size(550, value.length * 30), tabindex = 0, tabstop = false }; flwlayout.controls.add(gb); // flwlayout created designer panel gb_panel = new panel() { size = gb.size, tabindex = 0, tabstop = false, location = gb.location, autoscroll = false }; vscrollbar vs = new vscrollbar() { dock = dockstyle.right }; vs.scroll += (_sender, _e) => gb_panel.verticalscroll.value = vs.value; if (linksparser<track>.results[key] == null) { gb.controls.add(new label() { text = "no tracks found" }); } else { (int index = 0; index < 1; ++index) { track track = value[index]; panel panel = new panel() { borderstyle = borderstyle.fixedsingle, location = new point(gb.bounds.x + 6, gb.bounds.y + 15 + (40 * index)), size = new size(525, 40), tabindex = 0, tabstop = false }; label lbltrack; button playonline; lbltrack = new label() { text = track.name, autosize = true, tabindex = 0, location = new point(panel.bounds.x + 6, panel.bounds.y) }; playonline = new button() { text = "play online", tabindex = 2, size = new size(75, 23), usevisualstylebackcolor = true, location = new point( textrenderer.measuretext(lbltrack.text, lbltrack.font).width + lbltrack.bounds.x + 5, panel.bounds.y - 5) }; playonline.click += delegate { track.playonline(); }; panel.controls.add(lbltrack); logger.trace("attached lbltrack @ {0}", lbltrack.location); panel.controls.add(playonline); logger.trace("attached playonline @ {0}", playonline.location); gb_panel.controls.add(panel); logger.trace("attached panel @ {0}", panel.location); } } gb_panel.controls.add(vs); gb.controls.add(gb_panel); })); }
here get:
here want:
thanks idle_mind, advice using usercontrols (which hadn't heard of until pointed out) helped me dissect problem smaller parts , figured out the size of panel has absorb controls, according answer of question, used flowlayoutpanel instead, , controls appeared appropriately.
here final form, if anyone's interested:
Comments
Post a Comment