我正在创建不在我的Windows窗体中的后台工作程序,而是在实现所有处理的类文件(BusinessLogic)中.从主窗体我首先调用初始化BGW的BL方法.然后我调用BL的方法来启动BGW.
这是我的实现更多背景:). 如何在类文件中使用BackGroundWorker?
DoWork事件运行正常,但它不会调用RunWorkerCompleted.
一些谷歌搜索,我发现了这个链接.我觉得我的问题与这些家伙一样. http://www.eggheadcafe.com/software/aspnet/29191764/backgroundworker-does-not-fire-the-runworkercompleted-event.aspx
我对此问题的任何意见表示感谢.提前致谢.
主要代码:
private void frmMain_Load(object sender, EventArgs e)
{
Hide();
BusinessLogic.BGWInitialize();
BusinessLogic.StartBackgroundWorker();
while (!BusinessLogic.firstCycleDone)
{
Thread.Sleep(100);
}
Show();
}
Run Code Online (Sandbox Code Playgroud)
BusinessLogic中的代码:
public static void BGWInitialize()
{
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
bgWorker.ProgressChanged += new ProgressChangedEventHandler(bgWorker_ProgressChanged);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
bgWorker.WorkerReportsProgress = true;
}
public static void StartBackgroundWorker()
{
bgWorker.RunWorkerAsync();
}
private static void bgWorker_RunWorkerCompleted(
object sender, RunWorkerCompletedEventArgs e)
{
firstCycleDone = true;
}
Run Code Online (Sandbox Code Playgroud) 我正试图在Datagridview中删除整行.这就是我目前正在做的事情:
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Font = new Font(dgview.Font.OriginalFontName, 7, FontStyle.Strikeout);
dgview.Rows[dgview.RowCount - 1].DefaultCellStyle.ApplyStyle(style);
Run Code Online (Sandbox Code Playgroud)
这种方法只会触发其中包含任何文本的单元格.我想要的是连续三振,即一条线穿过该行.
我很感激你的帮助.提前致谢.
编辑:在另一个问题中看到这个可能的答案 - "如果所有的行都是相同的高度,最简单的方法就是将背景图像应用到中心,只有一条穿过中心的大线,相同的颜色作为测试."
如果其他一切都失败了,那我就去做吧.但有没有更简单的东西?
EDIT2:通过一些调整实现了Mark的建议.cellbound属性对我来说不正常,所以我决定使用rowindex和rowheight来获取位置.
private void dgv_CellPainting(object sender,DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex != -1)
{
if (dgv.Rows[e.RowIndex].Cells["Strikeout"].Value.ToString() == "Y")
{
e.Paint(e.CellBounds, e.PaintParts);
e.Graphics.DrawLine(new Pen(Color.Red, 2), new Point(e.CellBounds.Left, gridHeaderHeight+ e.RowIndex * rowHeight+ rowHeight/2),
new Point(e.CellBounds.Right, gridHeaderHeight+ e.RowIndex * rowHeight+ rowHeight/2));
e.Handled = true;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的datagridview的一些列是链接列.根据提取的数据,我想将某些单元格的LinkBehavior设置为NeverUnderLine.麻烦的是,我只能通过DataGridViewCell而不是DataGridViewLinkCell进行迭代.DataGridViewCell没有LinkBehavior属性(这是非常合理的).
那么我究竟如何设置单元格的LinkBehavior属性呢?
foreach (DataGridViewCell dcell in dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells)
{
if (dcell.Value.ToString() == "Error")
{
dcell.Style.ApplyStyle(style);
//dcell.LinkBehavior = LinkBehavior.NeverUnderline;
}
}
Run Code Online (Sandbox Code Playgroud)