/*
* Created with SharpDevelop.
* User: Gary Perkin
* Date: 02/03/2005
* Time: 08:31
*
*/
using System;
using System.Windows.Forms;
namespace DefaultNamespace
{
/// <summary>
/// De***ion of MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button buttonMisc;
private System.Windows.Forms.ListView listView2;
/// <summary>
/// QQ好友列表
/// </summary>
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Button buttonCars;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ImageList imageListOutlook;
private System.Windows.Forms.ImageList imageListZip;
private System.Windows.Forms.ImageList imageListCars;
private System.Windows.Forms.Button buttonZip;
private System.Windows.Forms.Splitter splitter1;
public MainForm()
{
InitializeComponent();
CreateOutlookList();
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.splitter1 = new System.Windows.Forms.Splitter();
this.buttonZip = new System.Windows.Forms.Button();
this.imageListCars = new System.Windows.Forms.ImageList(this.components);
this.imageListZip = new System.Windows.Forms.ImageList(this.components);
this.imageListOutlook = new System.Windows.Forms.ImageList(this.components);
this.panel1 = new System.Windows.Forms.Panel();
this.listView1 = new System.Windows.Forms.ListView();
this.buttonMisc = new System.Windows.Forms.Button();
this.buttonCars = new System.Windows.Forms.Button();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.listView2 = new System.Windows.Forms.ListView();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(136, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(4, 501);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// buttonZip
//
this.buttonZip.BackColor = System.Drawing.SystemColors.Control;
this.buttonZip.Dock = System.Windows.Forms.DockStyle.Top;
this.buttonZip.Location = new System.Drawing.Point(0, 23);
this.buttonZip.Name = "buttonZip";
this.buttonZip.Size = new System.Drawing.Size(132, 23);
this.buttonZip.TabIndex = 2;
this.buttonZip.Text = "Zip Files";
this.buttonZip.Click += new System.EventHandler(this.ButtonClick);
//
// imageListCars
//
this.imageListCars.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.imageListCars.ImageSize = new System.Drawing.Size(32, 32);
this.imageListCars.TransparentColor = System.Drawing.Color.White;
//
// imageListZip
//
this.imageListZip.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.imageListZip.ImageSize = new System.Drawing.Size(32, 32);
this.imageListZip.TransparentColor = System.Drawing.Color.White;
//
// imageListOutlook
//
this.imageListOutlook.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.imageListOutlook.ImageSize = new System.Drawing.Size(48, 48);
this.imageListOutlook.TransparentColor = System.Drawing.Color.White;
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.listView1);
this.panel1.Controls.Add(this.buttonMisc);
this.panel1.Controls.Add(this.buttonZip);
this.panel1.Controls.Add(this.buttonCars);
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(136, 501);
this.panel1.TabIndex = 0;
//
// listView1
//
this.listView1.BackColor = System.Drawing.SystemColors.Menu;
this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.LargeImageList = this.imageListCars;
this.listView1.Location = new System.Drawing.Point(0, 69);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(132, 428);
this.listView1.TabIndex = 6;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.ListView1SelectedIndexChanged);
//
// buttonMisc
//
this.buttonMisc.BackColor = System.Drawing.SystemColors.Control;
this.buttonMisc.Dock = System.Windows.Forms.DockStyle.Top;
this.buttonMisc.Location = new System.Drawing.Point(0, 46);
this.buttonMisc.Name = "buttonMisc";
this.buttonMisc.Size = new System.Drawing.Size(132, 23);
this.buttonMisc.TabIndex = 3;
this.buttonMisc.Text = "Outlook Shortcuts";
this.buttonMisc.Click += new System.EventHandler(this.ButtonClick);
//
// buttonCars
//
this.buttonCars.BackColor = System.Drawing.SystemColors.Control;
this.buttonCars.Dock = System.Windows.Forms.DockStyle.Top;
this.buttonCars.Location = new System.Drawing.Point(0, 0);
this.buttonCars.Name = "buttonCars";
this.buttonCars.Size = new System.Drawing.Size(132, 23);
this.buttonCars.TabIndex = 1;
this.buttonCars.Text = "Cars";
this.buttonCars.Click += new System.EventHandler(this.ButtonClick);
//
// columnHeader1
//
this.columnHeader1.Text = "Selected Item";
this.columnHeader1.Width = 359;
//
// listView2
//
this.listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1});
this.listView2.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView2.Location = new System.Drawing.Point(140, 0);
this.listView2.Name = "listView2";
this.listView2.Size = new System.Drawing.Size(445, 501);
this.listView2.TabIndex = 2;
this.listView2.View = System.Windows.Forms.View.Details;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(585, 501);
this.Controls.Add(this.listView2);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel1);
this.Name = "MainForm";
this.Text = "Cheat\'s Outlook Bar!";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
#region Populate the Outlook bar
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);
}
#endregion Populate the Outlook bar
#region Handle events
/// <summary>
/// 按不同的按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClick(object sender, System.EventArgs e)
{
// Get the clicked button...
Button clickedButton = (Button)sender;
// ... and it's tabindex
//获取当前点击的 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;
//显示控件
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.
}
// Show which item we've selected.
void ListView1SelectedIndexChanged(object sender, System.EventArgs e)
{
if (listView1.SelectedIndices.Count > 0)
listView2.Items.Add(listView1.SelectedItems[0].Text);
}
#endregion Handle events
}
}
这段代码主要是通过 TabIndex 来排序每个栏目(按钮) 最后通过调用BringToFront()函数来显示这个控件
界面设计是把三个栏目(按钮)和ListView控件放到一个 Panel中 通过Panel.Controls来控制显示他们








