-1
我試圖教自己編程,並且我正在製作一個自動繪圖程序,將數據提交給excel並返回圖形。代碼如下: 保存文件,然後導出:VB.NET:內存耗盡System.Drawing.dll
「開程序激活,建立一個I/O流數據庫和加載圖表
Private Sub Form1_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
' Open the database
xlWorkBook = xlApp.Workbooks.Open(DatabasePath + "Database.xlsx")
' Set the relevant worksheet
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
' Set the display status of the database
xlApp.Visible = False
' Clear the picture box before exporting to prevent the compiler from accessing a file already in use
If Not (Graph.Image Is Nothing) Then
Graph.Image.Dispose()
End If
' Export the graph
xlWorkSheet.ChartObjects(1).chart.Export(FileName:=DatabasePath + ("Graph.gif"), FilterName:="gif")
' Load the saved graph image into the userform
Graph.Image = Image.FromFile(DatabasePath + ("Graph.gif"))
End Sub
它不會加載該文件在形式激活雖然。 當我使用另一段代碼更新Excel文件中的相關單元並更改繪製的數據時,會出現系統錯誤。
Private Sub Proposed_Dollars_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Proposed_Dollars.TextChanged
' Export the data values
xlWorkSheet.Range("Q10").Value = Proposed_Dollars.Text()
' Clear the picture box before exporting to prevent the compiler from accessing a file already in use
If Not (Graph.Image Is Nothing) Then
Graph.Image.Dispose()
End If
' Export the graph
xlWorkSheet.ChartObjects(1).chart.Export(FileName:=DatabasePath + ("Graph.gif"), FilterName:="GIF")
' Load the saved graph image into the userform
Graph.Image = Image.FromFile(DatabasePath + ("Graph.gif"))
End Sub
是否有我丟失會導致程序的圖形不加載到用戶窗體PictureBox的任何明顯的內存泄漏:細胞在用戶窗體使用文本框更改事件更新? 我感謝任何幫助。
是'圖表'你的圖片框的名字? – Plutonix 2014-10-11 00:34:10
對於輸入到文本框中的每個字符,這是一個很大的工作,你不覺得嗎? – OneFineDay 2014-10-11 00:35:47
導出後Graph.gif文件有多大?你可以在Paint或PhotoViewer或類似的東西中打開它嗎? – 2014-10-11 00:36:08