Click here to Skip to main content
16,005,467 members
Home / Discussions / C#
   

C#

 
AnswerRe: Read and Replace Pin
Ravi Bhavnani26-Jan-06 12:42
professionalRavi Bhavnani26-Jan-06 12:42 
AnswerRe: Read and Replace Pin
DigitalKing26-Jan-06 14:30
DigitalKing26-Jan-06 14:30 
QuestionDisplay live video from an ethernet camera Pin
greg ross26-Jan-06 12:08
greg ross26-Jan-06 12:08 
AnswerRe: Display live video from an ethernet camera Pin
Daniel Santillanes26-Jan-06 13:00
professionalDaniel Santillanes26-Jan-06 13:00 
GeneralRe: Display live video from an ethernet camera Pin
greg ross31-Jan-06 3:18
greg ross31-Jan-06 3:18 
QuestionFun with generics Pin
tantiboh26-Jan-06 12:07
tantiboh26-Jan-06 12:07 
AnswerRe: Fun with generics Pin
Guffa26-Jan-06 12:27
Guffa26-Jan-06 12:27 
AnswerRe: Fun with generics Pin
Le centriste27-Jan-06 1:38
Le centriste27-Jan-06 1:38 
In Generics, types must be known compile-time, not run-time, and do not instance parameters (controltype is an instance of the System.String class). The suggestion from Guffa is very good, but you could still avoid having tons of switches in your code.

Start from the fact that all your controls inherit from the System.Windows.Forms.Control class, which, I would say, contains about 95% of the properties of the built-in controls (Size, Font, Text, Position, Name, Visible, etc.).

So, using reflection, you could, as suggested by Guffa, instanciate your controls in a way similar to the one below:

List<Control> controls = new List<Control>();

foreach (....)
{
    Type myControlType = Type.ReflectionOnlyGetType(controltype, true, false);
    ConstructorInfo myControlContructor = myControlType.GetConstructor(Type.EmtpyTypes); // Default
    Control myControl = myControlContructor.Invoke(null);

    controls.Add(myControl);
}

// It is more efficient to declare the variables outside the loop, though.


Then, set all the properties common to all controls, I think this would cover much of your cases.
You will need some mechanism (maybe a flag from your database) to indicate properties that are not defined in the System.Windows.Forms.Control class.

Hope this helps,
Michel

--------

"I say no to drugs, but they don't listen."
- Marilyn Manson

-- modified at 7:39 Friday 27th January, 2006
QuestionWindows refresh Pin
Kwai Cheng Kane26-Jan-06 9:43
Kwai Cheng Kane26-Jan-06 9:43 
AnswerRe: Windows refresh Pin
James Gupta26-Jan-06 10:21
professionalJames Gupta26-Jan-06 10:21 
GeneralRe: Windows refresh Pin
Kwai Cheng Kane26-Jan-06 10:28
Kwai Cheng Kane26-Jan-06 10:28 
GeneralRe: Windows refresh Pin
James Gupta26-Jan-06 10:58
professionalJames Gupta26-Jan-06 10:58 
Questionsystem tray Pin
mehrdadc4826-Jan-06 9:36
mehrdadc4826-Jan-06 9:36 
AnswerRe: system tray Pin
André Ziegler26-Jan-06 10:02
André Ziegler26-Jan-06 10:02 
AnswerRe: system tray Pin
Ravi Bhavnani26-Jan-06 10:20
professionalRavi Bhavnani26-Jan-06 10:20 
QuestionStrings and Interop Pin
Beringer26-Jan-06 9:27
Beringer26-Jan-06 9:27 
AnswerRe: Strings and Interop Pin
Beringer26-Jan-06 9:50
Beringer26-Jan-06 9:50 
GeneralRe: Strings and Interop Pin
Andy Moore26-Jan-06 11:17
Andy Moore26-Jan-06 11:17 
GeneralRe: Strings and Interop Pin
Beringer26-Jan-06 17:52
Beringer26-Jan-06 17:52 
AnswerRe: Strings and Interop Pin
James Gupta26-Jan-06 10:59
professionalJames Gupta26-Jan-06 10:59 
AnswerRe: Strings and Interop Pin
DigitalKing26-Jan-06 14:36
DigitalKing26-Jan-06 14:36 
GeneralRe: Strings and Interop Pin
Beringer26-Jan-06 15:27
Beringer26-Jan-06 15:27 
QuestionHelp with Code conversion Pin
TMF32026-Jan-06 7:11
TMF32026-Jan-06 7:11 
AnswerRe: Help with Code conversion Pin
Guffa26-Jan-06 7:24
Guffa26-Jan-06 7:24 
GeneralRe: Help with Code conversion Pin
TMF32026-Jan-06 7:46
TMF32026-Jan-06 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.