本文整理汇总了C#中System.Windows.Forms.Document.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Dispose方法的具体用法?C# Document.Dispose怎么用?C# Document.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Document
的用法示例。
在下文中一共展示了Document.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResizeDocument
public static Document ResizeDocument(Document document, Size newSize, AnchorEdge edge, ColorBgra background)
{
Document newDoc = new Document(newSize.Width, newSize.Height);
newDoc.ReplaceMetaDataFrom(document);
for (int i = 0; i < document.Layers.Count; ++i)
{
Layer layer = (Layer)document.Layers[i];
if (layer is BitmapLayer)
{
Layer newLayer;
try
{
newLayer = ResizeLayer((BitmapLayer)layer, newSize, edge, background);
}
catch (OutOfMemoryException)
{
newDoc.Dispose();
throw;
}
newDoc.Layers.Add(newLayer);
}
else
{
throw new InvalidOperationException("Canvas Size does not support Layers that are not BitmapLayers");
}
}
return newDoc;
}
示例2: PerformAction
public override void PerformAction(AppWorkspace appWorkspace)
{
try
{
IDataObject pasted;
Image image;
using (new WaitCursorChanger(appWorkspace))
{
Utility.GCFullCollect();
pasted = Clipboard.GetDataObject();
image = (Image)pasted.GetData(DataFormats.Bitmap);
}
if (image == null)
{
Utility.ErrorBox(appWorkspace, PdnResources.GetString("PasteInToNewImageAction.Error.NoClipboardImage"));
}
else
{
Size newSize = image.Size;
image.Dispose();
image = null;
pasted = null;
Document document = null;
using (new WaitCursorChanger(appWorkspace))
{
document = new Document(newSize);
DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();
dw.Document = document;
dw.History.PushNewMemento(new NullHistoryMemento(string.Empty, null));
PasteInToNewLayerAction pitnla = new PasteInToNewLayerAction(dw);
bool result = pitnla.PerformAction();
if (result)
{
dw.Selection.Reset();
dw.SetDocumentSaveOptions(null, null, null);
dw.History.ClearAll();
dw.History.PushNewMemento(
new NullHistoryMemento(
PdnResources.GetString("NewImageAction.Name"),
PdnResources.GetImageResource("Icons.MenuLayersAddNewLayerIcon.png")));
appWorkspace.ActiveDocumentWorkspace = dw;
}
else
{
appWorkspace.RemoveDocumentWorkspace(dw);
document.Dispose();
}
}
}
}
catch (ExternalException)
{
Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.TransferError"));
return;
}
catch (OutOfMemoryException)
{
Utility.ErrorBox(appWorkspace, PdnResources.GetString("AcquireImageAction.Error.Clipboard.OutOfMemory"));
return;
}
catch (ThreadStateException)
{
// The ApartmentState property of the application is not set to ApartmentState.STA
// I don't think this one will ever happen, seeing as how Main is tagged with the
// STA attribute.
return;
}
}
示例3: ImportDocument
/// <summary>
/// Presents a user interface and performs the operations required for importing an entire document.
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
/// <remarks>
/// This function will take ownership of the Document given to it, and will Dispose() of it.
/// </remarks>
private HistoryMemento ImportDocument(DocumentWorkspace documentWorkspace, Document document, out Rectangle lastLayerBounds)
{
List<HistoryMemento> historyMementos = new List<HistoryMemento>();
bool[] selected;
selected = new bool[document.Layers.Count];
for (int i = 0; i < selected.Length; ++i)
{
selected[i] = true;
}
lastLayerBounds = Rectangle.Empty;
if (selected != null)
{
List<Layer> layers = new List<Layer>();
for (int i = 0; i < selected.Length; ++i)
{
if (selected[i])
{
layers.Add((Layer)document.Layers[i]);
}
}
foreach (Layer layer in layers)
{
document.Layers.Remove(layer);
}
document.Dispose();
document = null;
foreach (Layer layer in layers)
{
lastLayerBounds = layer.Bounds;
HistoryMemento ha = ImportOneLayer(documentWorkspace, (BitmapLayer)layer);
if (ha != null)
{
historyMementos.Add(ha);
}
else
{
Rollback(historyMementos);
historyMementos.Clear();
break;
}
}
}
if (document != null)
{
document.Dispose();
document = null;
}
if (historyMementos.Count > 0)
{
HistoryMemento[] has = historyMementos.ToArray();
return new CompoundHistoryMemento(string.Empty, null, has);
}
else
{
lastLayerBounds = Rectangle.Empty;
return null;
}
}
示例4: findButton_Click
/// <summary>
/// Occurs when the button is clicked.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="e">Event arguments.</param>
private void findButton_Click(object sender, System.EventArgs e)
{
// Update find/replace options
//if ((this.owner as UCEditor)._ParentTab.Selected != true)
// (this.owner as UCEditor)._ParentTab.Selected = true;
this.UpdateFindReplaceOptions();
if (editor == null && optEntireProject.Checked == false) {
MessageBox.Show("No open windows.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
// Save this last search in the list
if (!g.Project.Finds.Contains(findTextBox.Text)) {
// Remove old stuff
if (g.Project.Finds.Count == 10)
g.Project.Finds.RemoveAt(0);
g.Project.Finds.Add(findTextBox.Text);
g.Main.cboRecentSearches.Text = findTextBox.Text;
RehashRecent();
}
// Set the status
//owner.SetStatusMessage("Find: \"" + options.FindText + "\"");
if (this.optCurFile.Checked || this.optSelection.Checked) {
// Perform find operation on currently open file
FindReplaceResultSet resultSet = null;
options.SearchInSelection = this.optSelection.Checked;
try {
resultSet = editor.SelectedView.FindReplace.Find(options);
} catch { return; }
if (resultSet.PastEndOfDocument)
MessageBox.Show(this, "Search past end of file; jumping to beginning.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (resultSet.Count == 0)
MessageBox.Show(this, "Cannot find search string.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information);
} else if (this.optAllFiles.Checked) {
// Perform search on all open files
PrimaryTab<UCEditor> ed = g.Editors[ActiveDocument];
SyntaxEditor actdoc = ed.Control.txtEditor;
ed.page.Selected = true;
FindReplaceResultSet resultSet = null;
try {
resultSet = actdoc.SelectedView.FindReplace.Find(options);
} catch { return; }
if (resultSet.PastEndOfDocument || resultSet.Count == 0) {
if (g.Editors.Count == (ActiveDocument + 1)) {
MessageBox.Show(this, "All open files searched; jumping to beginning.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information);
ActiveDocument = 0;
return;
} else {
ActiveDocument++;
}
if (resultSet.Count == 0)
findButton_Click(null, null);
}
} else if (this.optEntireProject.Checked) {
// Perform search on all files
UCFindResults fFindResults = new UCFindResults();
fFindResults.lvFind.BeginUpdate();
System.IO.Directory.SetCurrentDirectory(g.Project.ProjectPath);
foreach(CProject.File file in g.Project.FileList) {
Document doc = new Document();
try {
doc.LoadFile(System.IO.Path.GetFullPath(file.RelativePath));
} catch { continue; }
FindReplaceResultSet results = doc.FindReplace.FindAll(options);
foreach(FindReplaceResult result in results) {
ListViewItem item = new ListViewItem(file.RelativePath);
item.SubItems.Add(Convert.ToString(doc.OffsetToPosition(result.Offset).Line + 1));
item.SubItems.Add(doc.Lines[doc.OffsetToPosition(result.Offset).Line].Text);
item.Tag = file;
fFindResults.lvFind.Items.Add(item);
}
doc.Dispose();
doc = null;
}
//.........这里部分代码省略.........