當我使用MemoryStream
從資源文件加載Cursor
時,我收到一個ArgumentException
。這裏是我用來加載光標的代碼:當從資源文件讀取遊標時拋出ArgumentException
Cursor myCursor
= new Cursor(new MemoryStream(WaterforMGC.Properties.Resources.waterspray));
Cursor = myCursor;
但是我得到錯誤。我不知道什麼是錯的,我甚至將Cursor = myCursor;
更改爲this.Cursor = myCursor;
,這給了我同樣的錯誤。我試過gameform.Cursor = myCursor;
,但那根本不起作用。
System.ArgumentException: Image format is not valid. The image file may be corrupted. Parameter name: stream ---> System.Runtime.InteropServices.COMException (0x800A01E1): Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE) at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm) at System.Windows.Forms.Cursor.LoadPicture(IStream stream) --- End of inner exception stack trace --- at System.Windows.Forms.Cursor.LoadPicture(IStream stream) at WaterforMGC.gameform.Form1_Load(Object sender, EventArgs e) in C:\Users\Jan\Documents\Visual Studio 2008\Projects\WaterforMGC\WaterforMGC\Form1.cs:line 39 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
你的圖片格式是什麼? –
異常消息有讀取......顯然你沒有這樣做,因爲你改變了行後的東西,導致異常修復錯誤... –
@丹:我懷疑他知道什麼他正在尋找那個巨大的例外文本牆。我削減了它,希望它會有所幫助。 – user7116