我想在这个事件中采用线程调用TypeShowFrom方法,这个方法里面涉及到UI控件问题,我该怎么做
//在更改选中的树节点发生的事件
[C#] 纯文本查看 复制代码 private void tvMainMenu_AfterSelect(object sender, TreeViewEventArgs e)
{
try
{
//Thread td = new Thread(new ThreadStart(ThreadFunShow));
//td.Start(e);
////BeginInvoke(new Action(() =>
////{
//// TypeShowFrom(e);
////}));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
调用下面的方法
[C#] 纯文本查看 复制代码 /// <summary>
/// show出窗体
/// </summary>
/// <param name="type"></param>
public void TypeShowFrom(TreeViewEventArgs e)
{
Form frm = null;
if (e.Node.Name != "")
{
if (!HasChildrenForm)
{
this.pPrompt.Visible = false;//程序温馨提示容器隐藏
this.pLoading.Visible = true;
this.Refresh();
string type = e.Node.ToolTipText;
LoginInfo.parameter = e.Node.Name;
int n = e.Node.Text.IndexOf('(');
string text = n > 0 ? e.Node.Text.Remove(n) : e.Node.Text;
switch (type)
{
case "answerAndCommentsExamine":
string[] typeName = LoginInfo.parameter.Split('_');
if (typeName[typeName.Length-1].Equals("SINAASK"))
{
PublicData.formType = text.Equals("评论审核") ? "SINAASK_Comment" : "SINAASK_Answer";
}
else
{
PublicData.formType = text.Equals("评论审核") ? "Ordinary_Comment" : "Ordinary_Answer";
}
frm = new frm_CommentAdnAnswerAudit();
frm.MdiParent = this;
frm.Text = text;
frm.Show();
Application.DoEvents();
break;
case "weiBoCollect":
frm = new frm_WeiBoCollect();
frm.MdiParent = this;
frm.Text = text;
frm.Show();
break;
case "commentsSolutions":
frm = new frm_CommentsSolutions();
frm.MdiParent = this;
frm.Text = text;
frm.Show();
Application.DoEvents();
break;
case "questionAnswering":
PublicData.type = text.Equals("官方解答") ? "official" : "common";
frm = new frm_QuestionAnswering();
frm.MdiParent = this;
frm.Text = text;
frm.Show();
Application.DoEvents();
break;
case "questionExamine":
frm = new frm_QuestionAudit();
frm.Text = text;
frm.MdiParent = this;
frm.Show();
Application.DoEvents();
break;
case "askQuestionExamine":
frm = new frm_SinasHelp();
frm.Text = text;
frm.MdiParent = this;
frm.Show();
Application.DoEvents();
break;
default:
break;
}
this.tvMainMenu.SelectedNode = null;
this.pLoading.Visible = false;
frm.FormClosed += frm_FormClosed;
}
}
}
|