我的程序有一个自定义用户控件,其中包含一个粘贴处理程序。是否有必要在任何时候调用DataObject.RemovePastingHandler
方法,或者我的处理程序是否会被框架清理,例如当对象是Garbage Collected?
public class MyUserControl : UserControl
{
public MyUserControl()
: base()
{
// Other construction & initialisation code goes here.
// Add the pasting handler.
DataObject.AddPastingHandler(this, PastingHandler);
// Do I need to call the complimentary method anywhere?
// DataObject.RemovePastingHandler(this, PastingHandler);
}
private static void PastingHandler(object sender, DataObjectPastingEventArgs e)
{
// Do magic to handle the paste request.
}
}