DockStyle Fill for Created RunTime Controls

I am trying to do something very simple, which gives me huge problems in C # Winforms. I have two group fields in TabPage. One docked right and one docked bottom. I also have a chart on the page (System.Windows.Forms.DataVisualization.Charting). This graph is for Dock.Fill the remaining space on the page.

At first I ran into the problem of a chart hiding behind both group boxes, and a docking station filling the entire page. However, I found that I could solve this problem using "BringToFront" (or reordering the order of the document structure), and then the chart docked properly and did not overlap any other controls on the page.

However, I try to add a diagram to the page at runtime, and it fills the whole page again and hides behind other controls. How can I do this work?

EDIT: Forgot to mention, calling "BringToFront" will throw an exception "Width must be greater than 0px".

chart_TapChart = new Chart(); chart_TapChart.Dock = DockStyle.Fill; chart_TapChart.BringToFront(); GroupBox gp1 = new GroupBox(); gp1.Dock = DockStyle.Right; GroupBox gp2 = new GroupBox(); gp2.Dock = DockStyle.Bottom; this.Controls.Add(chart_TapChart); <--this refers to tabpage this.Controls.Add(gp1); this.Controls.Add(gp2); 
+6
source share
6 answers

It turns out that you need to wait until TabPage has already been viewed (you need to program yourtabpage.select () call), then search using the controls on this tab, find the chart and call “BringToFront” on it. You may have installed Dock.Fill before adding a control to the page.

You cannot configure your z index until a bookmark is displayed.

+4
source

Do not fasten it. Bind it instead:

 Chart.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top; 

Edit:

as John pointed out, calling:

 Chart.BringToFront(); Chart.Dock = DockStyle.Fill; 

Must allow the document to play with other controls on the form.

+2
source

I had a similar problem with a chart control where it crashed if the height was set to zero. The error message was "height must be greater than 0px". By changing the dock from Fill to None and setting the snap properties, lock it instead. It looks like an error in controlling the chart, but finding any additional information is difficult ...

+1
source

We had problems with "height should be greater than 0px". It turns out the problem / solution is the display settings. Setting the screen size to something over 100% led to the creation of DockStyle. Filling certain elements that fill all available space, leaving a chart with a height of 0px during initialization. Installing anchors instead of using Fill worked on the problem, but it really is a mistake in managing the chart.

+1
source

I managed to solve this problem and save the filled set of the docking station by setting the minimum chart size to 10.10.

+1
source

Setting up Dockstyle None allows me to upload a form, but I really need to use the Fill docking style for some of my diagrams. I solved this problem by setting myChart.Dock = DockStyle.None in the constructor, and then setting myChart.Dock = DockStyle.None at the end of the Form.Load event in the code. Now the program loads without errors, and the diagrams are the correct size.

0
source

Source: https://habr.com/ru/post/910121/


All Articles