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 > สอบถามเรื่องวิธีการเพิ่ม object ในฟรอม กับการใช้งานชื่อ object หลายๆอันในฟั่งชั่น ครับ



 

สอบถามเรื่องวิธีการเพิ่ม object ในฟรอม กับการใช้งานชื่อ object หลายๆอันในฟั่งชั่น ครับ

 



Topic : 128091



โพสกระทู้ ( 21 )
บทความ ( 0 )



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




สอบถามเรื่องวิธีการเพิ่ม object ในฟรอม กับการใช้งานชื่อ object หลายๆอันในฟั่งชั่น ครับ

1 )เช่น ผมลาก button1 มาวาง แล้วรันโปรแกรม อยากจะเขียน event ให้ button1 มันคลิกแล้วสร้าง button อีกอันขึ้นมาครับ


momo

จากรูป ผมสร้าง ช่องนึงเป็นโต๊ะ ภายในนั้นมี ปุ่ม 3 ปุ่มกับ label 3 อัน อยากเขียนฟังชั่นในการ เพิ่มโต๊ะ ครับ คือมันจะเพิ่ม ปุ่มใหม่อีก 3 และ label อีก 3

2) อยากทราบวิธีการเขียนฟั่งชั่นให้ รับค่าเป็นชื่อ ปุ่มหรือชื่อ panel มาใช้งานกับคำสั่งครับ

เช่น ผมมี label หลายอัน อยากใช้ฟังชั่นในการกำหนดการทำงานของมันครับ

สิ่งที่ทำเป็น
private void changetext (){

label1.text=(" ข้อความ ");

}

สิ่งที่อยากได้ ปล.ในวงเล็บหลังชื่อฟั่งชั่นนี้คือสิ่งที่มันจะรับค่าใช่ไหมครับ
private void changetext (label?){

label?.text=(" ข้อความ ");

}



Tag : .NET, Ms SQL Server 2014, Win (Windows App), VB.NET, C#, Windows









ประวัติการแก้ไข
2017-06-24 20:53:06
2017-06-24 21:20:16
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-06-24 20:49:09 By : gazutumn View : 782 Reply : 3
 

 

No. 1



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



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

ทำเป็น Usercontrol ครับ
คร่าวก็ประมาณนี้ครับ

Code (C#)
public partial class PanelTable : UserControl
    {
        public PanelTable()
        {
            InitializeComponent();
        }
    }
 partial class PanelTable
    {
        /// <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.button1 = new System.Windows.Forms.Button();
            this.lblTime = new System.Windows.Forms.Label();
            this.lblCusCount = new System.Windows.Forms.Label();
            this.lblTable = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(105, 10);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(39, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "+";
            this.button1.UseVisualStyleBackColor = true;
            // 
            // lblTime
            // 
            this.lblTime.AutoSize = true;
            this.lblTime.Location = new System.Drawing.Point(12, 10);
            this.lblTime.Name = "lblTime";
            this.lblTime.Size = new System.Drawing.Size(35, 13);
            this.lblTime.TabIndex = 1;
            this.lblTime.Text = "label1";
            // 
            // lblCusCount
            // 
            this.lblCusCount.AutoSize = true;
            this.lblCusCount.Location = new System.Drawing.Point(12, 29);
            this.lblCusCount.Name = "lblCusCount";
            this.lblCusCount.Size = new System.Drawing.Size(35, 13);
            this.lblCusCount.TabIndex = 2;
            this.lblCusCount.Text = "label2";
            // 
            // lblTable
            // 
            this.lblTable.AutoSize = true;
            this.lblTable.Location = new System.Drawing.Point(12, 53);
            this.lblTable.Name = "lblTable";
            this.lblTable.Size = new System.Drawing.Size(35, 13);
            this.lblTable.TabIndex = 3;
            this.lblTable.Text = "label3";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(150, 10);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(39, 23);
            this.button2.TabIndex = 4;
            this.button2.Text = "-";
            this.button2.UseVisualStyleBackColor = true;
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(105, 48);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(84, 23);
            this.button3.TabIndex = 5;
            this.button3.Text = "Cal";
            this.button3.UseVisualStyleBackColor = true;
            // 
            // PanelTable
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.lblTable);
            this.Controls.Add(this.lblCusCount);
            this.Controls.Add(this.lblTime);
            this.Controls.Add(this.button1);
            this.Name = "PanelTable";
            this.Size = new System.Drawing.Size(191, 74);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label lblTime;
        private System.Windows.Forms.Label lblCusCount;
        private System.Windows.Forms.Label lblTable;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
    }


เพิ่ม property,event แล้วก็ลากวางๆๆๆ ได้เลย ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-06-24 23:56:22 By : lamaka.tor
 


 

No. 2



โพสกระทู้ ( 21 )
บทความ ( 0 )



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : lamaka.tor เมื่อวันที่ 2017-06-24 23:56:22
รายละเอียดของการตอบ ::

ผมลองก๊อปโคตไปรันดูแล้ว มันเพิ่มได้ อันเดียวอะครับ อยากให้มันเพิ่มได้เรื่องๆ จารผมสั่งมาแบบนั้นครับ

ผมยังไม่ค่อยเข้าใจมันทำงานยังไงครับ ช่วยทีครับ

this.button1 = new System.Windows.Forms.Button(); อันนี้ สร้างให้ "button1" มัน = เป็นตัวแทนของ button ในฟรอมนี้ใช้ไหมครับ
หรือว่า สร้างให้มันเป็นตัวแปล ที่ทำหน้าที่แทน object ครับ


this.button1.Location = new System.Drawing.Point(105, 10); อันนี้น่าจะเกี่ยวกับตำแหน่ง

this.button1.Name = "button1"; อันนี้ใส่ชื่อปุ่ม ที่เป็น objectใช่ไหมครับ อย่างปุ่ม button7

this.button1.Size = new System.Drawing.Size(39, 23); อันนี้ขนาด
this.button1.TabIndex = 0;
this.button1.Text = "+";
this.button1.UseVisualStyleBackColor = true;

อันอื่นด้วยครับ






ประวัติการแก้ไข
2017-06-25 00:51:10
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-06-25 00:41:40 By : gazutumn
 

 

No. 3



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



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

ตอบความคิดเห็นที่ : 2 เขียนโดย : gazutumn เมื่อวันที่ 2017-06-25 00:41:40
รายละเอียดของการตอบ ::
โค้ดที่ให้ไปยังไม่เกี่ยวกับ การเพิ่มโต๊ะ นะครับ
แนะนำว่า ควรจะมี panel สำหรับจัดการหน้านี้ ครับ

การเพิ่มโต๊ะ ขณะ รันโปรแกรม มี 2 แบบ คือ

1. Add Control มาใหม่ ซึ่งต้อง กำหนด size,Position ของตัวที่จะ Add มาให้เหมาะสม
2. เพิ่มไว้ตั้งแต่ตอน design แล้ว Visible = false พอเรา Add ก็แค่ Visible = true

ทั้ง 2 วิธี ควรใส่ไว้ใน panel เพราะจะมี scrollbar เลื่อนดูได้ง่าย

แต่ส่วนใหญ่ ถ้าโปรแกรมร้านอาหาร จะมีการกำหนดโต๊ะไว้ตั้งแต่แรกอยู่แล้วว่าที่ร้านมีกี่โตะ เพื่อสะดวกในการจัดการครับ
ลูกค้ามา หรือจอง ก็แค่เปิดโต๊ะ แค่นั้นเอง และลูกค้ายัวสามารถเลือกนั่งโต๊ะไหนก็ได้ แล้วยังต้องเผื่อการรวมโตะด้วยครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-06-25 11:33:38 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

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