場景
Winform中實作跨表單獲取ZedGraph的ZedGraphControl控制元件物件:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/101375325
之前寫過使用存取全域物件的方式去跨表單獲取控制元件物件,
在主表單中有一個ZedGraphControl控制元件,如果要在本表單獲取此控制元件物件則通過:
this.zedGraphControl1
其中zedGraphControl1是控制元件ZedGraphControl的name屬性,
如果在另一個表單中獲取此控制元件物件并對其進行屬性設定的話,正常邏輯是
宣告主表單物件main,然后main.zedGraphControl1去呼叫,
但是試過之后發現卻不能對其屬性進行更改,
因為每次new 出來是一個新的物件,并不是想獲取的控制元件物件
注:
博客主頁:
https://blog.csdn.net/badao_liumang_qizhi
關注公眾號
霸道的程式猿
獲取編程相關電子書、教程推送與免費下載,
實作
現在要在FrmPDFOption這個表單中獲取MainViewContent這個表單的zedGraph控制元件,
在MainViewContent表單中,宣告一個public的靜態的當前表單物件:
public static MainViewContent mainViewContent;
然后在MainViewContent的構造方法中將this即當前表單物件賦值給上面的表單物件:
public MainViewContent() { InitializeComponent(); mainViewContent = this; }
然后在要呼叫當前MainViewContent的表單中獲取其控制元件:
System.Drawing.Image image = MainViewContent.mainViewContent.zedGraphControl1.GetImage();
這里是直接獲取MainViewContent中zedGraphControl1的image物件,
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/116676.html
標籤:C#
