Winform中实现跨窗体获取ZedGraph的ZedGraphControl控件对象
場(chǎng)景
Winforn中設(shè)置ZedGraph曲線圖的屬性、坐標(biāo)軸屬性、刻度屬性:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100112573
在主窗體中有一個(gè)ZedGraphControl控件,如果要在本窗體獲取此控件對(duì)象則通過(guò):
this.zedGraphControl1
其中zedGraphControl1是控件ZedGraphControl的name屬性。
?
如果在另一個(gè)窗體中獲取此控件對(duì)象并對(duì)其進(jìn)行屬性設(shè)置的話,正常邏輯是
聲明主窗體對(duì)象main,然后main.zedGraphControl1去調(diào)用。
但是卻不能對(duì)其屬性進(jìn)行更改。
注:
博客主頁(yè):
https://blog.csdn.net/badao_liumang_qizhi
關(guān)注公眾號(hào)
霸道的程序猿
獲取編程相關(guān)電子書、教程推送與免費(fèi)下載。
實(shí)現(xiàn)
在包含ZedGraphControl對(duì)象的主窗體中的load事件中將this.zedGraphControl1賦值給一個(gè)全局屬性,然后在
另一個(gè)窗體中調(diào)用全局屬性即可。
在load事件中:
?Global.zedGraphControl1 = this.zedGraphControl1;全局屬性聲明:
public class Global{#region 單例實(shí)現(xiàn)private static string _lockFlag = "GlobalLock";private static Global _instance;private Global(){}public static Global Instance{get{lock (_lockFlag){if (_instance == null){_instance = new Global();}return _instance;}}}#endregion??public static ZedGraphControl zedGraphControl1;public ZedGraphControl ZedGraphControl1{get { return ZedGraphControl1; }set { ZedGraphControl1 = value; }}}}在另一個(gè)窗體中調(diào)用:
DataChartHelper.RefreshPane(Global.zedGraphControl1);?
總結(jié)
以上是生活随笔為你收集整理的Winform中实现跨窗体获取ZedGraph的ZedGraphControl控件对象的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Winform中实现根据配置文件重新加载
- 下一篇: Nexus-在项目中使用Maven私服,