2017-10-09 27 views
0

我正在使用c#,如何将图表的标题放在字符串变量中?c#把图表的标题放在字符串变量中

我使用的是委托所以这里是我的代码:

private void ChartTitle(object sender, MouseEventArgs e) 
{ 
    Chart Chart = (Chart)sender; 
    string title=Chart.Titles. ??? 
} 
+1

WinForms,WPF,ASP.NET WebFor ms,UWP? – Backs

+0

'string title = Chart.Titles是什么? ''... –

+0

和无论哪个框架...你看过文档吗?...第一步 –

回答

0

作为msdn documentation说,你应该添加一个标题是这样的:

Chart1.Titles.Add("My Chart"); // Titles text, not the name 
Chart1.Titles.["Title1"].Name = "MyTitle"; // By default charts titles name is Title1, we rename it 

然后,你可以得到值与:

string title = Chart1.Titles["MyTitle"].Text; 
+0

在主表单中,我制作了一个图表,然后我使用委托,里面我必须得到标题的名称,我不能使用字符串title = Chart1.Titles [“MyTitle”]。我不能使用这个原因,实际上我没有“MyTitle”,但我必须找到它,因为图表的某些方法我认为 – ale

+0

所以这就是为什么当你初始化图表时你需要创建一个图表,另一个是不可能的访问不存在的元素。 – Ferus7

+0

[this](https://dotnetfiddle.net/swgg4W)完全适合我 – Ferus7