先谢谢大家 不过还是不行呀UserControl1代码 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 WindowsFormsApplication2 { public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public string a { get; set; } private void button1_Click(object sender, EventArgs e) { textBox1.Text = a; } } } form1代码 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 WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } UserControl1 my = new UserControl1(); private void button1_Click(object sender, EventArgs e) { my.a = "aaa"; } } } 大家帮忙看看哪不对啊?
public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public string str; private void button1_Click(object sender, EventArgs e) { textBox1.Text = str; } }public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); } UserControl1 uc = new UserControl1(); void Form1_Load(object sender, EventArgs e) { uc.Left = 100; uc.Top = 100; this.Controls.Add(uc); } private void button1_Click(object sender, EventArgs e) { uc.str = "test"; //uc.Invalidate(); } }
UserControl1 uc = new UserControl1();
uc.str = "ssss";
{
public string Text{get;set;}
}在FORM1中:
UserControl1 uc1=new UserControl();
uc1.Text="123";
{
private string a;
public UserControl1()
{
a="";
}
public string A
{
set{a=value;}
get{return a;}
}
}
UserControl1 u=new UserControl1()
u.A="";
如果uc1调用父类窗体,可以在uc1的构造窗体里边加上父类。
UserControl1 uc1=new UserControl(parentForm)
这样控件也可以使用父类的值了。需要什么值,加上个属性就可以了!!
UserControl1string m_key;
Public void a(string key)
{
m_key=key;
}FormUserControl1 uc1=new UserControl();
uc1.a("arg");
不过还是不行呀UserControl1代码
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 WindowsFormsApplication2
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
} public string a { get; set; } private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = a;
}
}
}
form1代码
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} UserControl1 my = new UserControl1(); private void button1_Click(object sender, EventArgs e)
{
my.a = "aaa";
}
}
}
大家帮忙看看哪不对啊?
{
public UserControl1()
{
InitializeComponent();
}
public string str;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = str;
}
}public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
UserControl1 uc = new UserControl1();
void Form1_Load(object sender, EventArgs e)
{
uc.Left = 100;
uc.Top = 100;
this.Controls.Add(uc);
} private void button1_Click(object sender, EventArgs e)
{
uc.str = "test";
//uc.Invalidate();
}
}
我直接在设计面板添加的控件,名字是UserControl11而不是我自己命名的
谢谢大家了