推 GoalBased: 有完整一點的程式碼嗎 01/19 11:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Button btn1 = new Button();
btn1.Text = "1";
btn1.SetBounds(30, 170, 30, 30);
Controls.Add(btn1);
TextBox result = new TextBox();
Controls.Add(result);
btn1.Click += new System.EventHandler(btn1_Click);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn1_Click(object sender, EventArgs e)
{
result.text="1";//找不到result
}
}
}
已補上,拜託大家了
※ 編輯: a0960330 (220.130.225.223), 01/19/2015 11:14:50
推 wheattea: TextBox result 不要寫在Form1()裡 Btn_click找不到的 01/19 11:56
不然應該寫在哪裏?想把他寫在外面當全域變數好像也不行......大大給個指點吧
※ 編輯: a0960330 (220.130.225.223), 01/19/2015 12:10:37
→ CiC: 看錯了XD 你有綁了。那Click方法可以取出sender轉型TextBox 01/19 12:55
推 soup514: controls.find 01/19 12:59
推 CrazyAngel: 如果你控制項用拉的,可以發現designer也是將控制項 01/19 16:14
→ CrazyAngel: 宣告在最外層 01/19 16:15
謝謝大家,問題解決了!
※ 編輯: a0960330 (36.224.71.227), 01/20/2015 21:35:28