試圖改變方法名稱也試圖創建新的類,並從form1代碼,但沒有任何工作。我該如何修復錯誤:t類型Form1'已經使用相同的參數類型定義了一個名爲'Dispose'的成員?
這是在Form1的代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VirtualBox;
using System.Runtime.InteropServices;
namespace Desktop
{
public partial class Form1 : Form
{
#region DLLs
[DllImport("user32.dll")]
private static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode,
int dwFlags, long dwDesiredAccess, IntPtr lpsa);
[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);
[DllImport("user32.dll", EntryPoint = "CloseDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseDesktop(IntPtr handle);
[DllImport("user32.dll")]
public static extern bool SetThreadDesktop(IntPtr hDesktop);
[DllImport("user32.dll")]
public static extern IntPtr GetThreadDesktop(int dwThreadId);
[DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId();
#endregion
#region Enumeratoren
[Flags]
internal enum DESKTOP_ACCESS_MASK : uint
{
DESKTOP_NONE = 0,
DESKTOP_READOBJECTS = 0x0001,
DESKTOP_CREATEWINDOW = 0x0002,
DESKTOP_CREATEMENU = 0x0004,
DESKTOP_HOOKCONTROL = 0x0008,
DESKTOP_JOURNALRECORD = 0x0010,
DESKTOP_JOURNALPLAYBACK = 0x0020,
DESKTOP_ENUMERATE = 0x0040,
DESKTOP_WRITEOBJECTS = 0x0080,
DESKTOP_SWITCHDESKTOP = 0x0100,
GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP),
}
#endregion
public Form1()
{
InitializeComponent();
Desktop("MyDesktop");
System.Threading.Thread.Sleep(1000);
Application.DoEvents();
Desktop();
Application.DoEvents();
System.Threading.Thread.Sleep(3000);
SwitchToOrginal();
Application.DoEvents();
}
public void Dispose()
{
SwitchToOrginal();
((IDisposable)this).Dispose();
}
/// <summary>
/// Unterklassen können hier die Funktionalität der Objektzerstörung erweitern.
/// </summary>
/// <param name="fDisposing"></param>
protected virtual void Dispose(bool fDisposing)
{
if (fDisposing)
{
// Hier die verwalteten Ressourcen freigeben
//BspVariable1 = null;
CloseDesktop(DesktopPtr);
}
// Hier die unverwalteten Ressourcen freigeben
}
void IDisposable.Dispose()
{
Dispose(true);
GC.SuppressFinalize(this); //Fordert das System auf, den Finalizer für das angegebenen Objekt nicht aufzurufen
}
#region Variablen
IntPtr _hOrigDesktop;
public IntPtr DesktopPtr;
private string _sMyDesk;
public string DesktopName
{
get
{
return (_sMyDesk);
}
set
{
_sMyDesk = value;
}
}
#endregion
#region Konstruktoren
public void Desktop()
{
_sMyDesk = "";
}
public void Desktop(string sDesktopName)
{
_hOrigDesktop = GetCurrentDesktopPtr();
_sMyDesk = sDesktopName;
DesktopPtr = CreateMyDesktop();
}
#endregion
#region Methoden
public void show()
{
SetThreadDesktop(DesktopPtr);
SwitchDesktop(DesktopPtr);
}
public void SwitchToOrginal()
{
SwitchDesktop(_hOrigDesktop);
SetThreadDesktop(_hOrigDesktop);
}
private IntPtr CreateMyDesktop()
{
return CreateDesktop(_sMyDesk, IntPtr.Zero, IntPtr.Zero, 0, (long)DESKTOP_ACCESS_MASK.GENERIC_ALL, IntPtr.Zero);
}
public IntPtr GetCurrentDesktopPtr()
{
return GetThreadDesktop(GetCurrentThreadId());
}
#endregion
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
的錯誤是在這條線在Form1.designer.cs:
protected override void Dispose(bool disposing)
試圖在這裏和在Form1改變方法的名字,但它沒有工作。
什麼是你想「修復」沒有錯誤,你試圖實現處置,而它已經完成,爲什麼你想添加自己的處置代碼? – 2014-09-04 09:03:45