简体   繁体   English

Microsoft WinForms图表控件-TitleBox

[英]Microsoft WinForms Chart Control - TitleBox

I am looking to produce this type of TitleBox in the Microsoft WinForms Chart Control, so that the titlebox is docked to the top of the chartarea. 我希望在Microsoft WinForms图表控件中产生这种类型的TitleBox,以使titlebox停靠在图表区域的顶部。

在此处输入图片说明

Is there any way to position the standard titlebox on the top of the chartarea like this or can I add such a textbox to the chart control? 有没有办法像这样将标准标题框放置在图表区域的顶部,还是可以将这样的文本框添加到图表控件中?

Option 1: You can add a Label into the Chart like this: 选项1:您可以像这样在Chart添加Label

int lh = (int)(label1.Height / chart1.Height * 100f);
int cw = chart1.Width;

ChartArea CA = chart1.ChartAreas[0];
ElementPosition EP = CA.InnerPlotPosition;
CA.InnerPlotPosition = new ElementPosition(EP.X, EP.Y + lh, EP.Width, EP.Height - lh);
label1.Location = new Point((int)(EP.X * cw / 100f) + 10, 0);
label1.Width = (int)(EP.Width * cw / 100f) - 20;
label1.Height -= 2;
label1.Parent = chart1;

Or you may want to position the Label by docking it to the top.. 或者您可能希望通过将标签停靠在顶部来放置标签。

You can style the Label to your liking, even add an Image .. 您可以根据自己的喜好设置Label样式,甚至可以添加Image ..

You may need to play with the offset for the label.Height! 您可能需要使用标签的偏移量。高度!

在此处输入图片说明

Option 2: You can move the Title box around in the same way: 选项2:您可以通过以下方式来移动标题框:

chart1.Titles.Add("TiltelBox");
Title T = chart1.Titles[0];
ChartArea CA = chart1.ChartAreas[0];

T.DockedToChartArea = CA.Name;
T.BackColor = Color.Wheat;
T.Docking = Docking.Top;
T.IsDockedInsideChartArea = true;
ElementPosition EP = T.Position;
T.Position = new ElementPosition
                (EP.X + 10f, EP.Y -0.5f, EP.Width + 83.5f, EP.Height + 9f);

在此处输入图片说明

Again: you will want to play around with the way you position the Title. 再说一遍:您将需要按照定位标题的方式进行操作。 The ones above happend to work here but you will need to change them with you chart.. 上面的那些碰巧在这里起作用,但是您需要随图表更改它们。

Remember that the ElementPosition uses 1/100 of the chart size as its unit; 请记住, ElementPosition使用图表大小的1/100作为单位; this is nice as it scales but makes it hard to set up at first.. 这很好,因为它可以扩展,但一开始很难设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM