|
|
|
จะเขียน Usercontrol ให้มี DataBindings เหมือน textbox ครับ |
|
|
|
|
|
|
|
ทำได้แล้วครับ
แค่เปลี่ยนจากการ Inheritance Usercontrol เป็น control ก็ได้เลยครับ
ได้ control ใหม่มาใช้อีกตัว
LinkDialog ครับ
Code (C#)
namespace TORServices.FormsTor.Textbox
{
partial class LinkDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this._btn = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this._lnk = new System.Windows.Forms.LinkLabel();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// _btn
//
this._btn.Dock = System.Windows.Forms.DockStyle.Right;
this._btn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this._btn.Image = Properties.Resources.finds;
this._btn.Location = new System.Drawing.Point(361, 0);
this._btn.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this._btn.Name = "_btn";
this._btn.Size = new System.Drawing.Size(32, 25);
this._btn.TabIndex = 0;
this._btn.UseVisualStyleBackColor = true;
this._btn.Click += new System.EventHandler(this._btn_Click);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this._lnk);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(361, 25);
this.panel1.TabIndex = 1;
//
// _lnk
//
this._lnk.AutoSize = true;
this._lnk.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this._lnk.Location = new System.Drawing.Point(2, 2);
this._lnk.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this._lnk.Name = "_lnk";
this._lnk.Size = new System.Drawing.Size(74, 15);
this._lnk.TabIndex = 0;
this._lnk.TabStop = true;
this._lnk.Text = "linkLabel1";
this._lnk.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this._lnk_LinkClicked);
//
// LinkDialog
//
this.Controls.Add(this.panel1);
this.Controls.Add(this._btn);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
this.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.Name = "LinkDialog";
this.Size = new System.Drawing.Size(393, 25);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button _btn;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.LinkLabel _lnk;
}
public partial class LinkDialog : Control
{
public string FullPath { get { return _Path + "\\" + this.Text; } }
public LinkDialog()
{
InitializeComponent();
}
#region Focus overrides
protected override void OnBackColorChanged(EventArgs e)
{
base.OnBackColorChanged(e);
panel1.BackColor = this.BackColor;
}
protected override void OnFontChanged(EventArgs e)
{
base.OnFontChanged(e);
_lnk.Font = this.Font;
}
public override string Text
{
get
{
return this._lnk.Text;
}
set
{
this._lnk.Text = value;
}
}
[Localizable(true)]
public Size SizeButton
{
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
get
{
return this._btn.Size;
}
set
{
_btn.Size = value; Invalidate();
}
}
[Localizable(true)]
public Image ImageButton
{
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
get
{
return _btn.Image;
}
set
{
_btn.Image = value; Invalidate();
}
}
[Localizable(true)]
public string TextButton
{
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
get
{
return _btn.Text;
}
set
{
_btn.Text = value; Invalidate();
}
}
public event EventHandler ButtonClick
{
add { _btn.Click += value; }
remove { _btn.Click -= value; }
}
public event EventHandler ButtonDoubleClick
{
add { _btn.DoubleClick += value; }
remove { _btn.DoubleClick -= value; }
}
public event EventHandler TextBoxTextChanged
{
add { _lnk.TextChanged += value; }
remove { _lnk.TextChanged -= value; }
}
public event EventHandler TextBoxDoubleClick
{
add { _lnk.DoubleClick += value; }
remove { _lnk.DoubleClick -= value; }
}
public event EventHandler TextBoxClick
{
add { _lnk.Click += value; }
remove { _lnk.Click -= value; }
}
private string _Path = @"C:";
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
[System.ComponentModel.Category("TOR Setting")]
[System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new path.")]
public string Directory
{
get
{
return _Path;
}
set
{
_Path = value;
}
}
#endregion
private void _lnk_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
/* try
{*/
if (_lnk.Links.Count > 0)
{
MessageBox.Show(FullPath);
if (System.IO.File.Exists(FullPath))
{
System.Diagnostics.Process.Start(FullPath);
}
else
{
MessageBox.Show("File Not Found"); return;
}
}
/* }
catch (Exception ex)
{
throw new ArgumentException("Link error!", ex);
}*/
}
private void _btn_Click(object sender, EventArgs e)
{
try
{
string directory = (string.IsNullOrEmpty(Directory)) ? Application.StartupPath : Directory.Replace("AppPath", Application.StartupPath);
OpenFileDialog dialog = new OpenFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
SaveFileDialog dialog1 = new SaveFileDialog();
dialog1.InitialDirectory = (!string.IsNullOrEmpty(directory)) ? directory : "";
dialog1.FileName = System.IO.Path.GetFileName(dialog.FileName);
if (dialog1.ShowDialog() == DialogResult.OK)
{
if (dialog.FileName != dialog1.FileName)
System.IO.File.Copy(dialog.FileName, dialog1.FileName, true);
this.Text = System.IO.Path.GetFileName(dialog1.FileName);
}
}
}
catch (Exception)
{
}
}
}
}
|
|
|
|
|
Date :
2018-04-28 10:19:08 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2018-04-30 09:23:10 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|