How Do I Use .NET Enums? (Magic xpa 3.x)
When dealing with .NET objects, Magic xpa will automatically handle much of the data conversion. For instance, you won’t generally have to worry whether a number is a Long or Short integer, or what kind of string is used to pass an Alpha. However, some of the values in a .NET object are of a specific data type called an enumeration, or enum. The only way to pass these between Magic xpa and .NET is to use a .NET method to supply the enumerator or to translate it.
In this example, the BackColor property requires the output of the System.Drawing.Color class. Magic xpa gives us a hint at the bottom of the property sheet.
When you enter the DotNet.System.Drawing.Color, Magic xpa will create a list of all the valid options each time you enter a dot (.). Many of these are hard-coded values, such as ‘ForestGreen’ or ‘Fuchsia’. Others, however, are functions that convert data from one form to another. This data conversion is called casting. FromKnownColor is a method that converts a string representing the color name, such as ‘Red’ or ‘ForestGreen’, into the form that will be accepted by the BackColor property.
So, in the Magic xpa expression, you could enter:
DotNet.System.Drawing.Color.FromKnownColor(‘Red’)
and this wold be a valid value for BackColor.
However, usually you would want to use a variable instead, so you would probably have an Alpha variable that would contain the string ‘Red’ or some other user selection, and you would use that instead. By using a list of valid .NET colors in a simple combo box, the user can select from some pre-selected set of values.
Alternatively, the FromArgb method could have been used, and a set of RGB values could have been passed instead.
Note that the appearance of the calendar control will be changed only if the Use Windows XP Themes environment setting is set to No.
The Online and Rich Client Samples projects (program NE04 and RNE04)