ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  c# Background TransparentColor
Posted by brian on Apr-05-2022 11:02
Attachments:
Transparent background doesn't work, please tell me how to fix it
source code

        public void createChart(WinChartViewer viewer, double value) {
//          AngularMeter m = new AngularMeter(410, 310, Chart.Transparent);
            AngularMeter m = new AngularMeter(410, 310, 0xffffff);
            m.setTransparentColor(0xffffff);
            // m.setTransparentColor(1);
            // m.setBackground(Chart.Transparent, Chart.Transparent);
            m.setColor(Chart.TextColor, 0xffffff);
            m.setColor(Chart.LineColor, 0xffffff);
            m.setMeter(200, 150, 111, -140, 140);
            m.addRing(0, 123, 0x000000);
            m.setSize(410, 310);
            double[] ringGradient = {1, 0x7f7f7f, 0.5, 0xd6d6d6, 0, 0xffffff, -0.5, 0xd6d6d6, -1, 0x7f7f7f};
            m.addRing(116, 122, m.relativeLinearGradient(ringGradient, 45, 122));
            m.setScale(-100, 300, 30, 5, 1);
            m.setLabelStyle("Arial", 15);
            m.setTickLength(-12, -9, -6);
            m.setLineWidth(0, 2, 1, 1);
            double[] smoothColorScale = {-100, 0x0000ff, 0, 0x0088ff, 100, 0x00ff00, 200, 0xdddd00, 300, 0xff0000};
            m.addColorScale(smoothColorScale, 111, 0, 111, -12);
            m.addGlare(116, -190, 45);
            m.addText(200, 190, "test", "Arial", 15, Chart.TextColor, Chart.Center);
            TextBox t = m.addText(205, 250, m.formatValue(value, "<*block,width=80,halign=center*>{value|1}%"), "Arial", 14, 0x000000,  Chart.BottomCenter);
            t.setBackground(0xFFA500);
            t.setRoundedCorners(5);
            m.addPointer2(value, 0xff0000);
            viewer.Chart = m;
        }
test.png

  Re: c# Background TransparentColor
Posted by Peter Kwan on Apr-05-2022 12:40
Hi Brian,

From your code, it seems you are using Windows Forms. Note that in Windows Forms, if the control has transparency, Windows Forms will automatically fill the transparent part with the background of the Form. For example, if the Form background is red, then the transparent part will be red. If the Form background is an image, then the transparent part will display that image. This is the same for all Windows Forms control.

For your case, if the Form background white, then transparency is working normally, as the transparent part did show white. You can try to set the Form background to another color. If the transparent part shows that color, then it is working normally.

Best Regards
Peter Kwan

  Re: c# Background TransparentColor
Posted by Peter Kwan on Apr-05-2022 12:50
HI Brian,

In brief, it is not suggested you use overlapping controls in Windows Forms.

Regards
Peter Kwan

  Re: c# Background TransparentColor
Posted by brian on Apr-05-2022 13:17
Attachments:
I'm trying to show the image of the nested control transparently, but I can't.

//            AngularMeter m = new AngularMeter(410, 310);                    // background color <== white
            AngularMeter m = new AngularMeter(410, 310, Chart.Transparent);   // <== X
//            m.setTransparentColor(Chart.Transparent);                      // <== X
//            m.setBackground(Chart.Transparent, Chart.Transparent);           // <== X
test.png

  Re: c# Background TransparentColor
Posted by Peter Kwan on Apr-05-2022 17:49
Hi Brian,

From your screenshot, it is already transparent. Note that like many things in programming, the word "Transparent" must be understood in the context of programming language and GUI framework (which is Windows Forms in your case).

You can try to add a normal Label control, and sets is background to transparent, and you you can see what it mean. In Windows Forms, Transparent means to fill with the Form background, not to see the underlying control. The Windows Forms GUI framework does not permit the underlying control to be visible.

If you want the underlying control to be visible, you would need to choose another framework that supports it (eg. WPF).

Since Windows Forms does not permit underlying control to be visible, if you want to see both the circular meter and the pie chart, the only method in Windows Forms is to put them into the same control. You can use a MultiChart to contain both charts, and put the MultiChart into the WinChartViewer control. In this way, there is only one control and so will not be subjected to Windows Forms limitations.

Regards
Peter Kwan