Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Thu May 10, 2018 9:39 am

Greetings!

I have to create rectangle using C#, can anyone help me with this this?

Code for currently rectangle:
Code: Select all
 public static ChartDataLabel Add(this ChartDataLabelCollection dataLabels, int paragraphs)
        {
            var cd = dataLabels.Add();

            cd.LabelValueVisible = true;
            cd.TextFrame.Paragraphs.Clear();
            for (int i = 0; i < paragraphs; i++)
            {
                cd.TextFrame.Paragraphs.Append(CreateParagraph());
            }

            return cd;
        }

        public static ChartDataLabel Add(this ChartDataLabelCollection dataLabels, string text)
        {
            var cd = dataLabels.Add(1);
            cd.TextFrame.Paragraphs[0].Text = text;

            return cd;
        }

        public static TextParagraph CreateParagraph()
        {
            var paragraph = new TextParagraph
            {
                Alignment = TextAlignmentType.Left,
                Text = string.Empty
            };
            paragraph.FirstTextRange.Format.FontHeight = 8;
            return paragraph;
        }

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Thu May 10, 2018 10:43 am

Dear rokaf,

Thanks for your inquiry.
According to your picture, I guess below two requirements are what you want.
1. Change the color of shape line to black, if so, please refer to following code.
Code: Select all
            var cd = dataLabels.Add();           
            cd.LabelValueVisible = true;
            //change the line color
            cd.Line.FillFormat.FillType = FillFormatType.Solid;
            cd.Line.FillFormat.SolidFillColor.Color = Color.Black;
           //your code...


2. Do you want to change the data label shape as below ?
Image 1.png

You could provide us with the expected MS PPT file for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 11, 2018 8:34 am

Yes, I need rectangle with rounded corners

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Fri May 11, 2018 9:06 am

Dear rokaf,

Thanks for your response.
Sorry that Spire.Presentation doesn't support that feature at present. We will consider adding it in our future upgrade. We will keep you informed once there is any update.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 11, 2018 9:20 am

Okay, thank you.
How can I add transparency to my rectangle?

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Fri May 11, 2018 10:16 am

Dear rokaf,

Thanks for your information again.
There is no direct way to set the transparency at present, yet there is a workaround that is using alpha when filling the color. Sample code for your reference:
Code: Select all
            cd.Fill.FillType = FillFormatType.Solid;
            cd.Fill.SolidColor.Color = Color.FromArgb(0x60,Color.Red);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri May 11, 2018 10:33 am

Thanks a lot for your replies!

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Fri May 11, 2018 10:55 am

I have one more question: how can I add outline shadow to my rectangle?

Here is how my code looks like:

Code: Select all
        public static ChartDataLabel Add(this ChartDataLabelCollection dataLabels, int paragraphs)
        {
            var cd = dataLabels.Add();

            cd.LabelValueVisible = true;
            cd.TextFrame.Paragraphs.Clear();

            cd.Fill.FillType = FillFormatType.Solid;
            cd.Fill.SolidColor.Color = Color.FromArgb(0x99, Color.White);
           

            cd.Line.FillFormat.FillType = FillFormatType.Solid;
            cd.Line.FillFormat.SolidFillColor.Color = Color.Black;
            for (int i = 0; i < paragraphs; i++)
            {
                cd.TextFrame.Paragraphs.Append(CreateParagraph());
            }

            return cd;
        }

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Mon May 14, 2018 9:39 am

So can you help me with shadow creating for my rectangle?

Betsy.jiang wrote:Dear rokaf,

Thanks for your information again.
There is no direct way to set the transparency at present, yet there is a workaround that is using alpha when filling the color. Sample code for your reference:
Code: Select all
            cd.Fill.FillType = FillFormatType.Solid;
            cd.Fill.SolidColor.Color = Color.FromArgb(0x60,Color.Red);


Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Mon May 14, 2018 9:46 am

Dear rokaf,

Thanks for your inquiry.
Sorry that Spire.Presentation doesn't support that feature at present. We will consider adding it in our future upgrade. Once there's any progress, I will let you know.

Sincerely,
Wade
E-iceblue support team
User avatar

Wade.shao
 
Posts: 32
Joined: Thu Mar 22, 2018 8:23 am

Mon May 14, 2018 10:18 am

Can I create it if I'll use the following algorithm?

Code: Select all
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 100, 100, 50));

shape.ShapeStyle.LineColor.Color = Color.Red;

//Effect
PresetShadow shadow = new PresetShadow();
shadow.Preset = PresetShadowValue.FrontRightPerspective;
shadow.Distance = 10.0;
shadow.Direction = 225.0f;
shape.EffectDag.PresetShadowEffect = shadow;


Can I merge it with my code structure?

Code: Select all
  public static ChartDataLabel Add(this ChartDataLabelCollection dataLabels, int paragraphs)
        {
            var cd = dataLabels.Add();

            cd.LabelValueVisible = true;
            cd.TextFrame.Paragraphs.Clear();

           
            cd.Fill.FillType = FillFormatType.Solid;
            cd.Fill.SolidColor.Color = Color.FromArgb(0x99, Color.WhiteSmoke);
     

            cd.Line.FillFormat.FillType = FillFormatType.Solid;
            cd.Line.FillFormat.SolidFillColor.Color = Color.Black;


            cd.TextFrame.Paragraphs.Append(CreateHeader());

            for (int i = 1; i < paragraphs; i++)
            {
                cd.TextFrame.Paragraphs.Append(CreateParagraph());
            }

            return cd;
        }



Wade.shao wrote:Dear rokaf,

Thanks for your inquiry.
Sorry that Spire.Presentation doesn't support that feature at present. We will consider adding it in our future upgrade. Once there's any progress, I will let you know.

Sincerely,
Wade
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Tue May 15, 2018 6:28 am

Dear rokaf,

Thanks for your inquiry.
After an in-depth investigation, we found a way to set the shadow of the data lable.
Please refer to the below code.
Code: Select all
cd.Effect.PresetShadowEffect = new PresetShadow();
cd.Effect.PresetShadowEffect.ColorFormat.Color = Color.Red;           
cd.Effect.PresetShadowEffect.Distance = 10.0f;
cd.Effect.PresetShadowEffect.Direction = 225.0f;


Sincerely,
Wade
E-iceblue support team
User avatar

Wade.shao
 
Posts: 32
Joined: Thu Mar 22, 2018 8:23 am

Thu May 17, 2018 1:18 pm

Thank you!
But I still didn't get how to set shadow size, can you help me?
I need to create this shadow using code(check shadow.png).
For now I've successfully created shadow with needed blur and transparency:
Code: Select all
            cd.Effect.OuterShadowEffect = new OuterShadowEffect();
            cd.Effect.OuterShadowEffect.ColorFormat.Color = Color.FromArgb(99,154,154,154);
            cd.Effect.OuterShadowEffect.BlurRadius = 5;



Wade.shao wrote:Dear rokaf,

Thanks for your inquiry.
After an in-depth investigation, we found a way to set the shadow of the data lable.
Please refer to the below code.
Code: Select all
cd.Effect.PresetShadowEffect = new PresetShadow();
cd.Effect.PresetShadowEffect.ColorFormat.Color = Color.Red;           
cd.Effect.PresetShadowEffect.Distance = 10.0f;
cd.Effect.PresetShadowEffect.Direction = 225.0f;


Sincerely,
Wade
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Fri May 18, 2018 3:30 am

Dear rokaf,

Thanks for your inquiry.
Please refer to the below code to set the size of shadow.
Code: Select all
cd.Effect.OuterShadowEffect.HorizontalScalingFactor = 102f;
cd.Effect.OuterShadowEffect.VerticalScalingFactor = 102f;


Sincerely,
Wade
E-iceblue support team
User avatar

Wade.shao
 
Posts: 32
Joined: Thu Mar 22, 2018 8:23 am

Fri May 18, 2018 9:40 am

Thank you!

How can I create point like this?(point jpg)

And maybe there are any extra ways to make datalabel look like rectangle with rounded corners? For example using picture or something? (shape.jpg)


Wade.shao wrote:Dear rokaf,

Thanks for your inquiry.
Please refer to the below code to set the size of shadow.
Code: Select all
cd.Effect.OuterShadowEffect.HorizontalScalingFactor = 102f;
cd.Effect.OuterShadowEffect.VerticalScalingFactor = 102f;


Sincerely,
Wade
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Return to Spire.Presentation