简体   繁体   English

DataVisualization.Charting.Chart PostPaint事件过早触发

[英]DataVisualization.Charting.Chart PostPaint Event Firing Prematurely

I have a complex chart that I'm drawing and the PostPaint event for System.Windows.Forms.DataVisualization.Charting.Chart seems to be firing prematurely. 我有一个正在绘制的复杂图表,System.Windows.Forms.DataVisualization.Charting.Chart的PostPaint事件似乎过早触发。 There is no chart on the screen yet. 屏幕上还没有图表。

Does anyone have a better understanding of the behavior of the PostPaint event with large charts? 有人对大型图表对PostPaint事件的行为有更好的了解吗? Is there a better event to listen to? 有更好的活动要听吗? Recommended strategies? 推荐策略?

I'm not sure posting code would provide any benefit. 我不确定发布代码会带来任何好处。

ORIGINAL POST: So it turns out the answer to this (for me anyway), is to create another thread (I'm doing it with a Task) off of the event. 原始帖子:事实证明,这个问题的答案(无论如何对我来说)是在事件之外创建另一个线程(我正在使用Task进行此操作)。 This thread's job is to continually compare the region with an empty image and when it is no longer empty, grab the image and save it in the database. 该线程的工作是不断地将区域与空图像进行比较,当该区域不再为空时,抓取图像并将其保存在数据库中。 Because it's a thread, this frees up the chart to eventually render itself. 因为它是线程,所以释放了图表以最终呈现自己。

FINAL POST: In the end, I had to put a lock inside the PostPaint event (it was firing multiple times as TaW indicated it would) and make sure the code inside would only execute a single time (I have a Draw button so these controls get reset every time it's clicked). 最终发布:最后,我必须在PostPaint事件中放置一个锁(它如TaW所示将触发多次),并确保其中的代码仅执行一次(我有一个Draw按钮,因此这些控件每次点击都会重置)。 Additionally, it was necessary for me to create a task to actually do the work of capturing the image and storing it in the database. 另外,对于我来说,有必要创建一个任务来实际完成捕获图像并将其存储在数据库中的工作。 If I didn't do this, I would get a blank image every time. 如果不这样做,每次都会得到一张空白图像。 I did not actually have to check point count or sample the image to see if it was blank. 我实际上不必检查点数或对图像进行采样以查看其是否为空白。

Locking down the event and creating the task inside the event is what made the difference. 锁定事件并在事件内部创建任务是与众不同的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不写入文件的情况下将DataVisualization.Charting.Chart的图像获取到iTextSharp.text.Image? - How may I get the image of DataVisualization.Charting.Chart to iTextSharp.text.Image without writing to a file? 是否可以以十六进制显示DataVisualization.Charting.Chart的x轴值? - Is it possible to display the x-axis values of the DataVisualization.Charting.Chart in hexadecimal? C#添加图表错误DataVisualization.Charting-Visual Studio - C# add chart error DataVisualization.Charting - Visual Studio 调整图表大小后如何为datavisualization.charting调整轴刻度? - How to adjust axis scales for datavisualization.charting after resizing a chart? 如何使用Web.UI.DataVisualization.Charting绘制图表? - How to chart using Web.UI.DataVisualization.Charting? 设置chart.ChartAreas [0] .Axes [0] .Maximum为“ Auto”时,是否存在System.Windows.Forms.DataVisualization.Charting.Chart的错误? - Is there a bug of System.Windows.Forms.DataVisualization.Charting.Chart, when setting chart.ChartAreas[0].Axes[0].Maximum as “Auto”? 有没有一种方法可以使用System.Web.UI.DataVisualization.Charting旋转烛台图表以水平显示,而不是垂直显示? - Is there a way using System.Web.UI.DataVisualization.Charting to rotate a Candlestick chart to display horizontally instead of vertically? 来自C#System.Web.UI.DataVisualization.Charting.Chart帮助程序的图像映射 - Image map from C# System.Web.UI.DataVisualization.Charting.Chart helper 用工作日标记 System.Windows.Forms.DataVisualization.Charting 图表中的 X 轴 - label the X axis in a System.Windows.Forms.DataVisualization.Charting chart with weekdays 使用System.Web.UI.DataVisualization.Charting命名空间更改饼图上的标签颜色 - Changing the label color on a Pie Chart using System.Web.UI.DataVisualization.Charting namespace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM