001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Drawing;
005.
using
System.Data;
006.
using
System.Linq;
007.
using
System.Text;
008.
using
System.Windows.Forms;
009.
010.
namespace
TORServices.Form
011.
{
012.
public
partial
class
TextBoxOpendialogControl : UserControl
013.
{
014.
public
enum
SelectedPathType { colorDialog, folderBrowserDialog, fontDialog, openFileDialog, saveFileDialog }
015.
private
TextBox txtCode;
016.
private
Button btnCode;
017.
018.
public
string
Value
019.
{
020.
get
{
return
txtCode.Text; }
021.
}
022.
[System.ComponentModel.Browsable(
true
)]
023.
[System.ComponentModel.DefaultValue(
".."
)]
024.
[System.ComponentModel.Category(
"Behavior"
)]
025.
[System.ComponentModel.Description(
"OpenFileDialog is dispalyed and on success the contents of the Cell is replaced with the new file path."
)]
026.
public
string
ButtonCaption
027.
{
028.
029.
get
{
return
btnCode.Text; }
030.
set
031.
{
032.
btnCode.Text = value;
033.
}
034.
}
035.
private
bool
_selectFolder;
036.
[System.ComponentModel.Browsable(
true
)]
037.
[System.ComponentModel.DefaultValue(
false
)]
038.
[System.ComponentModel.Category(
"Behavior"
)]
039.
public
bool
selectFolder
040.
{
041.
get
{
return
_selectFolder; }
042.
set
{ _selectFolder = value; }
043.
}
044.
private
SelectedPathType _selected;
045.
[System.ComponentModel.Browsable(
true
)]
046.
047.
[System.ComponentModel.Category(
"Behavior"
)]
048.
public
SelectedPathType SelectedMode
049.
{
050.
get
{
return
_selected; }
051.
set
{ _selected = value; }
052.
}
053.
054.
[System.ComponentModel.Browsable(
true
)]
055.
[System.ComponentModel.DefaultValue(
null
)]
056.
[System.ComponentModel.Category(
"Behavior"
)]
057.
public
Image Image {
get
{
return
btnCode.Image; }
set
{ btnCode.Image = value; } }
058.
public
TextBoxOpendialogControl()
059.
{
060.
InitializeComponent();
061.
this
.txtCode =
new
TextBox();
062.
this
.Controls.Add(
this
.txtCode);
063.
this
.btnCode =
new
Button();
064.
this
.btnCode.Text =
".."
;
065.
btnCode.Dock = DockStyle.Right;
066.
txtCode.Dock = DockStyle.Fill;
067.
txtCode.ReadOnly =
true
;
068.
this
.btnCode.Click +=
new
EventHandler(btnCode_Click);
069.
this
.Controls.Add(
this
.btnCode);
070.
this
.renderControl();
071.
}
072.
073.
public
void
renderControl()
074.
{
075.
this
.btnCode.Width = 32;
076.
this
.btnCode.Height = 21;
077.
}
078.
079.
private
void
btnCode_Click(
object
sender, EventArgs e)
080.
{
081.
try
082.
{
083.
if
(_selected == SelectedPathType.folderBrowserDialog)
084.
{
085.
OpenFileDialog dialog =
new
OpenFileDialog();
086.
if
(dialog.ShowDialog() == DialogResult.OK)
087.
{
088.
089.
txtCode.Text = dialog.FileName.ToString();
090.
091.
}
092.
}
093.
else
if
(_selected == SelectedPathType.openFileDialog)
094.
{
095.
FolderBrowserDialog dialog =
new
FolderBrowserDialog();
096.
if
(dialog.ShowDialog() == DialogResult.OK)
097.
{
098.
txtCode.Text = dialog.SelectedPath;
099.
}
100.
}
101.
else
if
(_selected == SelectedPathType.colorDialog)
102.
{
103.
ColorDialog dialog =
new
ColorDialog();
104.
if
(dialog.ShowDialog() == DialogResult.OK)
105.
{
106.
txtCode.Text = dialog.Color.ToString() +
":"
107.
+ dialog.Color.Name.ToString()
108.
+
": A="
+ dialog.Color.A +
" R="
+ dialog.Color.R +
" G="
+ dialog.Color.G +
" B="
+ dialog.Color.B;
109.
}
110.
}
111.
else
if
(_selected == SelectedPathType.fontDialog)
112.
{
113.
FontDialog dialog =
new
FontDialog();
114.
if
(dialog.ShowDialog() == DialogResult.OK)
115.
{
116.
txtCode.Text = dialog.Font.ToString();
117.
}
118.
}
119.
else
if
(_selected == SelectedPathType.saveFileDialog)
120.
{
121.
SaveFileDialog dialog =
new
SaveFileDialog();
122.
if
(dialog.ShowDialog() == DialogResult.OK)
123.
{
124.
txtCode.Text = dialog.FileName;
125.
}
126.
}
127.
}
128.
catch
(Exception)
129.
{
130.
}
131.
}
132.
private
void
TextBoxButtonControl_Leave(
object
sender, EventArgs e)
133.
{
134.
try
135.
{
136.
this
.Visible =
false
;
137.
this
.txtCode.Text =
""
;
138.
}
139.
catch
(Exception)
140.
{
141.
}
142.
}
143.
}
144.
}