xp 左侧 折叠式菜单 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace MainUI{  public partial class MainFrm : Form  {    public MainFrm()    {      InitializeComponent();    }    private void MainFrm_Load(object sender, EventArgs e)    {      CreateOutlookList();    }    private void CreateCarList()    {      listView1.Items.Clear();      listView1.LargeImageList = imageListCars;      listView1.Items.Add("Sports", 0);      listView1.Items.Add("Beetle", 1);      listView1.Items.Add("Vintage", 2);    }    private void CreateOutlookList()    {      listView1.Items.Clear();      listView1.LargeImageList = imageListOutlook;      listView1.Items.Add("Outlook Today", 0);      listView1.Items.Add("Inbox", 1);      listView1.Items.Add("Calendar", 2);      listView1.Items.Add("Contacts", 3);      listView1.Items.Add("Tasks", 4);      listView1.Items.Add("Deleted Items", 5);    }    private void CreateZipList()    {      listView1.Items.Clear();      listView1.LargeImageList = imageListZip;      listView1.Items.Add("Word Docs", 0);      listView1.Items.Add("Holiday Pics", 0);      listView1.Items.Add("C# programs", 0);      listView1.Items.Add("Samba Install", 0);    }    void ButtonClick(object sender, System.EventArgs e)    {      // Get the clicked button...      Button clickedButton = (Button)sender;      // ... and it's tabindex      int clickedButtonTabIndex = clickedButton.TabIndex;      // Send each button to top or bottom as appropriate      foreach (Control ctl in panel1.Controls)      {        if (ctl is Button)        {          Button btn = (Button)ctl;          if (btn.TabIndex > clickedButtonTabIndex)          {            if (btn.Dock != DockStyle.Bottom)            {              btn.Dock = DockStyle.Bottom;              // This is vital to preserve the correct order              btn.BringToFront();            }          }          else          {            if (btn.Dock != DockStyle.Top)            {              btn.Dock = DockStyle.Top;              // This is vital to preserve the correct order              btn.BringToFront();            }          }        }      }      // Determine which button was clicked.      switch (clickedButton.Text)      {        case "Cars":          CreateCarList();          break;        case "Outlook Shortcuts":          CreateOutlookList();          break;        case "Zip Files":          CreateZipList();          break;      }      listView1.BringToFront(); // Without this, the buttons will hide the items.    }    private void listView1_SelectedIndexChanged(object sender, EventArgs e)    {      if (this.listView1.SelectedIndices.Count > 0)      {        MessageBox.Show(this.listView1.SelectedItems[0].Text);      }    }  }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace MainUI{  public partial class MainFrm : Form  {    public MainFrm()    {      InitializeComponent();    }    private void MainFrm_Load(object sender, EventArgs e)    {      CreateOutlookList();    }    private void CreateCarList()    {      listView1.Items.Clear();      listView1.LargeImageList = imageListCars;      listView1.Items.Add("Sports", 0);      listView1.Items.Add("Beetle", 1);      listView1.Items.Add("Vintage", 2);    }    private void CreateOutlookList()    {      listView1.Items.Clear();      listView1.LargeImageList = imageListOutlook;      listView1.Items.Add("Outlook Today", 0);      listView1.Items.Add("Inbox", 1);      listView1.Items.Add("Calendar", 2);      listView1.Items.Add("Contacts", 3);      listView1.Items.Add("Tasks", 4);      listView1.Items.Add("Deleted Items", 5);    }    private void CreateZipList()    {      listView1.Items.Clear();      listView1.LargeImageList = imageListZip;      listView1.Items.Add("Word Docs", 0);      listView1.Items.Add("Holiday Pics", 0);      listView1.Items.Add("C# programs", 0);      listView1.Items.Add("Samba Install", 0);    }    void ButtonClick(object sender, System.EventArgs e)    {      // Get the clicked button...      Button clickedButton = (Button)sender;      // ... and it's tabindex      int clickedButtonTabIndex = clickedButton.TabIndex;      // Send each button to top or bottom as appropriate      foreach (Control ctl in panel1.Controls)      {        if (ctl is Button)        {          Button btn = (Button)ctl;          if (btn.TabIndex > clickedButtonTabIndex)          {            if (btn.Dock != DockStyle.Bottom)            {              btn.Dock = DockStyle.Bottom;              // This is vital to preserve the correct order              btn.BringToFront();            }          }          else          {            if (btn.Dock != DockStyle.Top)            {              btn.Dock = DockStyle.Top;              // This is vital to preserve the correct order              btn.BringToFront();            }          }        }      }      // Determine which button was clicked.      switch (clickedButton.Text)      {        case "Cars":          CreateCarList();          break;        case "Outlook Shortcuts":          CreateOutlookList();          break;        case "Zip Files":          CreateZipList();          break;      }      listView1.BringToFront(); // Without this, the buttons will hide the items.    }    private void listView1_SelectedIndexChanged(object sender, EventArgs e)    {      if (this.listView1.SelectedIndices.Count > 0)      {        MessageBox.Show(this.listView1.SelectedItems[0].Text);      }    }  }}

 
  
					
				
评论