FillOverlayEffect.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using GrapeCity.Documents.Word;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This example shows how to add fill overlay effect to shapes in a DOCX.
  15. public class FillOverlayEffect
  16. {
  17. public GcWordDocument CreateDocx()
  18. {
  19. var doc = new GcWordDocument();
  20.  
  21. // Shape fill overlay - direct:
  22. var p = doc.Body.Paragraphs.Add();
  23. var run = p.GetRange().Runs.Add();
  24. var shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star8);
  25. shape.Fill.Type = FillType.Solid;
  26. shape.Fill.SolidFill.RGB = Color.LightBlue;
  27. // Apply solid fill overlay with another color to mix with the main fill:
  28. FillOverlay overlay = shape.Effects.FillOverlay;
  29. overlay.BlendMode = BlendMode.Multiply;
  30. overlay.Fill.Type = FillType.Solid;
  31. overlay.Fill.SolidFill.RGB = Color.Yellow;
  32. p.GetRange().Runs.Add("Shape fill overlay - direct.", doc.Styles[BuiltInStyleId.Strong]);
  33.  
  34. // Shape FillOverlay - style effects, fixed color:
  35. p = doc.Body.Paragraphs.Add();
  36. p.Style.ParagraphFormat.Spacing.SpaceBefore = 30;
  37. run = p.GetRange().Runs.Add();
  38. shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star8);
  39. shape.Fill.Type = FillType.Solid;
  40. shape.Fill.SolidFill.RGB = Color.LightBlue;
  41. // apply solid fill overlay with another color to mix with the main fill
  42. var fmtEffect = doc.Theme.FormatScheme.Effects.Add();
  43. overlay = fmtEffect.FillOverlay;
  44. overlay.BlendMode = BlendMode.Multiply;
  45. overlay.Fill.Type = FillType.Solid;
  46. overlay.Fill.SolidFill.RGB = Color.Yellow;
  47. shape.Style.Effects.ThemeEffects = fmtEffect;
  48. p.GetRange().Runs.Add("Shape FillOverlay - style effects, fixed color.", doc.Styles[BuiltInStyleId.Strong]);
  49.  
  50. // Shape FillOverlay - style effects, fixed and placeholder color usage, pattern color
  51. // (BackColor uses fixed color, ForeColor uses placeholder color):
  52. p = doc.Body.Paragraphs.Add();
  53. p.Style.ParagraphFormat.Spacing.SpaceBefore = 30;
  54. run = p.GetRange().Runs.Add();
  55. shape = run.GetRange().Shapes.Add(100, 100, GeometryType.Star8);
  56. shape.Fill.Type = FillType.Solid;
  57. shape.Fill.SolidFill.RGB = Color.LightBlue;
  58. // Apply pattern fill overlay with another color to mix with the main fill:
  59. fmtEffect = doc.Theme.FormatScheme.Effects.Add();
  60. overlay = fmtEffect.FillOverlay;
  61. overlay.BlendMode = BlendMode.Multiply;
  62. //
  63. var foFill = overlay.Fill;
  64. foFill.Type = FillType.Pattern;
  65. foFill.PatternFill.Type = PatternFillType.DashedHorizontal;
  66. foFill.PatternFill.ForeColor.ThemeColor = ThemeColorId.None;
  67. foFill.PatternFill.BackColor.ThemeColor = ThemeColorId.Accent6;
  68. //
  69. shape.Style.Effects.PlaceholderColor.ThemeColor = ThemeColorId.Accent3;
  70. shape.Style.Effects.PlaceholderColor.Transparency = 0.6f;
  71. shape.Style.Effects.ThemeEffects = fmtEffect;
  72. p.GetRange().Runs.Add("Shape FillOverlay - style effects, fixed and placeholder color usage, pattern color.", doc.Styles[BuiltInStyleId.Strong]);
  73.  
  74. // Done:
  75. return doc;
  76. }
  77. }
  78. }
  79.