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 > C# WinApp สอบถามเรื่อง การสร้าง Usercontrol กำหนด property ให้ Usercontrol แต่มันไม่จำค่าที่ใส่ครับ



 

C# WinApp สอบถามเรื่อง การสร้าง Usercontrol กำหนด property ให้ Usercontrol แต่มันไม่จำค่าที่ใส่ครับ

 



Topic : 124673



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



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



ผมการสร้าง Usercontrol ขึ้นมาแล้วกำหนด property ให้ Usercontrol แต่มันไม่จำค่าที่ใส่ครับ

E2

Code 1
Code (C#)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserControl_1
{
    class TextBoxOpendialogControl : UserControl
    {
        public enum SelectedPathType { SelectFolder, SelectFile }
        private TextBox txtCode;
        private Button btnCode;
        private string _path;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue(false)]
        [System.ComponentModel.Category("Behavior")]
        [System.ComponentModel.Description("OpenFileDialog is dispalyed and on success the contents of the Cell is replaced with the new file path.")]
        public string Path
        {

            get { return _path; }
            set
            {
                txtCode.Text = value;
            }
        }

        public TextBoxOpendialogControl()
        {
            this.txtCode = new TextBox();
            this.txtCode.TextChanged += new EventHandler(txtCode_TextChanged);
            this.Controls.Add(this.txtCode);
            this.btnCode = new Button();
            this.btnCode.Text = "..";
            this.btnCode.Click += new EventHandler(btnCode_Click);
            this.Controls.Add(this.btnCode);
            this.renderControl();
        }
        public void renderControl()
        {
            this.txtCode.Location = new Point(0, 0);
            this.txtCode.Width = this.Width + 115;
            this.txtCode.Height = this.Height;
            this.btnCode.Location = new Point(this.Width + 115, 0);
            this.btnCode.Width = 32;
            this.btnCode.Height = 21;
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.Name = "TextBoxButtonControl";
            this.Size = new System.Drawing.Size(267, 176);
            this.Leave += new System.EventHandler(this.TextBoxButtonControl_Leave);
            this.ResumeLayout(false);

        }
        private void txtCode_TextChanged(object sender, EventArgs e)
        {
            if (txtCode.Modified)
            {
                _path = txtCode.Text;
            }
        }



        private void btnCode_Click(object sender, EventArgs e)
        {
            //Form2 form2 = new Form2();
            //form2.ShowDialog();
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    txtCode.Text = dialog.FileName.ToString();
                }
                catch (Exception)
                {
                }
            }
        }
        private void TextBoxButtonControl_Leave(object sender, EventArgs e)
        {
            try
            {
                this.Visible = false;
                this.txtCode.Text = "";
            }
            catch (Exception)
            {
            }
        }
    }
}



Code 2
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UserControl_1
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
        private string _text;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue("")]
        [System.ComponentModel.Category("Behavior")]
        [System.ComponentModel.Description("Test User Control by TOR ")]
        public string TextCaption
        {
            get { return _text; }
            set
            {
                _text = value;
                textBox1.Text = value;
            }
        }
    }
}





Tag : .NET, Win (Windows App), C#, VS 2012 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-09-21 10:03:50 By : lamaka.tor View : 973 Reply : 2
 

 

No. 1



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



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

และแล้วก็สำเร็จ
เอามาให้เล่นกันครับ
TextBoxOpendialogControl แบบที่มีทั้ง colorDialog, folderBrowserDialog, fontDialog, openFileDialog, saveFileDialog

Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TORServices.Form
{
    public partial class TextBoxOpendialogControl : UserControl
    {
        public enum SelectedPathType { colorDialog, folderBrowserDialog, fontDialog, openFileDialog, saveFileDialog }
        private TextBox txtCode;
        private Button btnCode;

        public string Value
        {
            get { return txtCode.Text; }
        }
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue("..")]
        [System.ComponentModel.Category("Behavior")]
        [System.ComponentModel.Description("OpenFileDialog is dispalyed and on success the contents of the Cell is replaced with the new file path.")]
        public string ButtonCaption
        {

            get { return btnCode.Text; }
            set
            {
                btnCode.Text = value;
            }
        }
        private bool _selectFolder;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue(false)]
        [System.ComponentModel.Category("Behavior")]
        public bool selectFolder
        {
            get { return _selectFolder; }
            set { _selectFolder = value; }
        }
        private SelectedPathType _selected;
        [System.ComponentModel.Browsable(true)]
        //[System.ComponentModel.DefaultValue(SelectedPathType.SelectFile)]
        [System.ComponentModel.Category("Behavior")]
        public SelectedPathType SelectedMode
        {
            get { return _selected; }
            set { _selected = value; }
        }

        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DefaultValue(null)]
        [System.ComponentModel.Category("Behavior")]
        public Image Image { get { return btnCode.Image; } set { btnCode.Image = value; } }
        public TextBoxOpendialogControl()
        {
            InitializeComponent();
            this.txtCode = new TextBox();
            this.Controls.Add(this.txtCode);
            this.btnCode = new Button();
            this.btnCode.Text = "..";
            btnCode.Dock = DockStyle.Right;
            txtCode.Dock = DockStyle.Fill;
            txtCode.ReadOnly = true;
            this.btnCode.Click += new EventHandler(btnCode_Click);
            this.Controls.Add(this.btnCode);
            this.renderControl();
        }

        public void renderControl()
        {
            this.btnCode.Width = 32;
            this.btnCode.Height = 21;
        }

        private void btnCode_Click(object sender, EventArgs e)
        {
            try
            {
                if (_selected == SelectedPathType.folderBrowserDialog)
                {
                    OpenFileDialog dialog = new OpenFileDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {

                        txtCode.Text = dialog.FileName.ToString();

                    }
                }
                else if (_selected == SelectedPathType.openFileDialog)
                {
                    FolderBrowserDialog dialog = new FolderBrowserDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        txtCode.Text = dialog.SelectedPath;
                    }
                }
                else if (_selected == SelectedPathType.colorDialog)
                {
                    ColorDialog dialog = new ColorDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        txtCode.Text = dialog.Color.ToString() + ":"
                                       + dialog.Color.Name.ToString()
                                      + ": A=" + dialog.Color.A + " R=" + dialog.Color.R + " G=" + dialog.Color.G + " B=" + dialog.Color.B;
                    }
                }
                else if (_selected == SelectedPathType.fontDialog)
                {
                    FontDialog dialog = new FontDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        txtCode.Text = dialog.Font.ToString();
                    }
                }
                else if (_selected == SelectedPathType.saveFileDialog)
                {
                    SaveFileDialog dialog = new SaveFileDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        txtCode.Text = dialog.FileName;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        private void TextBoxButtonControl_Leave(object sender, EventArgs e)
        {
            try
            {
                this.Visible = false;
                this.txtCode.Text = "";
            }
            catch (Exception)
            {
            }
        }
    }
}








แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-09-21 11:37:34 By : lamaka.tor
 


 

No. 2



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



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

เพิ่มเติมอีกนิด
txtCode.BackColor = dialog.Color;//จะได้ดูสีที่เลือก

Code (C#)
else if (_selected == SelectedPathType.colorDialog)
                {
                    ColorDialog dialog = new ColorDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        txtCode.Text = dialog.Color.ToString() + ":"
                                       + dialog.Color.Name.ToString()
                                      + ": A=" + dialog.Color.A + " R=" + dialog.Color.R + " G=" + dialog.Color.G + " B=" + dialog.Color.B;
                        txtCode.BackColor = dialog.Color;
                    }
                }


แต่ตอนนี้ก็มาติดอีกว่า

จะหาวิธีให้ txtCode.ForeColor เป็นสีตัดกับ txtCode.BackColor ได้ยังไง
ปัญหามีกันต่อไปเรื่อย 555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-09-21 11:49:59 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# WinApp สอบถามเรื่อง การสร้าง Usercontrol กำหนด property ให้ Usercontrol แต่มันไม่จำค่าที่ใส่ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 02
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 อัตราราคา คลิกที่นี่