property Color DrawColor
{
Color get()
{
return draw_color;
}
void set( Color val )
{
draw_color = val;
}
}
and also the below code and what's the difference between the above and below code?
[Description ("Alignment to be used for this text"), Category ("Text Configuration")]
[TypeConverter(AlignModeList::typeid)]
property String ^ Alignment
{
String ^ get()
{
return alignment;
}
void set( String ^ val )
{
alignment = val;
}
}
public ref class AlignModeList : System::ComponentModel::StringConverter
{
public:
static array
virtual System::ComponentModel::TypeConverter::StandardValuesCollection ^ GetStandardValues(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return gcnew StandardValuesCollection(alignmode);
}
virtual bool GetStandardValuesSupported(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true;
}
virtual bool GetStandardValuesExclusive(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true;
}
};
VulpesPosted Oct 27, 2011, 10:04 AM
http://msdn.microsoft.com/en-us/library/aa302326.aspx?ppud=4
Sam HobbsPosted Oct 28, 2011, 3:27 PM
Suthish NairPosted Oct 28, 2011, 3:21 PM
Sam HobbsPosted Oct 28, 2011, 1:40 PM
VulpesPosted Oct 28, 2011, 6:24 AM
Karthik AgarwalPosted Oct 28, 2011, 5:50 AM
VulpesPosted Oct 28, 2011, 5:13 AM
Suthish NairPosted Oct 27, 2011, 2:16 PM
Karthik AgarwalPosted Oct 27, 2011, 10:35 AM
VulpesPosted Oct 27, 2011, 10:30 AM
Karthik AgarwalPosted Oct 27, 2011, 10:22 AM
Karthik AgarwalPosted Oct 27, 2011, 9:27 AM
And if it comes to sample code the one which i posted first "DrawColor" is an editable dropdown. i want to resemble the same but with the code which i posted above.
[Description ("Foreground color"), Category ("Text Configuration")]
property Color DrawColor
{
Color get()
{
return draw_color;
}
void set( Color val )
{
draw_color = val;
}
}
For any clarifications please feel free to post back.
VulpesPosted Oct 27, 2011, 9:18 AM
If you mean that the user can type in a selection as well as selecting it from the dropdown (i.e. like a combobox rather than a listbox), then I didn't know that was even possible within a standard PropertyGrid.
Do you have some sample code that you're working from to do this?
Karthik AgarwalPosted Oct 27, 2011, 7:12 AM
[Description ("Sample text to be displayed in viewer"), Category ("Text Configuration")]
[TypeConverter(SidTextList::typeid)]
property String ^ TestString
{
String ^ get()
{
return sample_text;
}
void set( String ^ val )
{
array
space_delimiter[0] = ' ';
array
splitted_sid = val->Split(space_delimiter);
String ^ concat_text;
int len = splitted_sid->Length;
for each(KeyValuePair
{
if(SidLanguageData->copy_of_clicked_language == "View " + kvp.Key)
{
concat_text = "";
for(int j = 0;j < len;j++)
{
if(splitted_sid[j] != "")
{
for(int x = 0;x < SidLanguageData->language_string_id->Length;x++)
{
if(splitted_sid[j] == SidLanguageData->language_string_id[x])
{
List
if(len > 1)
{
concat_text = concat_text + values[x]->ToString();
sample_text = concat_text;
}
else
{
sample_text = values[x]->ToString();
}
}
}
}
if(splitted_sid[j]->StartsWith("X") &&
splitted_sid[j]->EndsWith("X"))
{
if(len > 1)
{
concat_text = concat_text + splitted_sid[j]->Replace("X",
SidLanguageData->max_dec_string);
sample_text = concat_text;
}
else
{
sample_text = val->Replace("X", SidLanguageData->max_dec_string);
}
}
else if(splitted_sid[j]->StartsWith("Y") &&
splitted_sid[j]->EndsWith("Y"))
{
if(len > 1)
{
concat_text = concat_text + splitted_sid[j]->Replace("Y",
SidLanguageData->max_string);
sample_text = concat_text;
}
else
{
sample_text = val->Replace("Y", SidLanguageData->max_string);
}
}
else if(splitted_sid[j]->StartsWith("'") &&
splitted_sid[j]->EndsWith("'"))
{
if(len > 1)
{
concat_text = concat_text + splitted_sid[j]->Replace("'", "");
sample_text = concat_text;
}
else
{
sample_text = val->Replace("'", "");
}
}
}
}
}
sample_text = val;
}
}
public ref class SidTextList : System::ComponentModel::StringConverter
{
public:
virtual System::ComponentModel::TypeConverter::StandardValuesCollection ^ GetStandardValues(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return gcnew StandardValuesCollection(Globals::sid_text_listbox->Items);
}
virtual bool GetStandardValuesSupported(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true;
}
virtual bool GetStandardValuesExclusive(System::ComponentModel::ITypeDescriptorContext ^ context) override
{
return true; // return false //EDITED it should be false to make it work like combobox
}
};
VulpesPosted Oct 27, 2011, 7:04 AM
If you can let me have a list of the possible values, I'll see if I can write the code for you when I next get time.
Karthik AgarwalPosted Oct 27, 2011, 6:41 AM
property String ^ StringSelect
{
String ^ get()
{
return sample_string;
}
void set( String ^ val )
{
sample_string = val;
}
}
VulpesPosted Oct 27, 2011, 6:32 AM
Here you have a reference type called AlignModeList which inherits from StringConverter which itself inherits from the TypeConverter base class.
TypeConverter has virtual methods called GetStandardValues, GetStandardValuesSupported and GetStandardValuesExclusive which are being overridden here in the derived class.
The AlignModeList class also has a static string array field called alignmode which has 3 elements: "Left", "Centre" and "Right".
The GetStandardValues method creates and returns a new StandardValuesCollection object from these three elements.
The other two methods return a bool (always true) to indicate that all these values are supported exclusively within the dropdown list
The AlignModeList TypeConverter is then applied (using an attribute which identifies it by its typeid property) to a string property called Alignment.
This property has a backing field called 'alignment' (not shown in the snippet) to store the current setting: "Left", "Centre" or "Right" which is get or set in the usual fashion.
The property also has Description and Category attributes for displaying its description and the category to which it is to be allocated within the Properties Box.
DrawColor is another property to be used at design time whose backing field is called draw_color and which has Description and Category attributes. However, this is of the standard Color type and so doesn't need a custom type descriptor to display its possible values - the ColorDialog will be displayed instead.