I'm working with xpCommonControls. I'm looking through the testbed of the controls. The only problem is that they are in vb. So with my limited knowledge I am trying to take some of the examples and turn them in to c# code that I will understand. I have done well up until this point and this routine is confusing me. If someone could explain to me how to make the equivalent in c# I would be very much appreciative.
Private Sub SetTheme(ByVal ctrl As Control, ByVal theme As mdobler.XPCommonControls.ThemeStyle)
If TypeOf ctrl Is mdobler.XPCommonControls.IThemed Then
CType(ctrl, mdobler.XPCommonControls.IThemed).Theme = theme
End If
For Each c As Control In ctrl.Controls
SetTheme(c, theme)
Next
End Sub

xpCommonControls..
rborders
Douglas911
The type or namespace name 'ctrl' could not be found (are you missing a using directive or an assembly reference )
I did some checking and the typeof function is different in c# than it is in vb. TypeOf in vb appears to check inheritance and see if the control inherits from different classes. My question is does c# have a function to check inheritance like this
Here is the description of the vb function.
The TypeOf keyword introduces a comparison clause that tests whether an object is derived from or implements a particular type, such as an interface.
mlewis
I don't know how to write the equivalent c# code (it might be done with the "is" comparison, as mentioned below...) but I can tell you what it does:
It checks in a recursive manner every control on a form/control collection if it implements the IThemed Interface. If it does so, the current theme is provided to the control and the control redraws itself with this new info.
Hope that Helps
Mike Dobler
Author of XPCommonControls
PantherBoy
private void SetTheme(Control control, mdobler.XPCommonControls.ThemeStyle theme)
{
for(int x = 0; x < control.Controls.Count; x++)
{
if(control.Controls[x] is mdobler.XPCommonControls.IThemed)
{
mdobler.XPCommonControls.IThemed ctrlCurrent = (mdobler.XPCommonControls.IThemed)control.Controls[x];
ctrlCurrent.Theme = theme;
}
if(control.Controls.Count > 0)
{
this.SetTheme(control.Controls[x], theme);
}
}
}
Anil Ambati
private void SetTheme(Control ctrl,mdobler.XPCommonControls.ThemeStyle theme)
{
if (typeof(ctrl) == mdobler.XPCommonControls.IThemed)
// a cast of the theme according to the VB-help, reading the help copied below:
((mdobler.XPCommonControls.IThemed) ctrl).Theme = theme; // I think
foreach (Control c in ctrl.Controls)
SetTheme(c,theme)
}
from the help of the cast operator: (CType Function)
Dim MyNumber As Long
Dim MyNewType As Single
MyNumber = 1000
MyNewType = CType(MyNumber,Single) ' MyNewType is set to 1000.0.
which translates to us simple C#-folk: float MyNewType = (float) MyNumber;
the above however seems to be the (CType Keyword)
the help reads:
A cast expression coerces an expression to a given type.
Specific cast keywords coerce expressions into the primitive types.
Two general cast keywords, CType and DirectCast, coerce an expression into any type.
DirectCast is different from CType in the way it converts expressions that are typed as Object.
When converting an expression of type Object whose run-time type is a primitive value type,
DirectCast throws a System.InvalidCastException exception if the specified type is not the same
as the run-time type of the expression or a System.NullReferenceException if the expression evaluates to Nothing.
If the specified type and the run-time type of the expression are the same, however,
the run-time performance of DirectCast is better than that of CType.
If no conversion exists from the type of the expression to the specified type, a compile-time error occurs.
Otherwise, the expression is classified as a value and the result is the value produced by the conversion.
CastExpression ::=
DirectCast ( Expression , TypeName ) |
CType ( Expression , TypeName ) |
CastTarget ( Expression )
CastTarget ::=
CBool | CByte | CChar | CDate | CDec | CDbl |
CInt | CLng | CObj | CShort | CSng | CStr
I haven't a clue what this all means, but I gather the Theme of the control( ) is forced into theme if the control is of that type, and thus support the Theme property.
Ugly way of doing simple things( !), I'm happy to be a c# programmer!
hope this helps!