private static bool Sync(Shape formatShape, Shape newShape) { try { PictureEffects dest = newShape.Fill.PictureEffects; PictureEffects source = formatShape.Fill.PictureEffects; // clear current effects for (int i = 1; i <= dest.Count; i++) { dest.Delete(i); } // add new effects for (int i = 1; i <= source.Count; i++) { PictureEffect effect = source[i]; dest.Insert(effect.Type, i); } } catch (Exception) { return(false); } return(true); }
public static void ClearArtisticEffects(Shape shape) { try { PictureEffects dest = shape.Fill.PictureEffects; for (int i = 1; i <= dest.Count; i++) { dest.Delete(i); } } catch (Exception) { // ignore the exception, this shape is not compatible with ArtisticEffects. } }
public static void ApplyArtisticEffects(Shape shape, List<MsoPictureEffectType> effectTypes) { // add new effects try { PictureEffects dest = shape.Fill.PictureEffects; for (int i = 0; i < effectTypes.Count; i++) { int index = i + 1; dest.Insert(effectTypes[i], index); } } catch (Exception) { // ignore the exception, this shape is not compatible with ArtisticEffects. } }
public static List<MsoPictureEffectType> GetArtisticEffects(Shape shape) { List<MsoPictureEffectType> artisticEffects = new List<MsoPictureEffectType>(); try { PictureEffects effects = shape.Fill.PictureEffects; for (int i = 1; i <= effects.Count; i++) { PictureEffect effect = effects[i]; artisticEffects.Add(effect.Type); } } catch (Exception) { // do nothing, shape does not support picture effect } return artisticEffects; }
/** * Replace all existing artistic effects with those from the source shape */ private static bool Sync(Shape formatShape, Shape newShape) { try { // access PictureEffects, just to make sure shapes are compatible with ArtisticEffect // will throw an exception otherwise PictureEffects dest = newShape.Fill.PictureEffects; PictureEffects source = formatShape.Fill.PictureEffects; List<MsoPictureEffectType> effectTypes = GetArtisticEffects(formatShape); // clear the existing artistic effects, // might experience unexpected behavior if they are left in the shape ClearArtisticEffects(newShape); ApplyArtisticEffects(newShape, effectTypes); } catch (Exception) { return false; } return true; }