📄 glistview.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;
using System.ComponentModel.Design;
using System.Drawing.Design;
namespace gowk.controls
{
public class GListView:GPanel
{
#region
private bool isInitialing=false;
private Orientation orientation=Orientation.Vertical;
private GListViewFolderCollection items;
private int indent=8;
/* private int top_offset=1;
private int bottom_offset=1;
private int right_offset=1;
private int left_offset=1;
private int border_left=2;
private int border_right=2;
private int border_top=2;
private int border_bottom=2;*/
private int top_offset=0;
private int bottom_offset=0;
private int right_offset=01;
private int left_offset=0;
private int border_left=0;
private int border_right=0;
private int border_top=02;
private int border_bottom=0;
private int maximize_height=58;
private int minimize_height=20;
private GListViewFolderManager foulderManager;
public event ItemEventHandler ItemAdded,ItemRemoved,
ItemExpanded,ItemClicked,ItemMouseHover,ItemMouseDown,
ItemMouseUp,ItemMouseItemMouseLeave,ItemMouseEnter,
ItemTextChanged,ItemVisibleChanged;
public event DrawItemEventHandler DrawItem;
private GListViewItem selectedItem;
#endregion
int expandfolderindex;
#region contructor
public GListView()
{
this.SetStyle(ControlStyles.DoubleBuffer|ControlStyles.UserPaint|ControlStyles.AllPaintingInWmPaint| ControlStyles.Selectable,true);
items=new GListViewFolderCollection(this);
this.foulderManager=new GListViewFolderManager(this);
this.IsRound=false;
this.GBorderStyle=GBorderStyle.Null;
}
#endregion
#region property
public GListViewItem SelectedItem
{
get{return this.selectedItem;}
set
{
//someting to to
this.selectedItem=value;
}
}
public int Indent {get{return this.indent;} set{this.indent=value;}}
private int InnerWidth
{
get{return this.Width-border_left-border_right-right_offset-left_offset;}
}
private int InnerHeight
{
get{return this.Height-top_offset-bottom_offset-border_top-border_bottom;}
}
private Rectangle InnerRectangle
{
get
{
return
new
Rectangle(
this.border_left+this.left_offset,
this.border_top+this.top_offset,
this.InnerWidth,
this.InnerHeight);
}
}
[System.ComponentModel.Editor(typeof(GListViewFolderCollectionEditor),typeof(System.Drawing.Design.UITypeEditor)), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GListViewFolderCollection Items
{
get{return this.items;}
set{this.items=value;}
}
public Orientation Orientation
{
get{return this.orientation;}
set{this.orientation=value;}
}
public int MinItemHeight
{
get{return this.minimize_height;}
set{this.minimize_height=value;}
}
public int MaxItemHeight
{
get{return this.maximize_height;}
set{this.maximize_height=value;}
}
#endregion
#region custom pretected methods
protected internal virtual void OnItemAdded(ItemEventArgs e)
{
this.update();
if(this.ItemAdded!=null)this.ItemAdded(this,e);
}
protected internal virtual void OnItemRemoved(ItemEventArgs e)
{
if(this.expandfolderindex>=this.items.Count)this.expandfolderindex=0;
this.update();
if(this.ItemRemoved!=null)this.ItemRemoved(this,e);
}
protected internal virtual void OnItemExpanded(ItemEventArgs e)
{
/* if(!(e.Item is GListViewFolder))
{
foreach(gowk.controls.GListViewItem itm in this.items)
{
if(itm!=e.Item)
{
itm.expanded=false;
}
}
this.update();
}*/
if(this.ItemExpanded!=null)this.ItemExpanded(this,e);
if(this.items.Contains(e.Item))
{
this.expandfolderindex=this.items.IndexOf(e.Item);
}
if(!(e.Item is GListViewFolder))
this.update();
}
protected internal virtual void OnItemClicked(ItemEventArgs e)
{
if(this.ItemClicked!=null)this.ItemClicked(this,e);
}
protected internal virtual void OnItemMouseHover(ItemEventArgs e)
{
if(this.ItemMouseHover!=null)this.ItemMouseHover(this,e);
}
protected internal virtual void OnItemMouseDown(ItemEventArgs e)
{
if(this.ItemMouseDown!=null)this.ItemMouseDown(this,e);
}
protected internal virtual void OnItemMouseUp(ItemEventArgs e)
{
// this.SelectedItem=e.Item;
if(this.ItemMouseUp!=null)this.ItemMouseUp(this,e);
}
protected internal virtual void OnItemMouseItemMouseLeave(ItemEventArgs e)
{
if(this.ItemMouseItemMouseLeave!=null)this.ItemMouseItemMouseLeave(this,e);
}
protected internal virtual void OnItemMouseEnter(ItemEventArgs e)
{
if(this.ItemMouseEnter!=null)this.ItemMouseEnter(this,e);
}
protected internal virtual void OnItemVisibleChanged(ItemEventArgs e)
{
this.update();
if(this.ItemVisibleChanged!=null)this.ItemVisibleChanged(this,e);
}
protected internal virtual void OnItemTextChanged(ItemEventArgs e)
{
this.Invalidate();
if(this.ItemTextChanged!=null)this.ItemTextChanged(this,e);
}
#endregion
#region override methods
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged (e);
this.update();
}
protected override void OnClick(EventArgs e)
{
base.OnClick (e);
GListViewItem item=this.GetMouseOnItem();
if(item!=null)
{
item.Expanded=!item.Expanded;
this.OnItemClicked(new ItemEventArgs(item));
// this.SelectedItem=item;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove (e);
this.Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.Select();
base.OnMouseDown (e);
GListViewItem item=this.GetMouseOnItem();
if(item!=null)
{
this.OnItemMouseDown(new ItemEventArgs(item));
this.SelectedItem=item;
}
this.Invalidate();
}
protected override void OnMouseHover(EventArgs e)
{
base.OnMouseHover (e);
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave (e);
this.Invalidate();
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp (e);
GListViewItem item=this.GetMouseOnItem();
if(item!=null)
this.OnItemMouseUp(new ItemEventArgs(item));
this.Invalidate();
}
protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel (e);
GListViewFolder folder=this.GetExpandedFolder();
if(folder!=null)
folder.OnMouseWheel(e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
foreach(GListViewFolder folder in this.Items)
{
try
{
folder.Paint(e.Graphics);
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.Assert(false,ex.Message);
}
}
/* e.Graphics.ResetClip();
Rectangle r=this.ClientRectangle;
r.Width-=2;
r.Height-=2;
e.Graphics.DrawRectangle(new Pen(Color.Blue),r);
r.Inflate(1,1);
e.Graphics.DrawRectangle(new Pen(Color.LightBlue),r);
r.Inflate(-2,-2);
e.Graphics.DrawRectangle(new Pen(Color.LightBlue),r);*/
}
// protected override void OnPaintBackground(PaintEventArgs pevent)
// {
// base.OnPaintBackground (pevent);
// Brush b=new System.Drawing.Drawing2D.LinearGradientBrush(this.InnerRectangle,Color.DarkOrange,Color.White,315,true);
// pevent.Graphics.FillRectangle(b,this.InnerRectangle);
// }
#endregion
public GListViewFolder GetExpandedFolder()
{
return (GListViewFolder)this.items[this.expandfolderindex];
/* foreach(GListViewFolder folder in this.Items)
{
if(folder.expanded)return folder;
}
return null;*/
}
#region
/*private GListViewDrawItemEventArgs CreateCurrentGListViewDrawItemEventArgs(GListViewItem item,DrawItemState state)
{
GListViewFolder folder=this.GetItemFolder(item);
Debug.Assert(folder!=null);
Graphics g=this.CreateGraphics();
g.SetClip(folder.Rect);
return new GListViewDrawItemEventArgs(g,
}*/
private GListViewItem GetMouseOnItem()
{
try
{
return this.GetItemAtPoint(this.GetMousePosition());
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.Assert(false,ex.Message);
return null;
}
}
public Point GetMousePosition()
{
return this.PointToClient(GListView.MousePosition);
}
public GListViewItem GetItemAtPoint(Point p)
{
bool contains=this.InnerRectangle.Contains(p);
if(!contains)return null;
foreach(GListViewFolder folder in this.Items)
{
if(folder.Rect.Contains(p))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -