1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141:
| namespace MagererPlayer { public partial class FileExplorer : UserControl, IScrollable { private string _directory;
public float visiblePercent { get => scrollablePanel.visiblePercent; set => scrollablePanel.visiblePercent = value; } public int scrollValue { get => scrollablePanel.scrollValue; set => scrollablePanel.scrollValue = value; } public CustomScrollBar scrollBar { get => scrollablePanel.scrollBar; set => scrollablePanel.scrollBar = value; }
public string Directory { get => this._directory; set { if (System.IO.Directory.Exists(value)) { this._directory = value; GetDirectory(); this.textBoxUrl.Text = this._directory; } } }
public float ScrollSpeedMultiplier { get; set; }
public EventHandler OnDirectoryChanged = null; public EventHandler<FileSelectedEventArgs> OnFileSelected = null;
public FileExplorer() { InitializeComponent(); }
private void FileExplorer_Load(object sender, EventArgs e) { AdjustSize(); }
private void FileExplorer_Resize(object sender, EventArgs e) { AdjustSize(); }
private void AdjustSize() {
}
private void GetDirectory() { scrollablePanel.Clear(); System.Diagnostics.Trace.WriteLine(this.Directory);
int offset = System.IO.Directory.GetParent(this.Directory) != null ? 1 : 0;
int colCount = scrollablePanel.Width / 145; string[] dirs = System.IO.Directory.GetDirectories(new string(this.Directory.Where(c => !char.IsControl(c)).ToArray())); Array.Sort(dirs);
if (offset == 1) { DirectoryInfo parent = System.IO.Directory.GetParent(this.Directory); scrollablePanel.Controls.Add(GetExplorerItem(parent.FullName, "..", new Point(0, 0))); }
for (int i = 0; i < dirs.Length; i++) scrollablePanel.Controls.Add(GetExplorerItem(dirs[i], new DirectoryInfo(dirs[i]).Name, new Point(((i + offset) % colCount) * 145, (i + offset) / colCount * 115 + 10)));
offset += dirs.Length;
dirs = System.IO.Directory.GetFiles(new string(this.Directory.Where(c => !char.IsControl(c)).ToArray()), "*.mp4", SearchOption.TopDirectoryOnly); Array.Sort(dirs);
for (int i = 0; i < dirs.Length; i++) scrollablePanel.Controls.Add(GetExplorerItem(dirs[i], new FileInfo(dirs[i]).Name, new Point(((i + offset) % colCount) * 145, (i + offset) / colCount * 115 + 10)));
System.Diagnostics.Trace.WriteLine(scrollablePanel.Count); System.Diagnostics.Trace.WriteLine(scrollablePanel.VisibleControls); this.Invalidate(); }
private Panel GetExplorerItem(string path, string text, Point location) { BunifuImageButton bunifuImageButton = new BunifuImageButton(); Label label = new Label(); Panel panel = new Panel();
if (System.IO.Directory.Exists(path)) { bunifuImageButton.Image = Properties.Resources.folder; bunifuImageButton.Click += delegate (object sender, EventArgs e) { this.Directory = path; }; } else if (System.IO.File.Exists(path)) { bunifuImageButton.Image = Properties.Resources.video_1; } bunifuImageButton.ImageActive = null; bunifuImageButton.Location = new System.Drawing.Point(10, 0); bunifuImageButton.Name = "bunifuImageButton"; bunifuImageButton.Size = new System.Drawing.Size(125, 70); bunifuImageButton.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; bunifuImageButton.TabStop = false; bunifuImageButton.Zoom = 5; bunifuImageButton.Cursor = Cursors.Hand;
label.Font = new System.Drawing.Font("Century Gothic", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0); label.ForeColor = System.Drawing.Color.FromArgb(224, 224, 224); label.Name = "label"; label.Dock = DockStyle.Bottom; label.Size = new Size(145, 40); label.Text = text; label.TextAlign = ContentAlignment.MiddleCenter; label.AutoEllipsis = true;
panel.Controls.Add(bunifuImageButton); panel.Controls.Add(label); panel.Location = location; panel.Name = "panel"; panel.Size = new System.Drawing.Size(145, 110);
return panel; }
private void textBoxUrl_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) this.Directory = this.textBoxUrl.Text; } }
public class FileSelectedEventArgs : EventArgs { public FileInfo File { get; }
public FileSelectedEventArgs(string path) { File = new FileInfo(path); }
public FileSelectedEventArgs(FileInfo info) { File = info; } } } |