public static RichTextBox RichMessage { get { return ; } } 我把属性定义成静态,这样A类就不需要使用B类的实例了,但是原来的return this.richMessage;用不了了,怎么解决?
你不觉得这么做很别扭么, 还不如传实例进去 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; namespace WindowsApplication180 { public partial class Form1 : Form { static TextBox _TB = new TextBox(); static public TextBox TB { get { return _TB; } } public Form1() { InitializeComponent(); TB.Parent = this; new X(); } } class X { public X() { Form1.TB.Text = "a"; } } }
b.控件名.name ...
2.如果不是的话,修改控件属性好像不太好用,是不是也可以把空间改成静态的?感觉在这种情况下传递控件比较好。
{
get {return this.textBox1;}
}
public RichTextBox RichMsg
{
get { return this.richMessage; }
}在A类调用:
B Main = new B();
B.RichMsg编译通过,但是无界面
b->LetAVisitMe(this);
欢迎大家来我的博客
http://blog.csdn.com/csdbfans
里面有很多C#的知识,一起讨论一起提高
{
get { return ; }
}
我把属性定义成静态,这样A类就不需要使用B类的实例了,但是原来的return this.richMessage;用不了了,怎么解决?
还不如传实例进去
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection; namespace WindowsApplication180
{
public partial class Form1 : Form
{
static TextBox _TB = new TextBox(); static public TextBox TB
{
get
{
return _TB;
}
} public Form1()
{
InitializeComponent(); TB.Parent = this; new X();
}
} class X
{
public X()
{
Form1.TB.Text = "a";
}
}
}
http://www.cnblogs.com/lifw/articles/1609356.html