none
Creating a shape fill with color in interop Power Point Object Library RRS feed

  • Question

  • Hi!

     

    I am using Microsoft Power Point Object Library to draw a shape that will fill in color. Does anyone know how to do that? I am able to draw a shape with this code

     

    objAllShape = objSlide.Shapes.AddShape(MsoAutoShapeType.msoShapeOval, 150, 300, 100, 50);

     

    but when i wish to fill in color with the code below, it seem cannot work.

    objAllShape.Fill.BackColor.RGB = RGB(255, 255, 255)

    but when i change to this code, it works but even though I change the value light blue will always appear as the shape background color.

     

    objAllShape.Fill.BackColor.RGB = 0255127;


    Thanks for the help.

    Wednesday, September 5, 2007 3:11 PM

Answers

  • Hi Yuen,

     

    You should use Fill.ForeColor instead of Fill.BackColor. Codes like these:

    PowerPoint.Shape myShape = app.ActivePresentation.Slides[1].Shapes.AddShape(

    Microsoft.Office.Core.MsoAutoShapeType.msoShapeOval,

                    150, 300, 100, 50);

     

                myShape.Fill.ForeColor.RGB = System.Drawing.Color.Blue.ToArgb();

    This code will fill the shape with Red color, because .Net treat color as RGB, while Com Interop treats color as BGR. So .Net Color Blue will be recognized as Red in PowerPoint. (Note ForeColor.RGB is a int value, you should use ToArgb() to translate the Color to int, then assign it)

     

    Thanks

    Ji

     

    Monday, September 10, 2007 3:26 AM
    Moderator

All replies

  • Hi Yuen,

     

    You should use Fill.ForeColor instead of Fill.BackColor. Codes like these:

    PowerPoint.Shape myShape = app.ActivePresentation.Slides[1].Shapes.AddShape(

    Microsoft.Office.Core.MsoAutoShapeType.msoShapeOval,

                    150, 300, 100, 50);

     

                myShape.Fill.ForeColor.RGB = System.Drawing.Color.Blue.ToArgb();

    This code will fill the shape with Red color, because .Net treat color as RGB, while Com Interop treats color as BGR. So .Net Color Blue will be recognized as Red in PowerPoint. (Note ForeColor.RGB is a int value, you should use ToArgb() to translate the Color to int, then assign it)

     

    Thanks

    Ji

     

    Monday, September 10, 2007 3:26 AM
    Moderator
  • I used the code:
    table.Table.Cell(row, 1).Shape.Fill.ForeColor.RGB = System.Drawing.Color.Blue.ToArgb();

    and i got runtime exception
    "The value is not in expected range."
    Monday, March 16, 2009 8:57 AM
  • Thanks so much for your answer!  I have been messing with BackColor for 3 days unable to get it to stick when what I really needed to use was ForeColor!

     

    Thanks again!

    Mike


    Mike
    Monday, April 12, 2010 8:28 PM