本文整理汇总了C#中ISurface.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ISurface.Dispose方法的具体用法?C# ISurface.Dispose怎么用?C# ISurface.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISurface
的用法示例。
在下文中一共展示了ISurface.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowPickerMenu
/// <summary>
/// This method will create and show the destination picker menu
/// </summary>
/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
/// <param name="surface">The surface which can be exported</param>
/// <param name="captureDetails">Details for the surface</param>
/// <param name="destinations">The list of destinations to show</param>
/// <returns></returns>
public ExportInformation ShowPickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
// Generate an empty ExportInformation object, for when nothing was selected.
ExportInformation exportInformation = new ExportInformation(Designation, Language.GetString("settings_destination_picker"));
ContextMenuStrip menu = new ContextMenuStrip();
menu.ImageScalingSize = configuration.IconSize;
menu.Tag = null;
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
switch (eventArgs.CloseReason) {
case ToolStripDropDownCloseReason.AppFocusChange:
if (menu.Tag == null) {
// Do not allow the close if the tag is not set, this means the user clicked somewhere else.
eventArgs.Cancel = true;
} else {
LOG.DebugFormat("Letting the menu 'close' as the tag is set to '{0}'", menu.Tag);
}
break;
case ToolStripDropDownCloseReason.ItemClicked:
case ToolStripDropDownCloseReason.CloseCalled:
// The ContextMenuStrip can be "closed" for these reasons.
break;
case ToolStripDropDownCloseReason.Keyboard:
// Dispose as the close is clicked
if (!captureDetails.HasDestination("Editor")) {
surface.Dispose();
surface = null;
}
break;
default:
eventArgs.Cancel = true;
break;
}
};
menu.MouseEnter += delegate(object source, EventArgs eventArgs) {
// in case the menu has been unfocused, focus again so that dropdown menus will still open on mouseenter
if(!menu.ContainsFocus) menu.Focus();
};
foreach (IDestination destination in destinations) {
// Fix foreach loop variable for the delegate
ToolStripMenuItem item = destination.GetMenuItem(addDynamics, menu,
delegate(object sender, EventArgs e) {
ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
if (toolStripMenuItem == null) {
return;
}
IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
if (clickedDestination == null) {
return;
}
menu.Tag = clickedDestination.Designation;
// Export
exportInformation = clickedDestination.ExportCapture(true, surface, captureDetails);
if (exportInformation != null && exportInformation.ExportMade) {
LOG.InfoFormat("Export to {0} success, closing menu", exportInformation.DestinationDescription);
// close menu if the destination wasn't the editor
menu.Close();
// Cleanup surface, only if there is no editor in the destinations and we didn't export to the editor
if (!captureDetails.HasDestination("Editor") && !"Editor".Equals(clickedDestination.Designation)) {
surface.Dispose();
surface = null;
}
} else {
LOG.Info("Export cancelled or failed, showing menu again");
// Make sure a click besides the menu don't close it.
menu.Tag = null;
// This prevents the problem that the context menu shows in the task-bar
ShowMenuAtCursor(menu);
}
}
);
if (item != null) {
menu.Items.Add(item);
}
}
// Close
menu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close"));
closeItem.Image = GreenshotResources.getImage("Close.Image");
closeItem.Click += delegate {
// This menu entry is the close itself, we can dispose the surface
menu.Close();
if (!captureDetails.HasDestination("Editor")) {
surface.Dispose();
surface = null;
}
};
menu.Items.Add(closeItem);
//.........这里部分代码省略.........
示例2: CreatePickerMenu
public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations)
{
ContextMenuStrip menu = new ContextMenuStrip();
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
if (eventArgs.CloseReason != ToolStripDropDownCloseReason.ItemClicked && eventArgs.CloseReason != ToolStripDropDownCloseReason.CloseCalled) {
eventArgs.Cancel = true;
}
};
foreach (IDestination destination in destinations) {
// Fix foreach loop variable for the delegate
ToolStripMenuItem item = destination.GetMenuItem(addDynamics,
delegate(object sender, EventArgs e) {
ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
if (toolStripMenuItem == null) {
return;
}
IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
if (clickedDestination == null) {
return;
}
// Make sure the menu is closed
menu.Close();
bool result = clickedDestination.ExportCapture(true, surface, captureDetails);
// TODO: Find some better way to detect that we exported to the editor
if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) {
LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result);
// Cleanup surface
surface.Dispose();
}
}
);
if (item != null) {
menu.Items.Add(item);
}
}
// Close
menu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString(LangKey.editor_close));
closeItem.Image = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)).GetObject("closeToolStripMenuItem.Image")));
closeItem.Click += delegate {
// This menu entry is the close itself, we can dispose the surface
menu.Close();
// Dispose as the close is clicked
surface.Dispose();
};
menu.Items.Add(closeItem);
return menu;
}