本文整理汇总了C#中ShapeCollection.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# ShapeCollection.Contains方法的具体用法?C# ShapeCollection.Contains怎么用?C# ShapeCollection.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShapeCollection
的用法示例。
在下文中一共展示了ShapeCollection.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
/// <summary>
/// Overridden save function
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public override bool Save(string filename)
{
PrefabDesc prefab = new PrefabDesc(filename);
ShapeCollection all = new ShapeCollection();
// the following shapes go into the prefab: lightgrid boxes, lights
foreach (ShapeBase shape in this.FilteredSupplier)
all.Add(shape);
foreach (ShapeBase shape in this.FilteredLights)
if (!all.Contains(shape))
all.Add(shape);
if (!prefab.CreateFromInstances(all, Vector3F.Zero, false, false))
return false;
return prefab.SaveToFile(null);
}
示例2: SortSelectedShapes
private void SortSelectedShapes(MoveShapesDirection moveDirection)
{
ShapeCollection selected = shapeTreeView.SelectedShapes;
// return if any of the indices is already on the maximum.
foreach (ShapeBase shape in selected)
{
if (moveDirection == MoveShapesDirection.Up)
{
if (shape.Parent.ChildCollection.FindIndex(i => i == shape) <= 0)
return;
}
else
if (shape.Parent.ChildCollection.FindIndex(i => i == shape) >= shape.Parent.ChildCollection.Count - 1)
return;
}
// get all parents to share modified collections between their children.
ShapeCollection parents = new ShapeCollection();
foreach (ShapeBase shape in selected)
if (!parents.Contains(shape.Parent))
parents.Add(shape.Parent);
EditorManager.Actions.StartGroup("Sort Shapes");
foreach (ShapeBase parent in parents)
{
// create copy of the original collection before sorting
ShapeCollection copyOfChildren = new ShapeCollection();
copyOfChildren.AddRange(parent.ChildCollection);
if (moveDirection == MoveShapesDirection.Up)
{
for (int i = 0; i < selected.Count; i++)
{
ShapeBase child = selected[i];
if (child.Parent == parent)
{
int index = copyOfChildren.FindIndex(c => c == child);
copyOfChildren.Remove(child);
copyOfChildren.Insert(index - 1, child);
EditorManager.Actions.Add(new SortShapeChildrenAction(parent, copyOfChildren));
}
}
}
else
for (int i = selected.Count - 1; i > -1; i--)
{
ShapeBase child = selected[i];
if (child.Parent == parent)
{
int index = copyOfChildren.FindIndex(c => c == child);
copyOfChildren.Remove(child);
copyOfChildren.Insert(index + 1, child);
EditorManager.Actions.Add(new SortShapeChildrenAction(parent, copyOfChildren));
}
}
}
EditorManager.Actions.EndGroup();
// recover selection
ArrayList newSelection = new ArrayList();
foreach (ShapeTreeNode node in shapeTreeView.Nodes)
{
if (selected.Contains(node.shape)) // root
newSelection.Add(node);
foreach (ShapeTreeNode subNode in shapeTreeView.GetChildNodes(node))
{
if (selected.Contains(subNode.shape)) // all children
newSelection.Add(subNode);
}
}
shapeTreeView.SelectedNodes = newSelection;
}
示例3: CreateImage
//.........这里部分代码省略.........
switch (imageFormat) {
case ImageFileFormat.Svg:
throw new NotImplementedException();
case ImageFileFormat.Emf:
case ImageFileFormat.EmfPlus:
// Create MetaFile and graphics context
IntPtr hdc = infoGraphics.GetHdc();
try {
Rectangle bounds = Rectangle.Empty;
bounds.Size = imageBounds.Size;
result = new Metafile(hdc, bounds, MetafileFrameUnit.Pixel,
(imageFormat == ImageFileFormat.Emf) ? EmfType.EmfOnly : EmfType.EmfPlusDual,
Name);
} finally {
infoGraphics.ReleaseHdc(hdc);
}
break;
case ImageFileFormat.Bmp:
case ImageFileFormat.Gif:
case ImageFileFormat.Jpeg:
case ImageFileFormat.Png:
case ImageFileFormat.Tiff:
int imgWidth = imageBounds.Width;
int imgHeight = imageBounds.Height;
if (dpi > 0 && dpi != infoGraphics.DpiX || dpi != infoGraphics.DpiY) {
scaleX = dpi / infoGraphics.DpiX;
scaleY = dpi / infoGraphics.DpiY;
imgWidth = (int)Math.Round(scaleX * imageBounds.Width);
imgHeight = (int)Math.Round(scaleY * imageBounds.Height);
}
result = new Bitmap(Math.Max(1, imgWidth), Math.Max(1, imgHeight));
((Bitmap)result).SetResolution(dpi, dpi);
break;
default:
throw new NShapeUnsupportedValueException(typeof(ImageFileFormat), imageFormat);
}
// Draw diagram
using (Graphics gfx = Graphics.FromImage(result)) {
GdiHelpers.ApplyGraphicsSettings(gfx, RenderingQuality.MaximumQuality);
// Fill background with background color
if (backgroundColor.A < 255) {
if (imageFormat == ImageFileFormat.Bmp || imageFormat == ImageFileFormat.Jpeg) {
// For image formats that do not support transparency, fill background with the RGB part of
// the given backgropund color
gfx.Clear(Color.FromArgb(255, backgroundColor));
} else if (backgroundColor.A > 0) {
// Skip filling background for meta files if transparency is 100%:
// Filling Background with Color.Transparent causes graphical glitches with many applications
gfx.Clear(backgroundColor);
}
} else {
// Graphics.Clear() does not work as expected for classic EMF (fills only the top left pixel
// instead of the whole graphics context).
if (imageFormat == ImageFileFormat.Emf) {
using (SolidBrush brush = new SolidBrush(backgroundColor))
gfx.FillRectangle(brush, gfx.ClipBounds);
} else gfx.Clear(backgroundColor);
}
// Transform graphics (if necessary)
gfx.TranslateTransform(-imageBounds.X, -imageBounds.Y, MatrixOrder.Prepend);
if (scaleX != 1 || scaleY != 1) gfx.ScaleTransform(scaleX, scaleY, MatrixOrder.Append);
// Draw diagram background
if (withBackground) DrawBackground(gfx, imageBounds);
// Draw diagram shapes
if (shapes == null) {
foreach (Shape shape in diagramShapes.BottomUp) shape.Draw(gfx);
} else {
// Add shapes to ShapeCollection (in order to maintain zOrder while drawing)
int cnt = (shapes is ICollection) ? ((ICollection)shapes).Count : -1;
ShapeCollection shapeCollection = new ShapeCollection(cnt);
foreach (Shape s in shapes) {
// Sort out duplicate references to shapes (as they can occur in the result of Diagram.FindShapes())
if (shapeCollection.Contains(s)) continue;
shapeCollection.Add(s, s.ZOrder);
}
// Draw shapes
foreach (Shape shape in shapeCollection.BottomUp)
shape.Draw(gfx);
shapeCollection.Clear();
}
// Reset transformation
gfx.ResetTransform();
}
// Restore original graphics settings
HighQualityRendering = originalQualitySetting;
UpdateBrushes();
return result;
} finally {
if (disposeInfoGfx)
GdiHelpers.DisposeObject(ref infoGraphics);
}
}