问题描述
在一个主窗体上有左边是treeview控件,右边是panel控件,我的用意是当点击treeview控件中的节点1就是在panel内显示窗体1,当我点击treeview控件中的节点2的时候,在panel控件内显示窗体2并且关闭窗体1,如何做到,谢谢!
解决方案
解决方案二:
窗体能放入PANEL中吗
解决方案三:
该回复于2012-04-08 14:40:04被版主删除
解决方案四:
引用1楼的回复:
窗体能放入PANEL中吗
当然可以。你把窗体的添加到panel中就行frmCheckProjectTypecpt=newfrmCheckProjectType(this);//你要添加的窗体cpt.TopLevel=false;cpt.Parent=this.panel1;//设置parent为panel1cpt.WindowState=FormWindowState.Maximized;cpt.Dock=DockStyle.Fill;cpt.FormBorderStyle=FormBorderStyle.None;cpt.Show();
解决方案五:
treeview不大熟悉,但是listbox的话很容易的~比如你有4个form,listbox1里有4个选项,form里有1个listbox,1个panel,你可以参考以下代码PrivateSubListBox1_SelectedIndexChanged(senderAsSystem.Object,eAsSystem.EventArgs)HandlesListBox1.SelectedIndexChangedPanel1.Controls.Clear()'(创意点,想象form是一个control)这样可以关闭掉所有的窗口先SelectCaseListBox1.SelectedIndexCase0'显示form1DimformAsNewForm1form.TopLevel=FalsePanel1.Controls.Add(form)form.Show()Case1'显示form2DimformAsNewForm2form.TopLevel=FalsePanel1.Controls.Add(form)form.Show()Case2'显示form3'代码就自己打咯Case3'显示form4'代码就自己打咯EndSelectEndSub
在此谢谢Chinajiyong的指导,让我知道原来panel可以加入form的
解决方案六:
引用4楼的回复:
treeview不大熟悉,但是listbox的话很容易的~比如你有4个form,listbox1里有4个选项,form里有1个listbox,1个panel,你可以参考以下代码VB.NETcodePrivateSubListBox1_SelectedIndexChanged(senderAsSystem.Object,eAsSystem.EventArgs)……
不只是panel,GroupBox这些都可以
解决方案七:
ImportsSystem.Windows.FormsImportsSystem.Runtime.InteropServices'使用到DllImport需要这个命名空间ImportsSystem.Reflection'使用到Assembly需要用到这个命名空间ImportsSystem.Reflection.Emit'使用到ILGenerator需要用到这个命名空间PublicClassWelcomePrivateSubWelcome_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.LoadDimMenuManageAsNewMenuManageMenuManage.TopLevel=FalseMe.MainPanel.Controls.Add(MenuManage)MenuManage.Dock=DockStyle.FillMenuManage.Show()ds=Service.MenuShow()buttonx()EndSubPrivatedsAsNewDataSetPrivateSubbuttonx()'DimsqlAsString="select*fromMenuwhereRoot=0orderbyiddesc"'DimcmdAsNewSqlClient.SqlDataAdapter(sql,Conn)'DimdsAsNewData.DataTable'cmd.Fill(ds)DimjAsButtonForEachiAsDataRowInds.Tables("Menu").Select("WS_MenuClass=0")j=NewButton'Withds.Rows(i)j.Name=i("id")j.Text=i("WS_MenuName")j.Tag=i("id")j.Dock=DockStyle.Topj.TabIndex=i("id")j.Height=40j.Font=NewSystem.Drawing.Font("宋体",11.0!,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,CType(134,Byte))j.BackgroundImage=System.Drawing.Bitmap.FromFile("di.jpg")j.FlatStyle=FlatStyle.Flatj.FlatAppearance.BorderSize=0j.ForeColor=Color.Whitej.Cursor=System.Windows.Forms.Cursors.HandMe.LeftPanel.Controls.Add(j)'EndWithAddHandlerj.Click,AddressOfxAddHandlerj.MouseMove,AddressOfButtonMouseMoveAddHandlerj.MouseLeave,AddressOfButtonMouseLeaveNext'ds.Reset()EndSubPrivateSubx(ByValsenderAsObject,ByValeAsSystem.EventArgs)DimClickBtnAsButton=CType(sender,Button)DimTabIndexAsInteger=ClickBtn.TabIndexForEachbtnAsControlInLeftPanel.Controls'[criteria]sortbybtn.tabindexdescIfbtn.GetType.ToString.Equals("System.Windows.Forms.Button")ThenIfbtn.TabIndex<>TabIndexThenbtn.Dock=DockStyle.BottomIfbtn.TabIndex=TabIndexThenbtn.Dock=DockStyle.TopEndIfNextbtnListView1.Items.Clear()Dimmyvalues(0)AsStringDimlistitemAsListViewItemForEachiAsDataRowInds.Tables("Menu").Select("WS_MenuClass="&CInt(sender.Tag))myvalues(0)=i("WS_MenuName")listitem=NewListViewItem(myvalues)listitem.Tag=i("WS_FormName")&"|"&i("WS_NameSpace")listitem.ImageIndex=i("id")listitem.Font=NewSystem.Drawing.Font("宋体",9.0!,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,CType(134,Byte))'Ifflag(sysflag,dx.Rows(i).Item("id"))=TrueThenListView1.Items.Add(listitem)'EndIfNext'dx.Reset()AddHandlerListView1.ItemActivate,AddressOfopenformEndSubPublicFunctionOpenOnce(ByValmyformAsForm)AsBooleanDimformAsFormForEachformInMe.MdiChildrenIfform.Text=myform.TextThenform.Activate()ReturnTrueEndIfNextReturnFalseEndFunctionPrivateSubopenform(ByValsenderAsObject,ByValeAsEventArgs)TryMe.MainPanel.Controls.Clear()DimnamespacestrAsObject=CType(sender,ListView).FocusedItem.Tag.ToStringnamespacestr=Split(namespacestr,"|")DimfrmAsNewFormIfnamespacestr(1)<>Application.ProductNameThenDimAAsAssembly=Assembly.LoadFrom(namespacestr(1)&".dll")'加载程序集DimTAsType=A.GetType(namespacestr(1)&"."&namespacestr(0))frm=Activator.CreateInstance(T)frm.Text=namespacestr(0).ToStringElseDimasmAsAssembly=System.Reflection.Assembly.GetExecutingAssembly()frm=CType(asm.CreateInstance(namespacestr(1)&"."&namespacestr(0)),Form)frm.Text=sender.focuseditem.text.ToStringEndIffrm.TopLevel=FalseMe.MainPanel.Controls.Add(frm)frm.FormBorderStyle=Windows.Forms.FormBorderStyle.Nonefrm.Dock=DockStyle.Fillfrm.Show()CatchexAsExceptionMsgBox("窗体不存在!"+ex.Message.ToString,MsgBoxStyle.Information,"系统提示")ExitSubEndTryEndSubPrivateSubButtonMouseMove(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)DimClickBtnAsButton=CType(sender,Button)ClickBtn.BackgroundImage=System.Drawing.Bitmap.FromFile("di2.jpg")EndSubPrivateSubButtonMouseLeave(ByValsenderAsObject,ByValeAsSystem.EventArgs)DimClickBtnAsButton=CType(sender,Button)ClickBtn.BackgroundImage=System.Drawing.Bitmap.FromFile("di.jpg")EndSubEndClass你可以试试这样的
解决方案八:
你不是要获得活动窗体么?怎么提问和题目不一样啊!
解决方案九:
你不是要获得活动窗体么?怎么提问和题目不一样啊!