Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > จะเขียน Usercontrol ให้มี DataBindings เหมือน textbox ครับ



 

จะเขียน Usercontrol ให้มี DataBindings เหมือน textbox ครับ

 



Topic : 130934



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



22

เราต้องเพิ่มโค้ดไหนเข้าไปใน Usercontrol ของเราครับ



Tag : .NET, C#, VS 2013 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-04-28 10:04:49 By : lamaka.tor View : 759 Reply : 2
 

 

No. 1



โพสกระทู้ ( 4,436 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ทำได้แล้วครับ
แค่เปลี่ยนจากการ 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
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-04-30 09:23:10 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะเขียน Usercontrol ให้มี DataBindings เหมือน textbox ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่