Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionHow to add Outlook toolbar under the subject line in C# add-in? Pin
Artem Moroz23-Apr-14 12:46
Artem Moroz23-Apr-14 12:46 
AnswerRe: How to add Outlook toolbar under the subject line in C# add-in? Pin
Eddy Vluggen23-Apr-14 22:45
professionalEddy Vluggen23-Apr-14 22:45 
GeneralRe: How to add Outlook toolbar under the subject line in C# add-in? Pin
Artem Moroz26-Apr-14 8:56
Artem Moroz26-Apr-14 8:56 
QuestionHow to Open new Form when click on TreeNode? Pin
aahamdan23-Apr-14 10:10
aahamdan23-Apr-14 10:10 
AnswerRe: How to Open new Form when click on TreeNode? Pin
Mycroft Holmes23-Apr-14 12:56
professionalMycroft Holmes23-Apr-14 12:56 
GeneralRe: How to Open new Form when click on TreeNode? Pin
aahamdan23-Apr-14 22:23
aahamdan23-Apr-14 22:23 
AnswerRe: How to Open new Form when click on TreeNode? Pin
UGUR KIZILKAYA24-Apr-14 4:55
UGUR KIZILKAYA24-Apr-14 4:55 
AnswerRe: How to Open new Form when click on TreeNode? Pin
BillWoodruff25-Apr-14 20:17
professionalBillWoodruff25-Apr-14 20:17 
Consider using a Dictionary<string, Form> to 'Show existing instances of Forms; or, consider using a Dictionary<string,Type> to create and 'Show new instances based on Type:
C#
// Assume five different Forms are defined in the Project, and 'Form1 is being used as the "main Form:"

private Dictionary<string, Form> dctStrForm;

private Dictionary<string, Type> dctStrType; 

private void Form1_Load(object sender, System.EventArgs e)
{
    dctStrForm = new Dictionary<string, Form>
    {
        {"Form2", new Form2()},
        {"Form3", new Form3()},
        {"Form4", new Form4()},
        {"Form5", new Form5()}
    };

    dctStrType = new Dictionary<string, Type>
    {
        {"Form2", typeof(Form2)},
        {"Form3", typeof(Form3)},
        {"Form4", typeof(Form4)},
        {"Form5", typeof(Form5)}
    };
}

private void btnShowFormFromString_Click(object sender, System.EventArgs e)
{
    string frmCandidate = textBox1.Text;

    if (dctStrForm.ContainsKey(frmCandidate))
    {
        dctStrForm[frmCandidate].Show();
    }
    else
    {
        MessageBox.Show("I don't have a Form named: " + frmCandidate);
    }
}

private void btnCreateAndShowFormFromString_Click(object sender, System.EventArgs e)
{
    string frmCandidate = textBox1.Text;

    if (dctStrType.ContainsKey(frmCandidate))
    {
        Type newFormType = dctStrType[frmCandidate];
        Form newForm = Activator.CreateInstance(newFormType) as Form; 
        newForm.Show();
    }
    else
    {
        MessageBox.Show("I don't have a Form of Type: " + frmCandidate);
    }
}
Note that in the second example we are ignoring the probably obvious need anyone would have to keep track of new Form instances created, install EventHandlers for Events raised by the new Forms, etc.

If you have assigned the 'Text or 'Type of your different Forms to the 'Tag Property of TreeNodes in your TreeView, then you can easily use the same techniques shown here:

0. in the After_Select EventHandler

1. check if the selected Node Tag is non-null: skip if null

2. if necessary cast the Tag to a Type

3. use the code shown above with either string or Type as needed.

“I speak in a poem of the ancient food of heroes: humiliation, unhappiness, discord. Those things are given to us to transform, so that we may make from the miserable circumstances of our lives things that are eternal, or aspire to be so.” Jorge Luis Borges


modified 26-Apr-14 7:50am.

QuestionWeb API action null data on post when deployed to production Pin
Basilfa23-Apr-14 0:43
Basilfa23-Apr-14 0:43 
Question"Combined Type" - Generics - something else? Pin
Bernhard Hiller22-Apr-14 23:55
Bernhard Hiller22-Apr-14 23:55 
QuestionRe: "Combined Type" - Generics - something else? Pin
Eddy Vluggen23-Apr-14 0:35
professionalEddy Vluggen23-Apr-14 0:35 
AnswerRe: "Combined Type" - Generics - something else? Pin
Bernhard Hiller23-Apr-14 0:54
Bernhard Hiller23-Apr-14 0:54 
AnswerRe: "Combined Type" - Generics - something else? PinPopular
Richard Deeming23-Apr-14 1:18
mveRichard Deeming23-Apr-14 1:18 
GeneralRe: "Combined Type" - Generics - something else? Pin
Bernhard Hiller23-Apr-14 2:28
Bernhard Hiller23-Apr-14 2:28 
Question"Configuration system failed to initialize" Pin
AshwiniSH22-Apr-14 23:32
professionalAshwiniSH22-Apr-14 23:32 
AnswerRe: "Configuration system failed to initialize" Pin
Bernhard Hiller22-Apr-14 23:56
Bernhard Hiller22-Apr-14 23:56 
GeneralRe: "Configuration system failed to initialize" Pin
AshwiniSH24-Apr-14 21:51
professionalAshwiniSH24-Apr-14 21:51 
Questionhow to use events using Base class Pin
Member 1034709222-Apr-14 15:44
Member 1034709222-Apr-14 15:44 
AnswerRe: how to use events using Base class Pin
Eddy Vluggen23-Apr-14 0:32
professionalEddy Vluggen23-Apr-14 0:32 
QuestionRe: how to use events using Base class Pin
Eddy Vluggen23-Apr-14 5:11
professionalEddy Vluggen23-Apr-14 5:11 
AnswerRe: how to use events using Base class Pin
Marco Bertschi23-Apr-14 5:40
protectorMarco Bertschi23-Apr-14 5:40 
QuestionRetaining index of an item Pin
Chris Copeland22-Apr-14 12:47
mveChris Copeland22-Apr-14 12:47 
AnswerRe: Retaining index of an item Pin
Ravi Bhavnani22-Apr-14 19:24
professionalRavi Bhavnani22-Apr-14 19:24 
GeneralRe: Retaining index of an item Pin
Chris Copeland22-Apr-14 23:11
mveChris Copeland22-Apr-14 23:11 
GeneralRe: Retaining index of an item Pin
Eddy Vluggen23-Apr-14 0:30
professionalEddy Vluggen23-Apr-14 0:30 

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.