初始化版本
This commit is contained in:
10
tongxin/NetWorkHelper/UDP/Controls/ControlState.cs
Normal file
10
tongxin/NetWorkHelper/UDP/Controls/ControlState.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
internal enum ControlState
|
||||
{
|
||||
Normal,
|
||||
Hover,
|
||||
Pressed,
|
||||
Focused
|
||||
}
|
||||
}
|
||||
162
tongxin/NetWorkHelper/UDP/Controls/FileTansfersContainer.cs
Normal file
162
tongxin/NetWorkHelper/UDP/Controls/FileTansfersContainer.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public class FileTansfersContainer : Panel
|
||||
{
|
||||
private IFileTransfersItemText _fileTransfersItemText;
|
||||
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public IFileTransfersItemText FileTransfersItemText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._fileTransfersItemText == null)
|
||||
{
|
||||
this._fileTransfersItemText = new FileTransfersItemText();
|
||||
}
|
||||
return this._fileTransfersItemText;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._fileTransfersItemText = value;
|
||||
foreach (FileTransfersItem item in base.Controls)
|
||||
{
|
||||
item.FileTransfersText = this._fileTransfersItemText;
|
||||
}
|
||||
}
|
||||
}
|
||||
public FileTansfersContainer()
|
||||
{
|
||||
this.AutoScroll = true;
|
||||
}
|
||||
|
||||
private bool _isAutomaticShowHide = true;
|
||||
[Description("<22>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ؿؼ<D8BF>\r\n(trueΪ<65><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ؿؼ<D8BF>)")]
|
||||
public bool IsAutomaticShowHide
|
||||
{
|
||||
get { return _isAutomaticShowHide; }
|
||||
set { _isAutomaticShowHide = value; }
|
||||
}
|
||||
|
||||
public FileTransfersItem AddItem(string text, string fileName, Image image, long fileSize, FileTransfersItemStyle style)
|
||||
{
|
||||
FileTransfersItem item = new FileTransfersItem();
|
||||
item.Text = text;
|
||||
item.FileName = fileName;
|
||||
item.Image = image;
|
||||
item.FileSize = fileSize;
|
||||
item.Style = style;
|
||||
item.FileTransfersText = this.FileTransfersItemText;
|
||||
item.Dock = DockStyle.Top;
|
||||
base.SuspendLayout();
|
||||
base.Controls.Add(item);
|
||||
item.BringToFront();
|
||||
base.ResumeLayout(true);
|
||||
if (IsAutomaticShowHide)
|
||||
{
|
||||
base.Visible = base.Controls.Count > 0 ? true : false;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>FileTransfersItem<65>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="md5"><3E><><EFBFBD>ƣ<EFBFBD>MD5У<35><D0A3>ֵ<EFBFBD><D6B5></param>
|
||||
/// <param name="typetext"><3E>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>/<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD></param>
|
||||
/// <param name="fileName"><3E>ļ<EFBFBD>·<EFBFBD><C2B7></param>
|
||||
/// <param name="image"><3E>ļ<EFBFBD>ͼ<EFBFBD><CDBC></param>
|
||||
/// <param name="fileSize"><3E>ļ<EFBFBD><C4BC><EFBFBD>С</param>
|
||||
/// <param name="style"><3E>ļ<EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鿴<EFBFBD><E9BFB4>FileTransfersItemStyle<6C><65></param>
|
||||
/// <returns></returns>
|
||||
public FileTransfersItem AddItem(string md5, string typetext, string fileName, Image image, long fileSize, FileTransfersItemStyle style)
|
||||
{
|
||||
FileTransfersItem item = new FileTransfersItem();
|
||||
item.Name = md5;
|
||||
item.Text = typetext;
|
||||
item.FileName = fileName;
|
||||
item.Image = image;
|
||||
item.FileSize = fileSize;
|
||||
item.Style = style;
|
||||
item.FileTransfersText = this.FileTransfersItemText;
|
||||
item.Dock = DockStyle.Top;
|
||||
base.SuspendLayout();
|
||||
base.Controls.Add(item);
|
||||
item.BringToFront();
|
||||
base.ResumeLayout(true);
|
||||
if (IsAutomaticShowHide)
|
||||
{
|
||||
base.Visible = base.Controls.Count > 0 ? true : false;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
/// <summary>
|
||||
/// <20>Ƴ<EFBFBD><C6B3><EFBFBD>ӦFileTransfersItem
|
||||
/// </summary>
|
||||
/// <param name="item">FileTransfersItem</param>
|
||||
public void RemoveItem(FileTransfersItem item)
|
||||
{
|
||||
base.Controls.Remove(item);
|
||||
if (IsAutomaticShowHide)
|
||||
{
|
||||
base.Visible = base.Controls.Count > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>MD5<44><35>ֵ<EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD>Ӧ<EFBFBD>ؼ<EFBFBD>
|
||||
/// </summary>
|
||||
/// <param name="md5"></param>
|
||||
public void RemoveItem(string md5)
|
||||
{
|
||||
base.Controls.RemoveByKey(md5);
|
||||
if (IsAutomaticShowHide)
|
||||
{
|
||||
base.Visible = base.Controls.Count > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveItem(Predicate<FileTransfersItem> match)
|
||||
{
|
||||
FileTransfersItem itemRemove = null;
|
||||
foreach (FileTransfersItem item in base.Controls)
|
||||
{
|
||||
if (match(item))
|
||||
{
|
||||
itemRemove = item;
|
||||
}
|
||||
}
|
||||
base.Controls.Remove(itemRemove);
|
||||
if (IsAutomaticShowHide)
|
||||
{
|
||||
base.Visible = base.Controls.Count > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD>MD5У<35><D0A3>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>FileTransfersItem
|
||||
/// </summary>
|
||||
/// <param name="md5"></param>
|
||||
/// <returns></returns>
|
||||
public FileTransfersItem Search(string md5)
|
||||
{
|
||||
return base.Controls[md5] as FileTransfersItem;
|
||||
}
|
||||
public FileTransfersItem Search(Predicate<FileTransfersItem> match)
|
||||
{
|
||||
FileTransfersItem result;
|
||||
foreach (FileTransfersItem item in base.Controls)
|
||||
{
|
||||
if (match(item))
|
||||
{
|
||||
result = item;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
986
tongxin/NetWorkHelper/UDP/Controls/FileTransfersItem.cs
Normal file
986
tongxin/NetWorkHelper/UDP/Controls/FileTransfersItem.cs
Normal file
@@ -0,0 +1,986 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Text;
|
||||
using System.Windows.Forms;
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
public class FileTransfersItem : Control
|
||||
{
|
||||
private Image _image;
|
||||
private string _fileName;
|
||||
private long _fileSize;
|
||||
private long _totalTransfersSize;
|
||||
private FileTransfersItemStyle _style;
|
||||
private RoundStyle _roundStyle = RoundStyle.All;
|
||||
private int _radius = 8;
|
||||
private Color _baseColor = Color.FromArgb(191, 233, 255);
|
||||
private Color _borderColor = Color.FromArgb(118, 208, 225);
|
||||
private Color _progressBarTrackColor = Color.Gainsboro;
|
||||
private Color _progressBarBarColor = Color.FromArgb(191, 233, 255);
|
||||
private Color _progressBarBorderColor = Color.FromArgb(118, 208, 225);
|
||||
private Color _progressBarTextColor = Color.FromArgb(0, 95, 147);
|
||||
private int _interval = 1000;
|
||||
private IFileTransfersItemText _fileTransfersText;
|
||||
private DateTime _startTime = DateTime.Now;
|
||||
private System.Threading.Timer _timer;
|
||||
private ControlState _saveState;
|
||||
private ControlState _saveToState;
|
||||
private ControlState _refuseState;
|
||||
private ControlState _cancelState;
|
||||
private static readonly object EventSaveButtonClick = new object();
|
||||
private static readonly object EventSaveToButtonClick = new object();
|
||||
private static readonly object EventRefuseButtonClick = new object();
|
||||
private static readonly object EventCancelButtonClick = new object();
|
||||
public event EventHandler SaveButtonClick
|
||||
{
|
||||
add
|
||||
{
|
||||
base.Events.AddHandler(FileTransfersItem.EventSaveButtonClick, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
base.Events.RemoveHandler(FileTransfersItem.EventSaveButtonClick, value);
|
||||
}
|
||||
}
|
||||
public event EventHandler SaveToButtonClick
|
||||
{
|
||||
add
|
||||
{
|
||||
base.Events.AddHandler(FileTransfersItem.EventSaveToButtonClick, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
base.Events.RemoveHandler(FileTransfersItem.EventSaveToButtonClick, value);
|
||||
}
|
||||
}
|
||||
public event EventHandler RefuseButtonClick
|
||||
{
|
||||
add
|
||||
{
|
||||
base.Events.AddHandler(FileTransfersItem.EventRefuseButtonClick, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
base.Events.RemoveHandler(FileTransfersItem.EventRefuseButtonClick, value);
|
||||
}
|
||||
}
|
||||
public event EventHandler CancelButtonClick
|
||||
{
|
||||
add
|
||||
{
|
||||
base.Events.AddHandler(FileTransfersItem.EventCancelButtonClick, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
base.Events.RemoveHandler(FileTransfersItem.EventCancelButtonClick, value);
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Icon), "null")]
|
||||
public Image Image
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._image;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._image = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue("")]
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._fileName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._fileName = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue(0)]
|
||||
public long FileSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._fileSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._fileSize = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue(0)]
|
||||
public long TotalTransfersSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._totalTransfersSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._totalTransfersSize != value)
|
||||
{
|
||||
if (value > this._fileSize)
|
||||
{
|
||||
this._totalTransfersSize = this._fileSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._totalTransfersSize = value;
|
||||
}
|
||||
base.Invalidate(this.ProgressBarRect);
|
||||
base.Invalidate(this.TransfersSizeRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(FileTransfersItemStyle), "0")]
|
||||
public FileTransfersItemStyle Style
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._style;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._style = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(RoundStyle), "1")]
|
||||
public RoundStyle RoundStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._roundStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._roundStyle != value)
|
||||
{
|
||||
this._roundStyle = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
[DefaultValue(8)]
|
||||
public int Radius
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._radius;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._radius != value)
|
||||
{
|
||||
this._radius = ((value < 1) ? 1 : value);
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Color), "191, 233, 255")]
|
||||
public Color BaseColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._baseColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._baseColor = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Color), "118, 208, 225")]
|
||||
public Color BorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._borderColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._borderColor = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Color), "Gainsboro")]
|
||||
public Color ProgressBarTrackColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._progressBarTrackColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._progressBarTrackColor = value;
|
||||
base.Invalidate(this.ProgressBarRect);
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Color), "191, 233, 255")]
|
||||
public Color ProgressBarBarColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._progressBarBarColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._progressBarBarColor = value;
|
||||
base.Invalidate(this.ProgressBarRect);
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Color), "118, 208, 225")]
|
||||
public Color ProgressBarBorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._progressBarBorderColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._progressBarBorderColor = value;
|
||||
base.Invalidate(this.ProgressBarRect);
|
||||
}
|
||||
}
|
||||
[DefaultValue(typeof(Color), "0, 95, 147")]
|
||||
public Color ProgressBarTextColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._progressBarTextColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._progressBarTextColor = value;
|
||||
base.Invalidate(this.ProgressBarRect);
|
||||
}
|
||||
}
|
||||
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||
public IFileTransfersItemText FileTransfersText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._fileTransfersText == null)
|
||||
{
|
||||
this._fileTransfersText = new FileTransfersItemText();
|
||||
}
|
||||
return this._fileTransfersText;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._fileTransfersText = value;
|
||||
base.Invalidate();
|
||||
}
|
||||
}
|
||||
[DefaultValue(1000)]
|
||||
public int Interval
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._interval;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._interval = value;
|
||||
}
|
||||
}
|
||||
internal System.Threading.Timer Timer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._timer == null)
|
||||
{
|
||||
this._timer = new System.Threading.Timer(delegate (object obj)
|
||||
{
|
||||
if (!base.Disposing)
|
||||
{
|
||||
if (!base.Disposing)
|
||||
{
|
||||
base.BeginInvoke((MethodInvoker)delegate ()
|
||||
{
|
||||
base.Invalidate(this.SpeedRect);
|
||||
});
|
||||
}
|
||||
}
|
||||
}, null, -1, this._interval);
|
||||
//System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(timer_Elapsed), null, -1, this._interval);
|
||||
}
|
||||
return this._timer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal Rectangle ImageRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(6, 6, 32, 32);
|
||||
}
|
||||
}
|
||||
internal Rectangle TextRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(43, 6, base.Width - 49, 16);
|
||||
}
|
||||
}
|
||||
internal Rectangle FileNameRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(43, 22, base.Width - 49, 16);
|
||||
}
|
||||
}
|
||||
internal Rectangle ProgressBarRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(4, 41, base.Width - 8, 16);
|
||||
}
|
||||
}
|
||||
internal Rectangle SpeedRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(6, 60, base.Width / 2 - 8, 16);
|
||||
}
|
||||
}
|
||||
internal Rectangle TransfersSizeRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(base.Width / 2, 60, base.Width / 2 - 6, 16);
|
||||
}
|
||||
}
|
||||
internal Rectangle RefuseReceiveRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Size size = TextRenderer.MeasureText(this.FileTransfersText.RefuseReceive, this.Font);
|
||||
return new Rectangle(base.Width - size.Width - 7, 79, size.Width, size.Height);
|
||||
}
|
||||
}
|
||||
internal Rectangle CancelTransfersRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Size size = TextRenderer.MeasureText(this.FileTransfersText.CancelTransfers, this.Font);
|
||||
return new Rectangle(base.Width - size.Width - 7, 79, size.Width, size.Height);
|
||||
}
|
||||
}
|
||||
internal Rectangle SaveToRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Size size = TextRenderer.MeasureText(this.FileTransfersText.SaveTo, this.Font);
|
||||
return new Rectangle(this.RefuseReceiveRect.X - size.Width - 20, 79, size.Width, size.Height);
|
||||
}
|
||||
}
|
||||
internal Rectangle SaveRect
|
||||
{
|
||||
get
|
||||
{
|
||||
Size size = TextRenderer.MeasureText(this.FileTransfersText.Save, this.Font);
|
||||
return new Rectangle(this.SaveToRect.X - size.Width - 20, 79, size.Width, size.Height);
|
||||
}
|
||||
}
|
||||
protected override Size DefaultSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Size(200, 97);
|
||||
}
|
||||
}
|
||||
private ControlState SaveState
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._saveState;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._saveState != value)
|
||||
{
|
||||
this._saveState = value;
|
||||
base.Invalidate(this.Inflate(this.SaveRect));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ControlState SaveToState
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._saveToState;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._saveToState != value)
|
||||
{
|
||||
this._saveToState = value;
|
||||
base.Invalidate(this.Inflate(this.SaveToRect));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ControlState RefuseState
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._refuseState;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._refuseState != value)
|
||||
{
|
||||
this._refuseState = value;
|
||||
base.Invalidate(this.Inflate(this.RefuseReceiveRect));
|
||||
}
|
||||
}
|
||||
}
|
||||
private ControlState CancelState
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._cancelState;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this._cancelState != value)
|
||||
{
|
||||
this._cancelState = value;
|
||||
base.Invalidate(this.Inflate(this.CancelTransfersRect));
|
||||
}
|
||||
}
|
||||
}
|
||||
public FileTransfersItem()
|
||||
{
|
||||
this.SetStyles();
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
this._startTime = DateTime.Now;
|
||||
this.Timer.Change(this._interval, this._interval);
|
||||
}
|
||||
protected virtual void OnSaveButtonClick(EventArgs e)
|
||||
{
|
||||
EventHandler handler = base.Events[FileTransfersItem.EventSaveButtonClick] as EventHandler;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
protected virtual void OnSaveToButtonClick(EventArgs e)
|
||||
{
|
||||
EventHandler handler = base.Events[FileTransfersItem.EventSaveToButtonClick] as EventHandler;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
protected virtual void OnRefuseButtonClick(EventArgs e)
|
||||
{
|
||||
EventHandler handler = base.Events[FileTransfersItem.EventRefuseButtonClick] as EventHandler;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
protected virtual void OnCancelButtonClick(EventArgs e)
|
||||
{
|
||||
EventHandler handler = base.Events[FileTransfersItem.EventCancelButtonClick] as EventHandler;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, e);
|
||||
}
|
||||
}
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
Point point = e.Location;
|
||||
switch (this._style)
|
||||
{
|
||||
case FileTransfersItemStyle.Send:
|
||||
case FileTransfersItemStyle.Receive:
|
||||
if (this.CancelTransfersRect.Contains(point))
|
||||
{
|
||||
this.CancelState = ControlState.Hover;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.CancelState = ControlState.Normal;
|
||||
}
|
||||
break;
|
||||
case FileTransfersItemStyle.ReadyReceive:
|
||||
if (this.SaveRect.Contains(point))
|
||||
{
|
||||
this.SaveState = ControlState.Hover;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SaveState = ControlState.Normal;
|
||||
}
|
||||
if (this.SaveToRect.Contains(point))
|
||||
{
|
||||
this.SaveToState = ControlState.Hover;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SaveToState = ControlState.Normal;
|
||||
}
|
||||
if (this.RefuseReceiveRect.Contains(point))
|
||||
{
|
||||
this.RefuseState = ControlState.Hover;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.RefuseState = ControlState.Normal;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
Point point = e.Location;
|
||||
switch (this._style)
|
||||
{
|
||||
case FileTransfersItemStyle.Send:
|
||||
case FileTransfersItemStyle.Receive:
|
||||
if (this.CancelTransfersRect.Contains(point))
|
||||
{
|
||||
this.CancelState = ControlState.Pressed;
|
||||
}
|
||||
break;
|
||||
case FileTransfersItemStyle.ReadyReceive:
|
||||
if (this.SaveRect.Contains(point))
|
||||
{
|
||||
this.SaveState = ControlState.Pressed;
|
||||
}
|
||||
if (this.SaveToRect.Contains(point))
|
||||
{
|
||||
this.SaveToState = ControlState.Pressed;
|
||||
}
|
||||
if (this.RefuseReceiveRect.Contains(point))
|
||||
{
|
||||
this.RefuseState = ControlState.Pressed;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnMouseUp(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
Point point = e.Location;
|
||||
switch (this._style)
|
||||
{
|
||||
case FileTransfersItemStyle.Send:
|
||||
case FileTransfersItemStyle.Receive:
|
||||
if (this.CancelTransfersRect.Contains(point))
|
||||
{
|
||||
this.CancelState = ControlState.Hover;
|
||||
this.OnCancelButtonClick(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.CancelState = ControlState.Normal;
|
||||
}
|
||||
break;
|
||||
case FileTransfersItemStyle.ReadyReceive:
|
||||
if (this.SaveRect.Contains(point))
|
||||
{
|
||||
this.SaveState = ControlState.Hover;
|
||||
this.OnSaveButtonClick(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SaveState = ControlState.Normal;
|
||||
}
|
||||
if (this.SaveToRect.Contains(point))
|
||||
{
|
||||
this.SaveToState = ControlState.Hover;
|
||||
this.OnSaveToButtonClick(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SaveToState = ControlState.Normal;
|
||||
}
|
||||
if (this.RefuseReceiveRect.Contains(point))
|
||||
{
|
||||
this.RefuseState = ControlState.Hover;
|
||||
this.OnRefuseButtonClick(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.RefuseState = ControlState.Normal;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnMouseLeave(EventArgs e)
|
||||
{
|
||||
base.OnMouseLeave(e);
|
||||
switch (this._style)
|
||||
{
|
||||
case FileTransfersItemStyle.Send:
|
||||
case FileTransfersItemStyle.Receive:
|
||||
this.CancelState = ControlState.Normal;
|
||||
break;
|
||||
case FileTransfersItemStyle.ReadyReceive:
|
||||
this.SaveState = ControlState.Normal;
|
||||
this.SaveToState = ControlState.Normal;
|
||||
this.RefuseState = ControlState.Normal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaint(e);
|
||||
Graphics g = e.Graphics;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
g.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||
if (this.Image != null)
|
||||
{
|
||||
g.DrawImage(this.Image, this.ImageRect, new Rectangle(Point.Empty, this.Image.Size), GraphicsUnit.Pixel);
|
||||
}
|
||||
TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine;
|
||||
TextRenderer.DrawText(g, this.Text, this.Font, this.TextRect, this.ForeColor, flags);
|
||||
TextRenderer.DrawText(g, this.FileName, this.Font, this.FileNameRect, this.ForeColor, flags);
|
||||
Rectangle rect = this.ProgressBarRect;
|
||||
Color innerBorderColor = Color.FromArgb(200, 255, 255, 255);
|
||||
this.RenderBackgroundInternal(g, rect, this._progressBarTrackColor, this._progressBarBorderColor, innerBorderColor, RoundStyle.None, 0, 0.0f, false, false, LinearGradientMode.Vertical);
|
||||
if (this.FileSize != 0L)
|
||||
{
|
||||
float percent = (float)this.TotalTransfersSize / (float)this.FileSize;
|
||||
int width = (int)((float)rect.Width * percent);
|
||||
width = Math.Min(width, rect.Width - 2);
|
||||
if (width > 5)
|
||||
{
|
||||
Rectangle barRect = new Rectangle(rect.X + 1, rect.Y + 1, width, rect.Height - 2);
|
||||
this.RenderBackgroundInternal(g, barRect, this._progressBarBarColor, this._progressBarBarColor, innerBorderColor, RoundStyle.None, 0, 0.0f, false, false, LinearGradientMode.Vertical);
|
||||
}
|
||||
TextRenderer.DrawText(g, percent.ToString("0.0%"), this.Font, rect, this._progressBarTextColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
|
||||
string transferSizeText = string.Format("{0}/{1}", this.GetText((double)this._totalTransfersSize), this.GetText((double)this._fileSize));
|
||||
TextRenderer.DrawText(g, transferSizeText, this.Font, this.TransfersSizeRect, this.ForeColor, TextFormatFlags.Right | TextFormatFlags.VerticalCenter);
|
||||
if (this._totalTransfersSize != 0L && !base.DesignMode)
|
||||
{
|
||||
TextRenderer.DrawText(g, this.GetSpeedText(), this.Font, this.SpeedRect, this.ForeColor, TextFormatFlags.VerticalCenter);
|
||||
}
|
||||
}
|
||||
flags = (TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter | TextFormatFlags.SingleLine);
|
||||
switch (this._style)
|
||||
{
|
||||
case FileTransfersItemStyle.Send:
|
||||
case FileTransfersItemStyle.Receive:
|
||||
if (this.CancelState != ControlState.Normal)
|
||||
{
|
||||
rect = this.CancelTransfersRect;
|
||||
rect.Inflate(2, 2);
|
||||
this.RenderBackgroundInternal(g, rect, this._baseColor, this._borderColor, innerBorderColor, RoundStyle.None, this._radius, 0.0f, true, true, LinearGradientMode.Vertical);
|
||||
}
|
||||
TextRenderer.DrawText(g, this.FileTransfersText.CancelTransfers, this.Font, this.CancelTransfersRect, this.ForeColor, flags);
|
||||
break;
|
||||
case FileTransfersItemStyle.ReadyReceive:
|
||||
{
|
||||
bool drawBack = false;
|
||||
if (this.SaveState != ControlState.Normal)
|
||||
{
|
||||
rect = this.SaveRect;
|
||||
rect.Inflate(2, 2);
|
||||
drawBack = true;
|
||||
}
|
||||
if (this.SaveToState != ControlState.Normal)
|
||||
{
|
||||
rect = this.SaveToRect;
|
||||
rect.Inflate(2, 2);
|
||||
drawBack = true;
|
||||
}
|
||||
if (this.RefuseState != ControlState.Normal)
|
||||
{
|
||||
rect = this.RefuseReceiveRect;
|
||||
rect.Inflate(2, 2);
|
||||
drawBack = true;
|
||||
}
|
||||
if (drawBack)
|
||||
{
|
||||
this.RenderBackgroundInternal(g, rect, this._baseColor, this._borderColor, innerBorderColor, RoundStyle.None, this._radius, 0.45f, true, true, LinearGradientMode.Vertical);
|
||||
}
|
||||
TextRenderer.DrawText(g, this.FileTransfersText.RefuseReceive, this.Font, this.RefuseReceiveRect, this.ForeColor, flags);
|
||||
TextRenderer.DrawText(g, this.FileTransfersText.SaveTo, this.Font, this.SaveToRect, this.ForeColor, flags);
|
||||
TextRenderer.DrawText(g, this.FileTransfersText.Save, this.Font, this.SaveRect, this.ForeColor, flags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
base.OnPaintBackground(e);
|
||||
Graphics g = e.Graphics;
|
||||
Rectangle rect = base.ClientRectangle;
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
rect.Inflate(-1, -1);
|
||||
this.RenderBackgroundInternal(g, rect, this._baseColor, this._borderColor, Color.FromArgb(200, 255, 255), this._roundStyle, this._radius, 0.45f, true, false, LinearGradientMode.Vertical);
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (disposing)
|
||||
{
|
||||
if (this._timer != null)
|
||||
{
|
||||
this._timer.Dispose();
|
||||
}
|
||||
this._fileTransfersText = null;
|
||||
}
|
||||
}
|
||||
private void SetStyles()
|
||||
{
|
||||
base.SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.FixedHeight | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
|
||||
base.SetStyle(ControlStyles.Opaque, false);
|
||||
base.UpdateStyles();
|
||||
}
|
||||
internal void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, LinearGradientMode mode)
|
||||
{
|
||||
if (drawBorder)
|
||||
{
|
||||
rect.Width--;
|
||||
rect.Height--;
|
||||
}
|
||||
if (rect.Width > 0 && rect.Height > 0)
|
||||
{
|
||||
using (LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
|
||||
{
|
||||
Color[] colors = new Color[]
|
||||
{
|
||||
this.GetColor(baseColor, 0, 35, 24, 9),
|
||||
this.GetColor(baseColor, 0, 13, 8, 3),
|
||||
baseColor,
|
||||
this.GetColor(baseColor, 0, 68, 69, 54)
|
||||
};
|
||||
brush.InterpolationColors = new ColorBlend
|
||||
{
|
||||
Positions = new float[]
|
||||
{
|
||||
0f,
|
||||
basePosition,
|
||||
basePosition + 0.05f,
|
||||
1f
|
||||
},
|
||||
Colors = colors
|
||||
};
|
||||
if (style != RoundStyle.None)
|
||||
{
|
||||
using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
|
||||
{
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
if (baseColor.A > 80)
|
||||
{
|
||||
Rectangle rectTop = rect;
|
||||
if (mode == LinearGradientMode.Vertical)
|
||||
{
|
||||
rectTop.Height = (int)((float)rectTop.Height * basePosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectTop.Width = (int)((float)rect.Width * basePosition);
|
||||
}
|
||||
using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(rectTop, roundWidth, RoundStyle.Top, false))
|
||||
{
|
||||
using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
|
||||
{
|
||||
g.FillPath(brushAlpha, pathTop);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (drawGlass)
|
||||
{
|
||||
RectangleF glassRect = rect;
|
||||
if (mode == LinearGradientMode.Vertical)
|
||||
{
|
||||
glassRect.Y = (float)rect.Y + (float)rect.Height * basePosition;
|
||||
glassRect.Height = ((float)rect.Height - (float)rect.Height * basePosition) * 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
glassRect.X = (float)rect.X + (float)rect.Width * basePosition;
|
||||
glassRect.Width = ((float)rect.Width - (float)rect.Width * basePosition) * 2f;
|
||||
}
|
||||
this.DrawGlass(g, glassRect, 170, 0);
|
||||
}
|
||||
if (drawBorder)
|
||||
{
|
||||
using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
}
|
||||
rect.Inflate(-1, -1);
|
||||
using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
|
||||
{
|
||||
using (Pen pen = new Pen(innerBorderColor))
|
||||
{
|
||||
g.DrawPath(pen, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FillRectangle(brush, rect);
|
||||
if (baseColor.A > 80)
|
||||
{
|
||||
Rectangle rectTop = rect;
|
||||
if (mode == LinearGradientMode.Vertical)
|
||||
{
|
||||
rectTop.Height = (int)((float)rectTop.Height * basePosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectTop.Width = (int)((float)rect.Width * basePosition);
|
||||
}
|
||||
using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
|
||||
{
|
||||
g.FillRectangle(brushAlpha, rectTop);
|
||||
}
|
||||
}
|
||||
if (drawGlass)
|
||||
{
|
||||
RectangleF glassRect = rect;
|
||||
if (mode == LinearGradientMode.Vertical)
|
||||
{
|
||||
glassRect.Y = (float)rect.Y + (float)rect.Height * basePosition;
|
||||
glassRect.Height = ((float)rect.Height - (float)rect.Height * basePosition) * 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
glassRect.X = (float)rect.X + (float)rect.Width * basePosition;
|
||||
glassRect.Width = ((float)rect.Width - (float)rect.Width * basePosition) * 2f;
|
||||
}
|
||||
this.DrawGlass(g, glassRect, 200, 0);
|
||||
}
|
||||
if (drawBorder)
|
||||
{
|
||||
using (Pen pen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
rect.Inflate(-1, -1);
|
||||
using (Pen pen = new Pen(innerBorderColor))
|
||||
{
|
||||
g.DrawRectangle(pen, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DrawGlass(Graphics g, RectangleF glassRect, int alphaCenter, int alphaSurround)
|
||||
{
|
||||
this.DrawGlass(g, glassRect, Color.White, alphaCenter, alphaSurround);
|
||||
}
|
||||
private void DrawGlass(Graphics g, RectangleF glassRect, Color glassColor, int alphaCenter, int alphaSurround)
|
||||
{
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
path.AddEllipse(glassRect);
|
||||
using (PathGradientBrush brush = new PathGradientBrush(path))
|
||||
{
|
||||
brush.CenterColor = Color.FromArgb(alphaCenter, glassColor);
|
||||
brush.SurroundColors = new Color[]
|
||||
{
|
||||
Color.FromArgb(alphaSurround, glassColor)
|
||||
};
|
||||
brush.CenterPoint = new PointF(glassRect.X + glassRect.Width / 2f, glassRect.Y + glassRect.Height / 2f);
|
||||
g.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Color GetColor(Color colorBase, int a, int r, int g, int b)
|
||||
{
|
||||
int a2 = (int)colorBase.A;
|
||||
int r2 = (int)colorBase.R;
|
||||
int g2 = (int)colorBase.G;
|
||||
int b2 = (int)colorBase.B;
|
||||
if (a + a2 > 255)
|
||||
{
|
||||
a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = Math.Max(a + a2, 0);
|
||||
}
|
||||
if (r + r2 > 255)
|
||||
{
|
||||
r = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = Math.Max(r + r2, 0);
|
||||
}
|
||||
if (g + g2 > 255)
|
||||
{
|
||||
g = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
g = Math.Max(g + g2, 0);
|
||||
}
|
||||
if (b + b2 > 255)
|
||||
{
|
||||
b = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = Math.Max(b + b2, 0);
|
||||
}
|
||||
return Color.FromArgb(a, r, g, b);
|
||||
}
|
||||
private string GetText(double size)
|
||||
{
|
||||
string result;
|
||||
if (size < 1024.0)
|
||||
{
|
||||
result = string.Format("{0} B", size.ToString("f1"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (size < 1048576.0)
|
||||
{
|
||||
result = string.Format("{0} KB", (size / 1024.0).ToString("f1"));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = string.Format("{0} MB", (size / 1048576.0).ToString("f1"));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private string GetSpeedText()
|
||||
{
|
||||
TimeSpan span = DateTime.Now - this._startTime;
|
||||
double speed = (double)this._totalTransfersSize / span.TotalSeconds;
|
||||
return string.Format("{0}/s", this.GetText(speed));
|
||||
}
|
||||
private Rectangle Inflate(Rectangle rect)
|
||||
{
|
||||
rect.Inflate(2, 2);
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
tongxin/NetWorkHelper/UDP/Controls/FileTransfersItemStyle.cs
Normal file
21
tongxin/NetWorkHelper/UDP/Controls/FileTransfersItemStyle.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// <20>ļ<EFBFBD>״̬
|
||||
/// </summary>
|
||||
public enum FileTransfersItemStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
/// </summary>
|
||||
Send,
|
||||
/// <summary>
|
||||
/// <><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
/// </summary>
|
||||
ReadyReceive,
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
/// </summary>
|
||||
Receive
|
||||
}
|
||||
}
|
||||
34
tongxin/NetWorkHelper/UDP/Controls/FileTransfersItemText.cs
Normal file
34
tongxin/NetWorkHelper/UDP/Controls/FileTransfersItemText.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
internal class FileTransfersItemText : IFileTransfersItemText
|
||||
{
|
||||
public string Save
|
||||
{
|
||||
get
|
||||
{
|
||||
return "接收";
|
||||
}
|
||||
}
|
||||
public string SaveTo
|
||||
{
|
||||
get
|
||||
{
|
||||
return "另存为...";
|
||||
}
|
||||
}
|
||||
public string RefuseReceive
|
||||
{
|
||||
get
|
||||
{
|
||||
return "拒绝";
|
||||
}
|
||||
}
|
||||
public string CancelTransfers
|
||||
{
|
||||
get
|
||||
{
|
||||
return "取消";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
tongxin/NetWorkHelper/UDP/Controls/GraphicsPathHelper.cs
Normal file
47
tongxin/NetWorkHelper/UDP/Controls/GraphicsPathHelper.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
public static class GraphicsPathHelper
|
||||
{
|
||||
public static GraphicsPath CreatePath(Rectangle rect, int radius, RoundStyle style, bool correction)
|
||||
{
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
int radiusCorrection = correction ? 1 : 0;
|
||||
switch (style)
|
||||
{
|
||||
case RoundStyle.None:
|
||||
path.AddRectangle(rect);
|
||||
break;
|
||||
case RoundStyle.All:
|
||||
path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
|
||||
path.AddArc(rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270f, 90f);
|
||||
path.AddArc(rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0f, 90f);
|
||||
path.AddArc(rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90f, 90f);
|
||||
break;
|
||||
case RoundStyle.Left:
|
||||
path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
|
||||
path.AddLine(rect.Right - radiusCorrection, rect.Y, rect.Right - radiusCorrection, rect.Bottom - radiusCorrection);
|
||||
path.AddArc(rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90f, 90f);
|
||||
break;
|
||||
case RoundStyle.Right:
|
||||
path.AddArc(rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270f, 90f);
|
||||
path.AddArc(rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0f, 90f);
|
||||
path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y);
|
||||
break;
|
||||
case RoundStyle.Top:
|
||||
path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
|
||||
path.AddArc(rect.Right - radius - radiusCorrection, rect.Y, radius, radius, 270f, 90f);
|
||||
path.AddLine(rect.Right - radiusCorrection, rect.Bottom - radiusCorrection, rect.X, rect.Bottom - radiusCorrection);
|
||||
break;
|
||||
case RoundStyle.Bottom:
|
||||
path.AddArc(rect.Right - radius - radiusCorrection, rect.Bottom - radius - radiusCorrection, radius, radius, 0f, 90f);
|
||||
path.AddArc(rect.X, rect.Bottom - radius - radiusCorrection, radius, radius, 90f, 90f);
|
||||
path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y);
|
||||
break;
|
||||
}
|
||||
path.CloseFigure();
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
tongxin/NetWorkHelper/UDP/Controls/IFileTransfersItemText.cs
Normal file
22
tongxin/NetWorkHelper/UDP/Controls/IFileTransfersItemText.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
public interface IFileTransfersItemText
|
||||
{
|
||||
string Save
|
||||
{
|
||||
get;
|
||||
}
|
||||
string SaveTo
|
||||
{
|
||||
get;
|
||||
}
|
||||
string RefuseReceive
|
||||
{
|
||||
get;
|
||||
}
|
||||
string CancelTransfers
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
tongxin/NetWorkHelper/UDP/Controls/RoundStyle.cs
Normal file
12
tongxin/NetWorkHelper/UDP/Controls/RoundStyle.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
public enum RoundStyle
|
||||
{
|
||||
None,
|
||||
All,
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom
|
||||
}
|
||||
}
|
||||
37
tongxin/NetWorkHelper/UDP/Controls/TraFransfersFile.cs
Normal file
37
tongxin/NetWorkHelper/UDP/Controls/TraFransfersFile.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
[Serializable]
|
||||
public class TraFransfersFile
|
||||
{
|
||||
private string _md5;
|
||||
private int _index;
|
||||
private byte[] _buffer;
|
||||
|
||||
public TraFransfersFile(string md5, int index, byte[] buffer)
|
||||
{
|
||||
_md5 = md5;
|
||||
_index = index;
|
||||
_buffer = buffer;
|
||||
}
|
||||
|
||||
public string MD5
|
||||
{
|
||||
get { return _md5; }
|
||||
set { _md5 = value; }
|
||||
}
|
||||
|
||||
public int Index
|
||||
{
|
||||
get { return _index; }
|
||||
set { _index = value; }
|
||||
}
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get { return _buffer; }
|
||||
set { _buffer = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
123
tongxin/NetWorkHelper/UDP/Controls/TraFransfersFileControl.resx
Normal file
123
tongxin/NetWorkHelper/UDP/Controls/TraFransfersFileControl.resx
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
68
tongxin/NetWorkHelper/UDP/Controls/TraFransfersFileStart.cs
Normal file
68
tongxin/NetWorkHelper/UDP/Controls/TraFransfersFileStart.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace NetWorkHelper
|
||||
{
|
||||
[Serializable]
|
||||
public class TraFransfersFileStart
|
||||
{
|
||||
private string _md5;
|
||||
private string _fileName;
|
||||
private Image _image;
|
||||
private long _length;
|
||||
private long _partCount;
|
||||
private int _partSize;
|
||||
|
||||
public TraFransfersFileStart(
|
||||
string md5,
|
||||
string fileName,
|
||||
Image image,
|
||||
long length,
|
||||
long partCount,
|
||||
int partSize)
|
||||
{
|
||||
_md5 = md5;
|
||||
_fileName = fileName;
|
||||
_image = image;
|
||||
_length = length;
|
||||
_partCount = partCount;
|
||||
_partSize = partSize;
|
||||
}
|
||||
|
||||
public string MD5
|
||||
{
|
||||
get { return _md5; }
|
||||
set { _md5 = value; }
|
||||
}
|
||||
|
||||
public Image Image
|
||||
{
|
||||
get { return _image; }
|
||||
set { _image = value; }
|
||||
}
|
||||
|
||||
public string FileName
|
||||
{
|
||||
get { return _fileName; }
|
||||
set { _fileName = value; }
|
||||
}
|
||||
|
||||
public long Length
|
||||
{
|
||||
get { return _length; }
|
||||
set { _length = value; }
|
||||
}
|
||||
|
||||
public long PartCount
|
||||
{
|
||||
get { return _partCount; }
|
||||
set { _partCount = value; }
|
||||
}
|
||||
|
||||
public int PartSize
|
||||
{
|
||||
get { return _partSize; }
|
||||
set { _partSize = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user