![](/img/trans.png)
[英]How to set a transparent winform, into a panel transparent panel, to show as background what's behind?
[英]How to show Piechart in Panel in Winform
我在winform中创建Piechart。我的图表运行正常。我唯一想添加的就是在面板中显示Piechart,但我无法做到。
这是饼图代码。
public void DrawPieChartOnForm()
{
//Take Total Five Values & Draw Chart Of These Values.
int[] myPiePercent = { 10, 20, 25, 5, 40 };
//Take Colors To Display Pie In That Colors Of Taken Five Values.
Color[] myPieColors = { Color.Red, Color.Black, Color.Blue, Color.Green, Color.Maroon };
using (Graphics myPieGraphic = this.CreateGraphics())
{
//Give Location Which Will Display Chart At That Location.
Point myPieLocation = new Point(10, 400);
//Set Here Size Of The Chart…
Size myPieSize = new Size(500, 500);
//Call Function Which Will Draw Pie of Values.
DrawPieChart(myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize);
}
}
请帮助我..预先感谢..
看看Hiren Khirsaria的这篇文章:
hirenkhirsaria.blogspot.com/2012/06/dynamically-creating-piebar-chart-in-c.html
我认为您需要做的是创建一个处理饼图的控件,然后将其添加到面板上。 就像是:
panel.Controls.Add(pieChart);
您需要了解WinForms Graphics的基础。
把你的饼到Panel
,而不是Form
,因为你现在拥有它,你只需要改变this.CreateGraphics()
来panel.CreateGraphics()
但这不好! 当您最小化窗体时,您的饼消失了,对吗?
因此, 所有绘图都必须使用其e.Graphics
对象从Paint
事件中发生/触发! 只有这样,图形才能保留各种外部事件。
您可以在类级别存储数据并调用DrawPieChart
在Paint
中的事件Panel
,在移交e.Graphics
代替myPieGraphic
..使用panel.Invalidate()
来触发,只要你有改变的值漆事件..:
//Five Values at class level
int[] myPiePercent = { 10, 20, 25, 5, 40 };
//Take Colors To Display Pie In That Colors Of Taken Five Values.
Color[] myPieColors = { Color.Red, Color.Black, Color.Blue, Color.Green, Color.Maroon };
public void DrawPieChart()
{
// maybe change the values here..
myPiePercent = { 11, 22, 23, 15, 29 };
// then let Paint call the draw routine:
panel1.Invalidate();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
//Give Location Which Will Display Chart At That Location.
Point myPieLocation = new Point(10, 400);
//Set Size Of The Chart
Size myPieSize = new Size(500, 500);
//Call Function Which Will Draw Pie of Values.
DrawPieChart(myPiePercent, myPieColors, e.Graphics, myPieLocation, myPieSize);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.