PDA

View Full Version : چگونه میتوان یک متغیر از یک کلاس مثلا A را در کلاس دیگر تعریف کرد



alexmcse
سه شنبه 28 بهمن 1393, 00:26 صبح
سلام

یک یوزر کنترل میخواهم بسازم

چگونه میتوان یک متغییر از یک کلاس مثلا A را در کلاس دیگر تعریف کرد که کاربر بتواند در پنجره پروپرتیز مقدار آن را تغییر دهد

using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApplication5
{
public partial class UserControl2 : UserControl
{
A ad = new A();


public A Ad
{
get { return ad; }
set { ad = value; }
}
public UserControl2()
{
InitializeComponent();
TextBox textBox1 = new TextBox();
//
// textBox1
//
textBox1.Location = new System.Drawing.Point(0, 0);
textBox1.Name = "textBox1";
textBox1.Size = new System.Drawing.Size(301, 20);
textBox1.TabIndex = 0;
this.Controls.Add(textBox1);


}


public class A:Component
{
public A()
{
this.Dock = DockStyle.Bottom;
}
private Color t1;


public Color T1
{
get { return t1; }
set { t1 = value; }
}
private Color t2;


public Color T2
{
get { return t2; }
set { t2 = value; }
}


}
}
}




یک متغیر از کلاس A درون کلاس یوزر کنترل تعریف شود و بتوان از پروپرتیهای کلاس A استفاده کرد (t1,t2)
در پنجره پروپرتی بشود این متغییر های فوق را مقدار دهی کنیم
من این کار را انجام میدهم اما بعد از Bulid کردن مقدار این متغییر ها تغییر نمیکنند
چرا؟

تشکر

ASKaffash
چهارشنبه 29 بهمن 1393, 07:29 صبح
سلام
دستور ذیل را قبل ار کلاس A قرار بده :


[TypeConverter (http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:2.0.0.0:b77a5c561934e089/System.ComponentModel.TypeConverterAttribute/.ctor(System.Type))(typeof(ExpandableObjectConvert er (http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System:2.0.0.0:b77a5c561934e089/System.ComponentModel.ExpandableObjectConverter)))]