public partial class OutLookExUI : UserControl
{
public InnerOutLookTreeClass OutLookTree = new InnerOutLookTreeClass();
public Panel MainPanel = new Panel();
public OutLookExUI()
{
InitializeComponent();
this.MainPanel.Visible = false;
this.MainPanel.AutoScroll = true;
this.Controls.Add(this.MainPanel);
}
private void OutLookExUI_Load(object sender, EventArgs e)
{
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
Point p=e.Location;
int newSelectedIndex = -1;
for (int i = 0; i < this.OutLookTree.Items.Count; i++)
{
if (this.OutLookTree.Items[i].MaxRect.Contains(p) == true)
{
newSelectedIndex = i;
break;
}
}
if (newSelectedIndex != -1)
{
this.OutLookTree.SetALLSelectedState(false);
this.OutLookTree.Items[newSelectedIndex].Selected = true;
this.MainPanel.Controls.Clear();
Control ctrl = this.OutLookTree.Items[newSelectedIndex].GetControl;
ctrl.Dock = DockStyle.Fill;
this.MainPanel.Controls.Add(ctrl);
this.Refresh();
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
//Point p = e.Location;
//int newSelectedIndex = -1;
//for (int i = 0; i < this.OutLookTree.Items.Count; i++)
//{
// if (this.OutLookTree.Items[i].MaxRect.Contains(p) == true)
// {
// newSelectedIndex = i;
// break;
// }
//}
//if (newSelectedIndex != -1)
//{
// this.Cursor = Cursors.Hand;
//}
//else
//{
// this.Cursor = Cursors.Default;
//}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.OutLookTree.SetALLControlByNull();
this.Refresh();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.OutLookTree != null)
{
Color c1 = Color.White;
Color c2 = this.BackColor;
Color c3 = Color.LightSlateGray;
int SelectedIndex = -1;
int totalItemCount = this.OutLookTree.Items.Count;
for (int i = 0; i < this.OutLookTree.Items.Count; i++)
{
if (SelectedIndex < 0)
{ //选中项的上半部分
Rectangle rac = new Rectangle(1, i * 30, this.Width - 2, 30);
if (this.OutLookTree.Items[i].Selected == false)
{ //未选中项
using (LinearGradientBrush lbrush = new LinearGradientBrush(rac,
c1, c2,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(lbrush, rac);
}
}
else
{ //已选中项
using (LinearGradientBrush lbrush = new LinearGradientBrush(rac,
c1, c3,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(lbrush, rac);
}
SelectedIndex = i;
}
this.OutLookTree.Items[i].MaxRect = rac;
PointF pf = new PointF(this.Width / 2 - this.OutLookTree.Items
[i].Text.Length * 5, i * 30 + 5);
e.Graphics.DrawString(this.OutLookTree.Items[i].Text, new Font("宋体
", 10), Brushes.Black, pf);
}
else
{ //选中项的下半部分
//未选中项
int top = this.Height - (totalItemCount - SelectedIndex) * 30 + (i -
SelectedIndex) * 30;
Rectangle rac = new Rectangle(1,top , this.Width - 2, 30);
using (LinearGradientBrush lbrush = new LinearGradientBrush(rac, c1,
c2,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(lbrush, rac);
}
PointF pf = new PointF(this.Width / 2 - this.OutLookTree.Items
[i].Text.Length * 5, top + 5);
e.Graphics.DrawString(this.OutLookTree.Items[i].Text, new Font("宋体
", 10), Brushes.Black, pf);
this.OutLookTree.Items[i].MaxRect = rac;
}
} //end for
if (SelectedIndex >= 0)
{
this.MainPanel.Top = this.OutLookTree.Items
[SelectedIndex].MaxRect.Bottom;
this.MainPanel.Left = 2;
this.MainPanel.Width = this.Width - 4;
this.MainPanel.Height = this.Height - totalItemCount * 30-5;
this.MainPanel.Visible = true;
}
else
{
this.MainPanel.Visible = false;
}
}
else
{
PointF pf=new PointF(this.Width/2,this.Height/2);
e.Graphics.DrawString("无数据", new Font("宋体", 15), Brushes.Black, pf);
}
this.DrawBorder(e.Graphics, Pens.Black);
}
protected virtual void DrawBorder(Graphics g, Pen pen)
{
//if (m_Region != null)
//{
int m_radius = 5;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawPath(pen, CreateRoundRectangle(new Rectangle
(this.ClientRectangle.Left, this.ClientRectangle.Top, this.ClientRectangle.Width - 1,
this.ClientRectangle.Height - 1), m_radius));
g.SmoothingMode = SmoothingMode.Default;
g.InterpolationMode = InterpolationMode.Default;
//}
//pen.Dispose();
//pen = null;
}
protected virtual void DrawUpperShine(Graphics g)
{
Color c1 = Color.FromArgb(200, Color.DarkGray);
Color c2 = Color.FromArgb(100, Color.White);
Rectangle rc = new Rectangle(this.ClientRectangle.Left,
this.ClientRectangle.Top, Width - 1, Height / 2);
//if (IsMouseDown)
//{
// rc = new Rectangle(this.ClientRectangle.Left, this.ClientRectangle.Top,
Width - 1, (Height - 10) / 2);
//}
using (LinearGradientBrush lbrush = new LinearGradientBrush(rc, c1, c2,
LinearGradientMode.Vertical))
{
g.FillRectangle(lbrush, rc);
}
}
protected virtual void DrawBottomShine(Graphics g)
{
Rectangle rc1 = new Rectangle(this.ClientRectangle.Left,
this.ClientRectangle.Top + this.ClientRectangle.Height / 2,
this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);
Rectangle rc2 = new Rectangle(this.ClientRectangle.Left +
this.ClientRectangle.Width / 2,
this.ClientRectangle.Top + this.ClientRectangle.Height / 2,
this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2);
Color c1 = BackColor;
Color c2 = Color.DarkGray;
using (LinearGradientBrush lbrush = new LinearGradientBrush(rc1, c1, c2,
LinearGradientMode.ForwardDiagonal))
{
g.FillRectangle(lbrush, rc1);
}
using (LinearGradientBrush lbrush = new LinearGradientBrush(rc2, c1, c2,
LinearGradientMode.BackwardDiagonal))
{
g.FillRectangle(lbrush, rc2);
}
}
protected virtual void DrawDisable(Graphics g, Brush brush, Pen pen)
{
//g.FillPath(brush, m_Region);
DrawBorder(g, pen);
brush.Dispose();
pen.Dispose();
brush = null;
pen = null;
}
protected virtual GraphicsPath CreateRoundRectangle(Rectangle rectangle, int radius)
{
GraphicsPath path = new GraphicsPath();
int l = rectangle.Left;
int t = rectangle.Top;
int w = rectangle.Width;
int h = rectangle.Height;
int d = radius << 1;
path.AddArc(l, t, d, d, 180, 90); // topleft
path.AddLine(l + radius, t, l + w - radius, t); // top
path.AddArc(l + w - d, t, d, d, 270, 90); // topright
path.AddLine(l + w, t + radius, l + w, t + h - radius); // right
path.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomright
path.AddLine(l + w - radius, t + h, l + radius, t + h); // bottom
path.AddArc(l, t + h - d, d, d, 90, 90); // bottomleft
path.AddLine(l, t + h - radius, l, t + radius); // left
path.CloseFigure();
return path;
}
}
/// <summary>
/// 内部树结构定义
/// </summary>
public class InnerOutLookTreeClass :IInnerOutLookTree
{
public Image Image = null;
public string Text = "";
public string Value = "";
public object Tag = null;
public int ImageIndex = -1;
public InnerOutLookTreeNodeItem CurrentOutLookTreeNodeItem = null;
public InnerOutLookTreeClass()
{
}
#region IInnerOutLookTree 成员
private InnerOutLookTreeNodeItems m_Items = new InnerOutLookTreeNodeItems();
public InnerOutLookTreeNodeItems Items
{
get { return this.m_Items; }
}
public void SetALLSelectedState(bool pSelected)
{
for (int i = 0; i < m_Items.Count; i++)
{
this.m_Items[i].Selected = pSelected;
}
}
public void SetALLControlByNull()
{
for (int i = 0; i < m_Items.Count; i++)
{
this.m_Items[i].SetControl(null);
for (int j = 0; j < this.m_Items[i].Items.Count; j++)
{
this.m_Items[i].Items[j].SetControl(null);
}
}
}
#endregion
}
public interface IInnerOutLookTree
{
InnerOutLookTreeNodeItems Items { get; }
}
/// <summary>
/// 内部树节点结构定义
/// </summary>
public class InnerOutLookTreeNodeItem : IInnerOutLookTree
{
public Image Image = null;
public string Text = "";
public string Value = "";
public object Tag = null;
public int ImageIndex = -1;
public bool;
public Rectangle MaxRect =new Rectangle();
private Control m_GetControl = null;
public Control GetControl
{
get
{
if (m_GetControl == null)
{ //初始化
m_GetControl = new OutLookQQViewItemHelper(this.Items);
//OutLookItemHelper(this.Items);
}
return m_GetControl;
}
}
public void SetControl(Control ctrl)
{
m_GetControl = ctrl;
}
#region IInnerOutLookTree 成员
private InnerOutLookTreeNodeItems m_Items = new InnerOutLookTreeNodeItems();
public InnerOutLookTreeNodeItems Items
{
get { return this.m_Items; }
}
#endregion
}
/// <summary>
/// 内部树节点集合结构定义
/// </summary>
public class InnerOutLookTreeNodeItems : List<InnerOutLookTreeNodeItem>
{
}
//-----------------------------
//树型风格显示的OutLook项内容
public class OutLookTreeViewItemHelper : System.Windows.Forms.TreeView
{
private InnerOutLookTreeNodeItems m_Items = null;
public OutLookTreeViewItemHelper(InnerOutLookTreeNodeItems pItems)
{
m_Items = pItems;
this.BorderStyle = BorderStyle.None;
//初始化树控件
this.Nodes.Clear();
for (int i = 0; i < m_Items.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = this.m_Items[i].Text;
this.Nodes.Add(tn);
}
}
}
//ListView型风格显示的OutLook项内容
public class OutLookListViewItemHelper : System.Windows.Forms.ListView
{
private InnerOutLookTreeNodeItems m_Items = null;
public OutLookListViewItemHelper(InnerOutLookTreeNodeItems pItems)
{
m_Items = pItems;
this.BorderStyle = BorderStyle.None;
this.GridLines = false;
this.View = View.LargeIcon;
//初始化树控件
this.Items.Clear();
for (int i = 0; i < m_Items.Count; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = this.m_Items[i].Text;
this.Items.Add(lvi);
}
}
}
//QQ视图型风格显示的OutLook项内容
public class OutLookQQViewItemHelper : UserControl
{
private InnerOutLookTreeNodeItems m_Items = null;
public OutLookQQViewItemHelper(InnerOutLookTreeNodeItems pItems)
{
m_Items = pItems;
this.BorderStyle = BorderStyle.None;
this.AutoScroll = true;
this.VScroll = true;
this.AdjustFormScrollbars(true);
this.initQQView();
}
public void initQQView()
{
//初始化树控件
this.Controls.Clear();
for (int i = 0; i < m_Items.Count; i++)
{
QQViewStyle_BigImageUC uc = new QQViewStyle_BigImageUC();
uc.Label.Text = this.m_Items[i].Text;
uc.PictureBox.Click += new EventHandler(PictureBox_Click);
uc.PictureBox.Tag = this.m_Items[i];
uc.Left = this.Width - this.Width / 2 - uc.Width / 2;
uc.Top = i * uc.Height;
this.Controls.Add(uc);
}
}
private void PictureBox_Click(object sender, EventArgs e)
{
PictureBox pic = sender as PictureBox;
if (pic.Tag != null && pic.Tag is InnerOutLookTreeNodeItem)
{
InnerOutLookTreeNodeItem nodeItem = pic.Tag as InnerOutLookTreeNodeItem;
MessageBox.Show(nodeItem.Text, "提示");
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
this.initQQView();
}
}
public partial class QQViewStyle_BigImageUC : UserControl, IQQViewStyle_BigImage
{
public QQViewStyle_BigImageUC()
{
InitializeComponent();
}
private void QQViewStyle_BigImageUC_Load(object sender, EventArgs e)
{
this.PictureBox.MouseEnter += new EventHandler(PictureBox_MouseEnter);
this.PictureBox.MouseLeave += new EventHandler(PictureBox_MouseLeave);
}
private void PictureBox_MouseLeave(object sender, EventArgs e)
{
this.Cursor = Cursors.Default;
this.PictureBox.BorderStyle = BorderStyle.None;
}
private void PictureBox_MouseEnter(object sender, EventArgs e)
{
this.Cursor = Cursors.Hand;
this.PictureBox.BorderStyle = BorderStyle.FixedSingle;
}
#region IQQViewStyle_BigImage 成员
public PictureBox PictureBox
{
get { return this.pictureBox1; }
}
public Label Label
{
get { return this.label1; }
}
#endregion
}
public interface IQQViewStyle_BigImage
{
PictureBox PictureBox { get; }
Label Label { get; }
}