WinForm programming problem



Excuse me, how to achieve the UI, different options on the left, on the right shows the input box and press button, not the same.?

Started by Antoine at November 17, 2016 - 4:50 PM

On the left side of treeview, on the right is panel.
The left side of each one on a form.
According to the selected item, panel loads the corresponding form.
ps: WinForm panel can be loaded in other forms.

Posted by Michelle at November 24, 2016 - 5:21 PM

Can write two lines of code about how panel loading window.?

Posted by Antoine at December 05, 2016 - 6:12 PM

Define a custom control, as the right, use:
panel.Controls.Clear();
panel.Controls.Add(new UserControl1());

Posted by Todd at December 08, 2016 - 6:26 PM

Form1 fm = new Form1();
fm.TopLevel = false;
fm.Show();
panel1.Controls.Add(fm);

Posted by Michelle at December 09, 2016 - 7:10 PM

+1

Posted by Cora at December 19, 2016 - 8:05 PM

+1

Posted by Taylor at January 01, 2017 - 9:32 PM

Panal left treeview right

The button of what the interface you use UserControl

Posted by Carl at January 03, 2017 - 8:42 PM

//The user control 

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Data; 
using System.Text; 
using System.Windows.Forms; 

namespace MenuTest.UCcontrol 
{ 
public partial class Menu : UserControl 
{ 
public Menu() 
{ 
InitializeComponent(); 

} 
void CreateFirst() 
{ 
mylistView.Items.Clear(); 
mylistView.LargeImageList = imageListF; 
mylistView.Items.Add("The first sub menu", 0); 
mylistView.Items.Add("The second sub menu", 1); 
} 
void CreateSecond() 
{ 
mylistView.Items.Clear(); 
mylistView.LargeImageList = imageListS; 
mylistView.Items.Add("The first sub menu", 0); 
mylistView.Items.Add("The second sub menu", 1); 
mylistView.Items.Add("The third sub menu", 2); 
mylistView.Items.Add("The fourth sub menu", 3); 
} 
void CreateThree() 
{ 
mylistView.Items.Clear(); 
mylistView.LargeImageList = imageListT; 
mylistView.Items.Add("The first sub menu", 0); 
mylistView.Items.Add("The second sub menu", 1); 
} 
/// <summary> 
/// Click the button to display the menu is different in different 
/// Principle 1: get the click of a button control in all 2 cycles of panel, if the button 
/// Then determine whether the button, set the display position 
/// 3 don't forget all the controls are displayed in the front (BringToFront) function 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
void ButtonClick(object sender, System.EventArgs e) 
{ 
//Get click button 
Button clickedButton = (Button)sender; 
// The tab index 
int clickedButtonTabIndex = clickedButton.TabIndex; 

//Button shows the location of the top or the bottom 
foreach (Control ctl in this.panel1.Controls) //Access to all controls in panel1 
{ 
if (ctl is Button) //If it is Button 
{ 
Button btn = (Button)ctl; 
//If the Button TabIndex is greater than a click on the button TabIndex 
//The circulation to the button is not clicked the button 
if (btn.TabIndex > clickedButtonTabIndex) 
{ 
//If the circulation to the button is not displayed in the bottom 
if (btn.Dock != DockStyle.Bottom) 
{ 
//Let the show at the bottom 
btn.Dock = DockStyle.Bottom; 
// Displayed in the front 
btn.BringToFront(); 
} 
} 
else //Circulation to the click of a button 
{ 
//Not at the top is shown at the top 
if (btn.Dock != DockStyle.Top) 
{ 
btn.Dock = DockStyle.Top; 
// Displayed in the front 
btn.BringToFront(); 
} 
} 
} 
} 

switch (clickedButton.Text) 
{ 
case "The first item": 
CreateFirst(); 
break; 

case "Second": 
CreateSecond(); 
break; 

case "Third": 
CreateThree(); 
break; 
} 
mylistView.BringToFront(); 
} 

//Customize your event 
public event EventHandler menu_listView1_SelectedIndexChanged; 

//This trigger your own custom events in preparation for the main form of hanging the event 
private void listView1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
if (this.menu_listView1_SelectedIndexChanged != null) 
menu_listView1_SelectedIndexChanged(sender, e); 
} 

} 
} 

///////////////////////////////////////
//The main form 

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 

namespace MenuTest 
{ 
public partial class Form1 : Form 
{ 
public Form1() 
{ 
InitializeComponent(); 
} 
//The instantiation of the user control 
UCcontrol.Menu menu = new UCcontrol.Menu(); 
string Item; 

private void Form1_Load(object sender, EventArgs e) 
{ 


this.Controls.Add(menu); 
//Hanging the user control events 
this.menu.menu_listView1_SelectedIndexChanged += new EventHandler(menu_listView1_SelectedIndexChanged); 
} 


// 
#region //User defined control test 
void Do() 
{ 
MessageBox.Show("The first sub menu"); 
} 
// 
void Do1() 
{ 
MessageBox.Show("The second sub menu"); 
} 

//According to the different click execute different events 
void Dosomething() 
{ 
switch(Item) 
{ 
case "The first sub menu": 
Do(); 
break; 
case "The second sub menu": 
Do1(); 
break; 
} 
} 


/// <summary> 
/// User controls that define their own custom events events 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
private void menu_listView1_SelectedIndexChanged(object sender, EventArgs e) 
{ 

ListView listView = (ListView)sender; //Take to send event control 
if (listView.SelectedIndices.Count > 0) 
{ 
Item = listView.SelectedItems[0].Text; 
Dosomething(); 
} 
} 
#endregion 
} 
} 


 

Posted by Carl at January 04, 2017 - 10:00 PM

Is actually a MDI ah, Baidu search "parent, child," all understand

Posted by Wilbur at January 07, 2017 - 10:27 PM