So i'm making a settings screen at the moment where i'll have a tree on the left then a panel on the right. The panel thats on screen will depend on what tree item is selected..
Just wondering how do I go about designing these panels and saving theme for use later on (runtime).
Do I need to go and draw them out etc. view code then copy into a class or something?
Sorry if my question is a bit vague but i'm not really sure what I want :-O
EDIT Yes, i'm looking to make a settings screen like the one found in Visual Studio. A tree on the left (explorer like) and then a new form layout for each tree node.
You'll want to create UserControls instead of a Panel, it is easy to edit in the designer. Dock the tree view to the left and use code like this to select the active user control:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
}
private UserControl mActivePanel;
void treeView1_AfterSelect(object sender, TreeViewEventArgs e) {
UserControl newPanel = null;
switch (e.Node.Index) {
case 0: newPanel = new UserControl1(); break;
case 1: newPanel = new UserControl2(); break;
// etc...
}
if (newPanel != null) {
if (mActivePanel != null) {
mActivePanel.Dispose();
this.Controls.Remove(mActivePanel);
}
newPanel.Dock = DockStyle.Fill;
this.Controls.Add(newPanel);
this.Controls.SetChildIndex(newPanel, 0);
mActivePanel = newPanel;
}
}
}
Related
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 a form that contains a TableLayoutPanel with various controls and labels in it. One of them is a custom control that inherits from ComboBox that has extra auto-complete behavior (auto-completes on any text rather than just left to right). I didn't write the code for this control, so I'm not super familiar with how it works, but essentially upon clicking on the Combobox, it adds a ListBox below the ComboBox, within the same Panel of the TableLayoutPanel, that covers the normal drop down.
Unfortunately, the TableLayoutPanel prevents the ListBox from being fully visible when added, and only one item is shown. The goal is to get it to look like a normal ComboBox which would drop down to cover any controls below it.
Is there any way to allow a control that is in a TableLayoutPanel to overlap the TableLayoutPanel to get this to work as I want? I want to avoid any controls moving around due to the TableLayoutPanel growing to accommodate the ListBox.
Relevant code from the control:
void InitListControl()
{
if (listBoxChild == null)
{
// Find parent - or keep going up until you find the parent form
ComboParentForm = this.Parent;
if (ComboParentForm != null)
{
// Setup a messaage filter so we can listen to the keyboard
if (!MsgFilterActive)
{
Application.AddMessageFilter(this);
MsgFilterActive = true;
}
listBoxChild = listBoxChild = new ListBox();
listBoxChild.Visible = false;
listBoxChild.Click += listBox1_Click;
ComboParentForm.Controls.Add(listBoxChild);
ComboParentForm.Controls.SetChildIndex(listBoxChild, 0); // Put it at the front
}
}
}
void ComboListMatcher_TextChanged(object sender, EventArgs e)
{
if (IgnoreTextChange > 0)
{
IgnoreTextChange = 0;
return;
}
InitListControl();
if (listBoxChild == null)
return;
string SearchText = this.Text;
listBoxChild.Items.Clear();
// Don't show the list when nothing has been typed
if (!string.IsNullOrEmpty(SearchText))
{
foreach (string Item in this.Items)
{
if (Item != null && Item.ToLower().Contains(SearchText.ToLower()))
{
listBoxChild.Items.Add(Item);
listBoxChild.SelectedIndex = 0;
}
}
}
if (listBoxChild.Items.Count > 0)
{
Point PutItHere = new Point(this.Left, this.Bottom);
Control TheControlToMove = this;
PutItHere = this.Parent.PointToScreen(PutItHere);
TheControlToMove = listBoxChild;
PutItHere = ComboParentForm.PointToClient(PutItHere);
TheControlToMove.Anchor = ((System.Windows.Forms.AnchorStyles)
((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
TheControlToMove.BringToFront();
TheControlToMove.Show();
TheControlToMove.Left = PutItHere.X;
TheControlToMove.Top = PutItHere.Y;
TheControlToMove.Width = this.Width;
int TotalItemHeight = listBoxChild.ItemHeight * (listBoxChild.Items.Count + 1);
TheControlToMove.Height = Math.Min(ComboParentForm.ClientSize.Height - TheControlToMove.Top, TotalItemHeight);
}
else
HideTheList();
}
Images:
Desired behavior
Current behavior
Going on the suggestion from TaW, I came up with a tentative solution. This form isn't re-sizable but does auto-size so that it looks ok if the user changes their DPI in Windows.
To resolve this, I moved the control out of the TableLayoutPanel to an arbitrary position in the Parent of the TableLayoutPanel. On form loading, I summed the coordinates of the TableLayoutPanel and an empty panel in the cell that I wanted the control to be located on top of. This worked for my needs but it feels like a kludge.
The better solution is probably to use Control.PointToScreen and Control.PointToClient methods, however I wasn't able to get these methods to give me the correct coordinates.
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.
Does anyone know a way to open a 2nd form in a .NET application with a certain tab selected in a tab control on that form?
This is what my current code looks like which just opens the form:
SettingsForm TheSettingsForm = new SettingsForm(this);
TheSettingsForm.Show();
SettingsForm.cs is the name of the 2nd form to be opened.
Thanks in advance,
You just need to expose a property on your form that allows the calling code to set the desired tab. You might do it just by index like this:
var form = new SettingsForm(this);
form.SelectedTab = 2;
form.Show();
The property on the form would just set the appropriate property on the tab control:
public int SelectedTab
{
get { return _tabControl.SelectedIndex; }
set { _tabControl.SelectedIndex = value; }
}
Do something like this:
SettingsForm TheSettingsForm = new SettingsForm(this);
TheSettingsForm.TabPanel.SelectedIndex = SettingsFormTabIndexes.MyDesiredTab;
TheSettingsForm.Show();
where you've made a property in TheSettingsForm that exposes the tab control and SettingsFormTabIndexes is a friendly enum naming all the tabs by index.
Add an event handler to the TabControl.SelectedIndexChanged event.
myTabControl.SelectedIndexChanged += myTabControl_SelectedIndexChanged;
private void myTabControl_SelectedIndexChanged(object sender, EventArgs e) {
TabControl tc = sender as TabControl;
if (tc.SelectedIndex == indexOfTabToShowFormOn) {
TheSettingsForm.Show();
}
}