110,556
社区成员
发帖
与我相关
我的任务
分享
private BackgroundWorker m_BackgroundWorker;// 界面绘制线程
public MyControl()
{
#region 后台绘制界面线程设置
CheckForIllegalCrossThreadCalls = false;
m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
m_BackgroundWorker.DoWork += new DoWorkEventHandler(StartPaint);
m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(EndPaint);
#endregion
}
#region 控件绘制
bool _isPainting;
private void TimeAxisView_Paint(object sender, PaintEventArgs e)
{
if (_isPainting) return;
if (m_BackgroundWorker.IsBusy)
{
m_BackgroundWorker.CancelAsync();
}
m_BackgroundWorker.RunWorkerAsync(e);
}
//protected override void OnPaint(PaintEventArgs e)//本来用OnPaint结果程序都跑不起来...用Paint事件好歹能跑起来
//{
//}
private void StartPaint(object sender,DoWorkEventArgs de)
{
_isPainting = true;
PaintEventArgs e = de.Argument as PaintEventArgs;
if (e != null)
{
//base.OnPaint(e);
PaintHeader(e.Graphics);
PaintLeft(e.Graphics);
PaintTimeScale(e.Graphics);
_btnAudio.PaintControl(e.Graphics);
}
}
private void EndPaint(object sender, RunWorkerCompletedEventArgs e)
{
_isPainting = false;
}
//头部绘制
private void PaintHeader(Graphics g)
{
if (ViewHeaderBackImage != null)
{
Brush brush = new TextureBrush(ViewHeaderBackImage);
g.FillRectangle(brush, 0, 0, this.Width, ViewHeaderHeight);//这里报错,我尝试过用纯色,并且固定常量绘制都不行
}
}