2017-07-19 16 views
5

मैंने एक कस्टम प्रॉपर्टी ग्रिड लागू किया है, मैं जानना चाहता हूं कि क्या मैं प्रत्येक संपत्ति के लेबल को बाएं से दाएं से बदल सकता हूं।संपत्ति ग्रिड: ग्रिड के दाईं ओर प्रत्येक संपत्ति का प्रदर्शन नाम लेबल कैसे सेट करें?

मेरे कस्टम गुण ग्रिड संपत्ति से पता चलता के रूप में आप चित्र में देख सकते हैं।

enter image description here

मैं इस तरह होने के लिए इसे बदलना चाहते:

enter image description here

इस कस्टम गुण ग्रिड के मुख्य कोड

public class CustomPropertyGrid : PropertyGrid 
{ 

    private System.ComponentModel.Container components = null; 
    private ReperesentAttr representAttr; 
    private myTab tab; 
    public CustomPropertyGrid() 
    { 
     this.representAttr = new ReperesentAttr("", ""); 
     tab.SetRepresentAttr = this.representAttr; 
     InitializeComponent(); 
     this.PropertySort = PropertySort.Alphabetical; 
     this.RightToLeft = RightToLeft.Yes; 


    // this. 

    } 

    public ReperesentAttr SetRepresentAttr 
    { 
     set 
     { 
      representAttr = value; 
      tab.SetRepresentAttr = this.representAttr; 

     } 
    } 
    protected override void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      if (components != null) 
      { 
       components.Dispose(); 
      } 
     } 
     base.Dispose(disposing); 
    } 

    #region Codice generato da Progettazione componenti 
    /// <summary> 
    /// Metodo necessario per il supporto della finestra di progettazione. Non modificare 
    /// il contenuto del metodo con l'editor di codice. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     // 
     // UserControl1 
     // 
     this.Name = "myPropertyGrid"; 

    } 
    #endregion 

    protected override PropertyTab CreatePropertyTab(Type tabType) 
    { 
     tab = new myTab(representAttr); 
     return tab; 
    } 
} 

public class myTab : PropertyTab 
{ 
    private ReperesentAttr representAttr; 
    public myTab(ReperesentAttr representAttr) 
    { 
     this.representAttr = representAttr; 
    } 

    public ReperesentAttr SetRepresentAttr 
    { 
     set 
     { 
      representAttr = value; 
     } 
    } 
    // get the properties of the selected component 
    public override System.ComponentModel.PropertyDescriptorCollection GetProperties(object component, System.Attribute[] attributes) 
    { 
     PropertyDescriptorCollection properties; 
     if (attributes != null) 
      properties = TypeDescriptor.GetProperties(component, attributes); 
     else 
      properties = TypeDescriptor.GetProperties(component); 

     //Componet must implement the ICUSTOMCLASS interface. 
     if (component is ICustomClass) 
     { 
      ICustomClass bclass = (ICustomClass)component; 

      //The new array of properties, based on the PublicProperties properties of "model" 
      PropertyDescriptor[] arrProp = new PropertyDescriptor[bclass.PublicProperties.Count]; 

      for (int i = 0; i < bclass.PublicProperties.Count; i++) 
      { 
       //Find the properties in the array of the propertis which neme is in the PubliCProperties 
       PropertyDescriptor prop = properties.Find(bclass.PublicProperties[i].Name, true); 
       //Build a new properties 
       arrProp[i] = TypeDescriptor.CreateProperty(prop.ComponentType, prop, new CategoryAttribute(this.representAttr.Category)); 

      } 
      return new PropertyDescriptorCollection(arrProp); 
     } 
     else 
     { 
      return properties; 
     } 
    } 

    public override System.ComponentModel.PropertyDescriptorCollection GetProperties(object component) 
    { 
     return this.GetProperties(component, null); 
    } 

    // PropertyTab Name 
    public override string TabName 
    { 
     get 
     { 
      return "Properties"; 
     } 
    } 

    //Image of the property tab (return a blank 16x16 Bitmap) 
    public override System.Drawing.Bitmap Bitmap 
    { 
     get 
     { 
      return new Bitmap(16, 16); 
     } 
    } 

} 
public class ReperesentAttr 
{ 
    string category = string.Empty; 
    string name = string.Empty; 
    public ReperesentAttr(string name, string category) 
    { 
     this.category = category; 
     this.name = name; 
    } 
    public string Category 
    { 
     set { category = value; } 
     get { return category; } 
    } 

    public string Name 
    { 
     set { name = value; } 
     get { return name; } 
    } 
} 
public interface ICustomClass 
{ 
    PropertyList PublicProperties 
    { 
     get; 
     set; 
    } 
} 
public class PropertyList : NameObjectCollectionBase 
{ 
    public void Add(Object value) 
    { 
     //The key for the object is taken from the object to insert 
     this.BaseAdd(((CustomProperty)value).Name, value); 
    } 

    public void Remove(String key) 
    { 
     this.BaseRemove(key); 
    } 

    public void Remove(int index) 
    { 
     this.BaseRemoveAt(index); 
    } 

    public void Clear() 
    { 
     this.BaseClear(); 
    } 

    public CustomProperty this[String key] 
    { 
     get 
     { 
      return (CustomProperty)(this.BaseGet(key)); 
     } 
     set 
     { 
      this.BaseSet(key, value); 
     } 
    } 

    public CustomProperty this[int indice] 
    { 
     get 
     { 
      return (CustomProperty)(this.BaseGet(indice)); 
     } 
     set 
     { 
      this.BaseSet(indice, value); 
     } 
    } 
    public bool HasKey(String key) 
    { 
     foreach(String item in this.BaseGetAllKeys()) 
     { 
      if(key == item) 
       return true; 
     } 

     return false; 
    } 

} 
+1

मुझे नहीं लगता कि आप यह कर सकते हैं। Winforms संपत्ति ग्रिड की आंतरिक ग्रिड विन्यास योग्य नहीं है। –

+0

जंगली अनुमान लेकिन शायद DataGridViewCellStyle.Alignment संपत्ति मदद कर सकता है? । उदाहरण: this.dataGridView1.Columns [ "CUSTOMERNAME"] DefaultCellStyle .Alignment = DataGridViewContentAlignment.MiddleRight; – krzysztofla

+0

यह संपत्ति ग्रिड और डेटाग्रिड से अलग है। @KrzysztofLa –

उत्तर

1

अपने CustomPropertyGrid को यह जोड़ें, यह है आपको आरंभ हो सकता है:

const int WS_EX_LAYOUTRTL = 0x400000; 
private bool _RTL = false; 

[Description("Change to the right-to-left layout."), DefaultValue(false), 
Localizable(true), Category("Appearance"), Browsable(true)] 
public bool Mirrored 
{ 
    get 
    { 
     return _RTL; 
    } 
    set 
    { 
     if (_RTL != value) 
      _RTL = value; 
     base.OnRightToLeftChanged(EventArgs.Empty); 
    } 
} 
protected override CreateParams CreateParams 
{ 
    get 
    { 
     CreateParams CP; 
     CP = base.CreateParams; 
     if (this.Mirrored) 
      CP.ExStyle = CP.ExStyle | WS_EX_LAYOUTRTL; 
     return CP; 
    } 
} 

https://www.microsoft.com/middleeast/msdn/mirror.aspx

+0

वहाँ एक समस्या है जब मैं इस कोड को जोड़ा है: लेबल सही लेकिन उनके करने के लिए जाना पाठ नहीं दिखाया गया है। और कुछ हिस्सा काला हो जाते हैं: https://www.dropbox.com/s/qjefidstcsxqrja/puo.png?dl=0 –

+0

क्योंकि यह कोड विस्तारित विंडो शैलियों का उपयोग करता है या नहीं, यह समस्या उत्पन्न कर सकता है। आप यहां विस्तारित विंडोज शैलियों पर पढ़ना चाहेंगे https://msdn.microsoft.com/en-us/library/ff700543(v=vs.85).aspx, इन विंडोज शैलियों https://msdn.microsoft .com/en-us/पुस्तकालय/ms632600 (v = vs.85) .aspx। यह स्टैक ओवरफ़्लो प्रश्न भी देखें https://stackoverflow.com/questions/8206450/what-are-the- संभावित-values-for-createparams-style – DafyddNZ

संबंधित मुद्दे