Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Import
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- using System.Windows.Forms;
- #endregion
- #region Copyright & Contact
- // Creator: Cheat Eye
- // CEO: Yassine Abbani
- // Link: https://www.facebook.com/yassineabbani
- // Version: 1.0.0
- #endregion
- #region FileBrowser
- [DefaultEvent("TextChanged")]
- public class Ce_FileBrowser : Control
- {
- #region Variables
- private TextBox BlueTB = new TextBox();
- private Button BrowseBTN = new Button();
- public OpenFileDialog Dialog;
- private string filter = @"All Files (*.*)|*.*";
- private int _maxchars = 32767;
- private bool _ReadOnly;
- private HorizontalAlignment ALNType;
- private Pen P1;
- private SolidBrush B1;
- private GraphicsPath Shape;
- #endregion
- #region Properties
- public HorizontalAlignment TextAlignment
- {
- get
- {
- return ALNType;
- }
- set
- {
- ALNType = value;
- Invalidate();
- }
- }
- public int MaxLength
- {
- get
- {
- return _maxchars;
- }
- set
- {
- _maxchars = value;
- BlueTB.MaxLength = MaxLength;
- Invalidate();
- }
- }
- public bool ReadOnly
- {
- get
- {
- return _ReadOnly;
- }
- set
- {
- _ReadOnly = value;
- if (BlueTB != null)
- {
- BlueTB.ReadOnly = value;
- }
- }
- }
- [Description("Default is: All Files (*.*)|*.*"), Category("Behavior")]
- public string Filter
- {
- get { return filter; }
- set
- {
- filter = value;
- Invalidate();
- }
- }
- #endregion
- #region EventArgs
- private void _Enter(object Obj, EventArgs e)
- {
- P1 = new Pen(Color.FromArgb(146, 192, 224));
- Refresh();
- }
- private void _Leave(object Obj, EventArgs e)
- {
- P1 = new Pen(Color.FromArgb(255, 172, 172));
- Refresh();
- }
- private void _OnKeyDown(object Obj, KeyEventArgs e)
- {
- if (e.Control && e.KeyCode == Keys.A)
- {
- BlueTB.SelectAll();
- e.SuppressKeyPress = true;
- }
- if (e.Control && e.KeyCode == Keys.C)
- {
- BlueTB.Copy();
- e.SuppressKeyPress = true;
- }
- }
- private void BrowseDown(object Obj, EventArgs e)
- {
- Dialog = new OpenFileDialog();
- Dialog.Filter = filter;
- DialogResult result = Dialog.ShowDialog();
- if (result == DialogResult.OK && Dialog.SafeFileName != null)
- {
- Text = Dialog.FileName;
- }
- }
- public void TextChngTxtBox(System.Object sender, System.EventArgs e)
- {
- Text = BlueTB.Text;
- }
- public void TextChng(System.Object sender, System.EventArgs e)
- {
- BlueTB.Text = Text;
- }
- protected override void OnTextChanged(System.EventArgs e)
- {
- base.OnTextChanged(e);
- Invalidate();
- }
- protected override void OnEnabledChanged(EventArgs e)
- {
- P1 = new Pen(Color.FromArgb(172, 172, 172));
- base.OnEnabledChanged(e);
- }
- protected override void OnForeColorChanged(System.EventArgs e)
- {
- base.OnForeColorChanged(e);
- BlueTB.ForeColor = ForeColor;
- Invalidate();
- }
- protected override void OnFontChanged(System.EventArgs e)
- {
- base.OnFontChanged(e);
- BlueTB.Font = Font;
- }
- protected override void OnResize(System.EventArgs e)
- {
- base.OnResize(e);
- Height = BlueTB.Height + 6;
- Shape = new GraphicsPath();
- Shape.AddArc(0, 0, 3, 3, 180, 90);
- Shape.AddArc(Width - 4, 0, 3, 3, -90, 90);
- Shape.AddArc(Width - 4, Height - 4, 3, 3, 0, 90);
- Shape.AddArc(0, Height - 4, 3, 3, 90, 90);
- Shape.CloseAllFigures();
- }
- protected override void OnGotFocus(System.EventArgs e)
- {
- base.OnGotFocus(e);
- BlueTB.Focus();
- }
- #endregion
- public void AddTextBox()
- {
- BlueTB.Location = new Point(3, 3);
- BlueTB.Size = new Size(140, 20);
- BlueTB.Text = Text;
- BlueTB.BorderStyle = BorderStyle.None;
- BlueTB.TextAlign = HorizontalAlignment.Left;
- BlueTB.Font = new Font("Tahoma", 10);
- BlueTB.Multiline = false;
- BlueTB.BackColor = Color.FromArgb(22, 44, 51);
- BlueTB.ForeColor = Color.FromArgb(138, 133, 133);
- BlueTB.ScrollBars = ScrollBars.None;
- BlueTB.KeyDown += _OnKeyDown;
- BlueTB.Enter += _Enter;
- BlueTB.Leave += _Leave;
- }
- public void AddButton()
- {
- BrowseBTN.Location = new Point(271, 4);
- BrowseBTN.Size = new Size(25, 15);
- BrowseBTN.Text = "...";
- BrowseBTN.FlatStyle = FlatStyle.Flat;
- BrowseBTN.FlatAppearance.BorderSize = 0;
- BrowseBTN.TextAlign = ContentAlignment.MiddleCenter;
- BrowseBTN.BackColor = Color.Transparent;
- BrowseBTN.ForeColor = Color.FromArgb(37, 150, 255);
- BrowseBTN.MouseDown += BrowseDown;
- }
- public Ce_FileBrowser()
- {
- SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- SetStyle(ControlStyles.UserPaint, true);
- AddButton();
- AddTextBox();
- Controls.Add(BrowseBTN);
- Controls.Add(BlueTB);
- P1 = new Pen(Color.FromArgb(172, 172, 172));
- B1 = new SolidBrush(Color.FromArgb(53, 78, 105));
- BackColor = Color.Transparent;
- ForeColor = Color.FromArgb(138, 133, 133);
- Text = null;
- Font = new Font("Tahoma", 10);
- Size = new Size(300, 20);
- DoubleBuffered = true;
- BlueTB.TextChanged += new EventHandler(TextChngTxtBox);
- base.TextChanged += new EventHandler(TextChng);
- }
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- base.OnPaint(e);
- Bitmap B = new Bitmap(Width, Height);
- Graphics G = Graphics.FromImage(B);
- G.SmoothingMode = SmoothingMode.AntiAlias;
- BlueTB.Width = Width - 35;
- BrowseBTN.Location = new Point(Width - 29, 4);
- Rectangle Rect = new Rectangle(BrowseBTN.Location.X - 1, BrowseBTN.Location.Y - 1, BrowseBTN.Width + 1, BrowseBTN.Height + 1);
- BlueTB.TextAlign = TextAlignment;
- G.Clear(Color.Transparent);
- G.FillPath(B1, Shape);
- G.DrawPath(P1, Shape);
- G.DrawRectangle(P1, Rect);
- G.DrawString("...", Font, new SolidBrush(Color.FromArgb(91, 110, 144)), Width - 25, 0);
- e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
- G.Dispose();
- B.Dispose();
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement