Click here to Skip to main content
15,925,782 members
Home / Discussions / C#
   

C#

 
AnswerRe: Hiding your computer's mouse [modified] Pin
Scott Dorman7-Dec-06 15:21
professionalScott Dorman7-Dec-06 15:21 
QuestionAdding dynamicly controls to a Panel Pin
seq-7-Dec-06 6:53
seq-7-Dec-06 6:53 
AnswerRe: Adding dynamicly controls to a Panel Pin
Stefan Troschuetz7-Dec-06 7:36
Stefan Troschuetz7-Dec-06 7:36 
AnswerRe: Adding dynamicly controls to a Panel Pin
Robert Rohde7-Dec-06 7:43
Robert Rohde7-Dec-06 7:43 
QuestionIdentify Serial Ports Pin
babak37-Dec-06 6:33
babak37-Dec-06 6:33 
AnswerRe: Identify Serial Ports Pin
Tim Paaschen7-Dec-06 19:10
Tim Paaschen7-Dec-06 19:10 
QuestionTreeview and refresh Pin
Saamir7-Dec-06 6:31
Saamir7-Dec-06 6:31 
QuestionI need a better aproach to this tree code. Pin
gesox0017-Dec-06 6:28
gesox0017-Dec-06 6:28 
With this c# code I try to write vb6 code. I am a newbie in C# and I think this is not a good approach to my need. I want to create a list of different objects that write the code, but list admit only the same kind of classes (type-safe, right?). I Know i can resolve this using List<object>, but your opinions are useful.

In the example below I do this.

root (form)
|
|--- eFrame
| |
| |--- eTxt (TextBox)
|
eLbl (label)

Example.
--------


public class Tester
{
static void Main()
{
FormControl root = new FormControl("Main", "frmMenu");
Element eFrm = new Element(root);

TextBoxControl txt = new TextBoxControl("txtName",false, " ");
Element eTxt = new Element(txt);

LabelControl lbl = new LabelControl("Name", " ");
Element eLbl = new Element(lbl);

FrameControl frame = new FrameControl("Frame", " ");
Element eFrame = new Element(frame);

frame.AddChild(eTxt);
root.AddChild(eLbl);
root.AddChild(eFrame);

Console.WriteLine(root.GenerateCode());

}

public class BaseControl
{
protected string name;
protected string indent = "";
protected List<element> elementsList;

public BaseControl(string name, string indent)
{
this.name = name;
this.indent = indent;
elementsList = new List<element>();
}

public string Indent
{
get { return indent; }
set { indent = value; }
}

public string Name
{
get { return name; }
set { name = value; }
}

public void AddChild(Element e)
{
elementsList.Add(e);
}
}

public class FormControl : BaseControl
{
private string caption;

public FormControl(string caption, string name)
: base(name, "")
{
this.caption = caption;
}

public string GenerateCode()
{
string code = "";

code += indent + "Begin Form code\n";
foreach (Element e in elementsList) { code += e.GenerateCode(); }
code += indent + "End Form code\n";

return code;
}
}

public class FrameControl : BaseControl
{
private int index;

public FrameControl(string name, string indent)
: base(name, indent)
{
index = -1;
}

public FrameControl(string name, int index, string indent)
: base(name, indent)
{
this.index = index;
}

public int Index
{
get { return index; }
set { index = value; }
}

public string GenerateCode()
{
string code = "";

code += indent + "Begin Frame code\n";
foreach (Element e in elementsList) { code += e.GenerateCode(); }
code += indent + "End Frame code\n";

return code;
}
}

public class LabelControl : BaseControl
{
private string caption;
private static int index;

public LabelControl(string caption, string indent)
: base("", indent)
{
this.caption = caption;
index = 0;
}

public string GenerateCode()
{
string code = "";

code += indent + "Begin label code\n";
code += indent + " ....\n";
code += indent + "End lable code\n";

return code;
}
}

public class Element
{
private delegate string GenCodeDelegate();
private GenCodeDelegate doCode;

#region ' Contructor overloaded '

public Element(LabelControl lbl)
{
doCode = new GenCodeDelegate(lbl.GenerateCode);
}

public Element(TextBoxControl txt)
{
doCode = new GenCodeDelegate(txt.GenerateCode);
}

public Element(FormControl frm)
{
doCode = new GenCodeDelegate(frm.GenerateCode);
}

public Element(FrameControl frame)
{
doCode = new GenCodeDelegate(frame.GenerateCode);
}

#endregion

public string GenerateCode()
{
string code = "";

code = doCode();

return code;
}
}


Thanks in advance.

Gerard
Sorry for my english.
AnswerRe: I need a better aproach to this tree code. Pin
Robert Rohde7-Dec-06 7:32
Robert Rohde7-Dec-06 7:32 
GeneralRe: I need a better aproach to this tree code. Pin
gesox00111-Dec-06 2:07
gesox00111-Dec-06 2:07 
QuestionGeting variables from UserControl Pin
Muntyness7-Dec-06 6:10
Muntyness7-Dec-06 6:10 
AnswerRe: Geting variables from UserControl Pin
Robert Rohde7-Dec-06 6:16
Robert Rohde7-Dec-06 6:16 
GeneralRe: Geting variables from UserControl Pin
Muntyness7-Dec-06 6:36
Muntyness7-Dec-06 6:36 
GeneralRe: Geting variables from UserControl Pin
Robert Rohde7-Dec-06 7:27
Robert Rohde7-Dec-06 7:27 
GeneralRe: Geting variables from UserControl Pin
Muntyness7-Dec-06 8:16
Muntyness7-Dec-06 8:16 
QuestionSwitch Question Pin
mcd24247-Dec-06 5:55
mcd24247-Dec-06 5:55 
AnswerRe: Switch Question Pin
User 66587-Dec-06 6:00
User 66587-Dec-06 6:00 
AnswerRe: Switch Question Pin
Colin Angus Mackay7-Dec-06 6:05
Colin Angus Mackay7-Dec-06 6:05 
GeneralRe: Switch Question Pin
mcd24247-Dec-06 6:14
mcd24247-Dec-06 6:14 
GeneralRe: Switch Question Pin
Colin Angus Mackay7-Dec-06 6:18
Colin Angus Mackay7-Dec-06 6:18 
AnswerRe: Switch Question Pin
Robert Rohde7-Dec-06 6:19
Robert Rohde7-Dec-06 6:19 
GeneralRe: Switch Question Pin
Not Active7-Dec-06 6:27
mentorNot Active7-Dec-06 6:27 
GeneralRe: Switch Question Pin
Robert Rohde7-Dec-06 7:19
Robert Rohde7-Dec-06 7:19 
GeneralRe: Switch Question Pin
Not Active7-Dec-06 7:31
mentorNot Active7-Dec-06 7:31 
GeneralRe: Switch Question Pin
Robert Rohde7-Dec-06 7:46
Robert Rohde7-Dec-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.