I prepared the form with using "SplitContainer tool".I added Treeview into left side of that SplitContainer. next i added to that treeview two Node such as hide and show and also i prepared a "child form". I need to do, Chile form SplitContainer load to right side when I click on the Node show and hide child form when click on the hide node.i can show chile form but can not hide it.please help me to do this.below i attached code which i used to "Show"
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
UserControll.UscCreateUser UscPerobjForm = new UserControll.UscCreateUser();
string Tree = (string)e.Node.Tag;
if (Tree == "1")
{
UscPerobjForm.TopLevel = false;
splitContainer1.Panel2.Controls.Add(UscPerobjForm);
UscPerobjForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
UscPerobjForm.Dock = DockStyle.Fill;
UscPerobjForm.Show();
//Show part
}
else if (Tree == "2")
{
// Hide part
}
}
I need to Hide part.
Try using http://dockpanelsuite.com/ where you can have the tree view implement in a Form class docked on Left while the Child Form dock the center.
Related
i am new in c# windows application learning
i have 3 form.
main form, form menu, child form
in main form when i click on button1, form menu is show in 1st panel.
this code in main form.....this work properly for me... if anyone have better then this then suggest me.
private void button1_Click(object sender, EventArgs e)
{
bool IsOpen = false;
foreach (Form frmchild in Application.OpenForms)
{
if (frmchild.Text == "Child Form")
{
IsOpen = true;
frmchild.Close();
break;
}
}
if (IsOpen == false)
{
child form cf = new child form();
cf.Owner = this; //main form is owenr
cf.Show();
cf.Location
= new Point(button1.Left + 37, button1.Height + button1.Top + 4);
}
}
main form have 2 panel, 1st is small and dock in top. 2nd is main panel (dock = fill) where i want to dock all child form.
in form menu i have button and when i click on i want to open child form in main form 2nd panel.
please help me to open child form in main form's panel when i click button in another child form in c# language.
please help me.
i think you have to use USER CONTROL instead of a form. Add a usercontrol at your prject and here is the code :
for (int i = panel2.Controls.Count; i > 0; i--)
{
panel2.Controls[i-1].Dispose();
}
//add user control you want
UserControl1 uc = new UserControl1();
panel2.Controls.Add(uc);
I have created ribbon form (XtraMain)and I set IsMdiContainer Property to true,i also add documentManager controle i set MdiParent to XtraMain I have add this code to open child forms
public void ViewChildForm(XtraForm _form)
{
if (!IsFormActived(_form))
{
_form.MdiParent = this;
_form.Show();
}
}
private bool IsFormActived(XtraForm form)
{
bool IsOpenend = false;
if (MdiChildren.Count() > 0)
{
foreach (var item in MdiChildren)
{
if (form.Name == item.Name)
{
tabbedView1.ActivateDocument(item);
IsOpenend = true;
}
}
}
return IsOpenend;
}
and i use this code in click of button to open the child form
private void bbtnEmployee_ItemClick(object sender, ItemClickEventArgs e)
{
FrmEmployee frme = new FrmEmployee();
frme.Name = "FrmEmployee";
ViewChildForm(frme);
}
my problem start when the form contain a LayoutControl for example i have this code that open on click of button
private void btnBonLivraison_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Top;
LookUpEdit OrderNumber = new LookUpEdit();
OrderNumber.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
OrderNumber.Properties.DataSource = shippProdu.GetOrderNumber();
OrderNumber.Properties.DisplayMember = "N° Bon de livraison";
OrderNumber.Properties.ValueMember = "N° Bon de livraison";
lc.AddItem(Resources.selectOrderNumber, OrderNumber).TextVisible = true;
lc.Height = 70;
this.Controls.Add(lc);
this.Dock = DockStyle.Top;
lc.BestFit();
the second I click on a button the tabHeader disappears,what cause this problem?and how can I solve it.before I use documentManager I used XtraTabControl and if i click a button to open LayoutControl and after that try to open another form the focus remaining in the first form even when the form two is already opened and if I want to go to form two I must first click on a tab of the first form and then click on tab of the second form , thanks in advance .
this is my main form
and this is when the eader disappears
If DocumentManager resides within the same form to which you add LayoutControl, it is the expected behavior. DocumentManager places a special documents' host onto the main form and set its Dock property to Fill. That is why it is incorrect to place LayoutControl onto the same form and dock it to form edges.
If you need to show tabbed documents and LayoutControl on the same form simultaneously, do not use the MDI mode. Consider the use of a separate UserControl. Place your DocumentManager there. Then, put this UserControl onto your form. Note that in this case UserControl's Dock property should be set to Top or Bottom since LayoutControl should fill all available area or vice versa.
I'm using C#, and I want create a form - which is composed of treeview treeview1, a panel panel1 and a button btn1.
In the begining the panel is empty, then a userControl userControl1 will be shown when the user select a node from the tree, and another userControl userControl2 will replace the first whene the user select another specific node , and go on ... as in setting forms
I found a solution here :
How to create an options form in C# Windows Forms?
but it is written i pseudo-code, i try implementing the code, and this what i get:
//on initializing
treeView1.Nodes.Add(new TreeNode());
treeView1.Nodes.Add(new TreeNode());
treeView1.Nodes.Add(new TreeNode());
treeView1.Nodes[0].Tag = new UserControl1();
treeView1.Nodes[1].Tag = new UserControl2();
treeView1.Nodes[2].Tag = new UserControl3();
treeView1.Nodes[0].Text = "user controle1";
treeView1.Nodes[1].Text = "user controle2";
treeView1.Nodes[2].Text = "user controle3";
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
UserControl currentControl = (UserControl)treeView1.SelectedNode.Tag;
TreeNode currentnode = treeView1.SelectedNode;
if (panel1.Controls != null)
{
panel1.Controls.Clear();
}
if (currentnode.Tag == null)
return;
panel1.Controls.Add((UserControl)currentnode.Tag);
}
and about the usecontrols I add nothing to the code, just controls that i need...
It works, but I am not sure if it is correct, I find other solutions and they add a lot of stuff to both, the user controls and to the main form.
So, what this code need to work properly.
i have make user control and inside that user control takes two buttons name dock and close respectively .
now i want to dock my user control to left when i clicks button dock and close my user control when i clicks button close..
now it works fine.....
but when i add my usercontrol to the toolbox by taking choose items....
then drag and drop my user control to form...
now i have chk on form move event if user control is dock or not...
(i am trying to use by making object of user control but doesnt helps.....)
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Container_User_Control.Container1 obj = new Container_User_Control.Container1();
if (obj.Dock != DockStyle.Left)
{
obj.visible=false;
}
else
{
obj.visible=true;
}
}
Thanks in advanced....
I have no idea why you are using a Mouse_Move event but if I understood your question right then:
When you drag your UserControl from the toolbox to the form, an instance of the usercontrol is created in the form designer code. Something like Container_User_Control1, so instead of using:
Container_User_Control.Container1 obj = new Container_User_Control.Container1();
if (obj.Dock != DockStyle.Left)
{
MessageBox.Show("none");
}
else
{
MessageBox.Show("left");
}
use:
if (Container_User_Control1.Dock != DockStyle.Left)
{
MessageBox.Show("none");
}
else
{
MessageBox.Show("left");
}
I have a main form in a panel on the left thats clickable, depending on what you click a new type of form opens. on the righti have another panel where i want to dock the forms that have been opened from clicking on the left.
How can i get the forms to add in a list under one another in the panel on the right? the issue with the code below is that it adds the first element fine. However when i add the second element they both dissapear behind the panel :/
private void addToPanel2(Form o)
{
if (o is Form)
{
if (panel2.Controls.Count == 0)
{
o.MdiParent = this;
panel2.Controls.Add(o);
o.Dock = DockStyle.Top;
o.Show();
}
else
{
//then we know that this is an addable data item
foreach (Form obj in panel2.Controls)
{
if(obj.GetType().Name.Equals(o.GetType().Name))
{
//we dont want to add it as the data type is already open
MessageBox.Show("This data item must already be open. Please Check.");
}
else
{
// add it as its not in there
Form f = (Form)obj;
f.MdiParent = this;
f.Dock = DockStyle.Top;
f.Show();
}
}
}
}
thanks
This is not possible, an MDI child form cannot be a child control of a panel. Adding a non-MDI form to a panel is an iffy proposition as well but is supported. Call its SetTopLevel() method, passing false, set its Visible property to true. You also have to set its FormBorderStyle property to None, it no longer behaves properly as a top-level window.
This just turns it into a UserControl. You are better off actually making it a UserControl, that uses a lot less resources and is much better documented.