Guest User

Untitled

a guest
Jun 24th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp1
  12. {
  13.     public partial class FileTextBox : UserControl
  14.     {
  15.         public string Path { get; set; }
  16.  
  17.         private TextBox tbPath;
  18.         private Button btnSelect;
  19.  
  20.         public FileTextBox()
  21.         {
  22.             InitializeComponent();
  23.             tbPath = new TextBox() { Dock = DockStyle.Fill, Location = new Point(0,0) };
  24.             btnSelect = new Button { Dock = DockStyle.Right, Text = "...", Width=25 };
  25.             btnSelect.Click += BtnSelect_Click;
  26.             this.Controls.Add(tbPath);
  27.             this.Controls.Add(btnSelect);
  28.         }
  29.  
  30.         private void BtnSelect_Click(object sender, EventArgs e)
  31.         {
  32.             OpenFileDialog ofd = new OpenFileDialog();
  33.             var result = ofd.ShowDialog();
  34.             if(result == DialogResult.OK)
  35.             {
  36.                 tbPath.Text = ofd.FileName;
  37.             }
  38.         }      
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment