समस्या 1:सी क्लास और ऑपरेटर के लिए डिफ़ॉल्ट संपत्ति नियत # =
मैं एक सरल WinForms अनुप्रयोग है और मैं एक पाठ बॉक्स के लिए मेरे Person.Name संपत्ति DataBind करना चाहते हैं। नाम स्ट्रिंगफिल्ड प्रकार का है। मैंने मूल रूप से नाम संपत्ति को स्ट्रिंग के रूप में परिभाषित किया। डेटा बाइंडिंग स्ट्रिंग जैसे मूल्य प्रकारों पर बहुत बढ़िया काम करती है। मुझे StringField.Value प्रॉपर्टी स्ट्रिंगफ़िल्ल्ड की डिफ़ॉल्ट प्रॉपर्टी चाहिए। मैं "FieldApp.StringField" टेक्स्ट के बजाय टेक्स्टबॉक्स में StringField.Value का मान देखना चाहता हूं।
समस्या 2:
मैं ऑपरेटर का उपयोग कर एक StringField के लिए एक स्ट्रिंग आवंटित करने के लिए = सक्षम होने के लिए करना चाहते हैं। इस असाइनमेंट के परिणामस्वरूप स्ट्रिंगफ़िल्ल्ड होगा। वैल्यू सदस्य सेट किया जा रहा है।
क्या यह पूरा किया जा सकता है?
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 FieldApp
{
public class StringField
{
public string Value { get; set; }
}
public class Person
{
//private String _Name;
//public String Name
//{
// get { return _Name; }
// set { _Name = value; }
//}
//public Person(string name)
//{
// Name = name;
//}
private StringField _Name;
public StringField Name
{
get { return _Name; }
set { _Name = value; }
}
public Person(string name)
{
Name = new StringField();
Name.Value = name;
}
}
public partial class FieldAppForm : Form
{
Person person = new Person("steve");
public FieldAppForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//our form contains a button1 and textBox1
//this compiles
person.Name.Value = "steve";
//this does not. Is there anyway to accomplish this?
person.Name = "steve";
//steve appears in the textbox
textBox1.DataBindings.Add("Text", person, "Name.Value");
//FieldApp.StringField appears in the textbox
textBox1.DataBindings.Add("Text", person, "Name");
}
}
}