示例#1
0
        /// <summary>
        /// Called when the example type changes
        /// </summary>
        protected void OnExampleTypeChanged()
        {
            Type[] types = exampleType.Assembly.GetTypes();
            tutorialsTree.Nodes.Clear();
            tutorialsTree.ShowNodeToolTips = true;

            // To ensure that the known sections will appear in order
            foreach (var categoryName in new[] { "Tutorials", "String tutorials", "Applications" })
            {
                TreeNode categoryNode = tutorialsTree.Nodes.Add(categoryName);
                categoryNode.Tag  = categoryName;
                categoryNode.Name = categoryName;
            }

            foreach (Type t in types)
            {
                if (t.GetMethod("Run") == null)
                {
                    continue;
                }
                string           category = "Examples";
                ExampleAttribute exa      = GetExampleAttribute(t);
                if (exa != null)
                {
                    category = exa.Category;
                }

                // Find an existing category node
                TreeNode par = null;
                foreach (TreeNode nd in tutorialsTree.Nodes)
                {
                    if (category.Equals(nd.Tag))
                    {
                        par = nd;
                    }
                }

                if (par == null)
                {
                    // Handle unknown categories
                    par     = tutorialsTree.Nodes.Add(category);
                    par.Tag = category;
                    //par.NodeFont = new Font(tutorialsTree.Font, FontStyle.Bold);
                    par.Name = category;
                }

                string name = t.Name;
                if ((exa != null) && (exa.Prefix != null))
                {
                    name = exa.Prefix + " " + name;
                }
                TreeNode nd2 = par.Nodes.Add(name);
                if (exa != null)
                {
                    nd2.ToolTipText = exa.Description;
                }
                nd2.Tag = t;
            }
            tutorialsTree.ExpandAll();
            foreach (TreeNode nd in tutorialsTree.Nodes)
            {
                SortChildNodesByName(nd);
            }
            if ((tutorialsTree.Nodes.Count > 0) && (tutorialsTree.Nodes[0].Nodes.Count > 0))
            {
                tutorialsTree.SelectedNode = tutorialsTree.Nodes[0].Nodes[0];
            }
        }
示例#2
0
        /// <summary>
        /// Selection changed handler
        /// </summary>
        protected void OnSelectionChanged()
        {
            Type exampleClass = SelectedExample;

            if (exampleClass == null)
            {
                return;
            }
            SuspendLayout();
            exampleSummaryBox.Clear();
            exampleSummaryBox.SelectionColor = Color.DarkBlue;
            exampleSummaryBox.SelectionFont  = new Font(FontFamily.GenericSansSerif, 11f, FontStyle.Bold);
            exampleSummaryBox.AppendText(exampleClass.Name + Environment.NewLine);
            //label1.Text = "'" + tutorialClass.Name + "' source code";
            ExampleAttribute exa = GetExampleAttribute(exampleClass);

            exampleSummaryBox.SelectionFont  = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular);
            exampleSummaryBox.SelectionColor = Color.FromArgb(0, 0, 100);

            string desc = "";

            if (exa != null)
            {
                desc = exa.Description;
            }
            exampleSummaryBox.AppendText(desc);
            exampleSummaryBox.Size    = exampleSummaryBox.GetPreferredSize(exampleSummaryBox.Size);
            exampleSummaryBox.Height += 10;
            exampleSummaryBox.Refresh();
            string filename = GetSourceCodeFilename(exampleClass);

            DoubleBuffered = true;
            //sourceTextBox.SuspendLayout();
            try
            {
                if (filename == null)
                {
                    sourceTextBox.Text = "Example source code was not found.  " + Environment.NewLine +
                                         "Go to the properties of the source file in Visual Studio and set 'Copy To Output Directory' to 'Copy if newer'.";
                }
                else
                {
                    RichTextBox tempBox = new RichTextBox();
                    tempBox.Font          = sourceTextBox.Font;
                    tempBox.SelectionTabs = sourceTextBox.SelectionTabs;
                    EfficientTextBox etb      = new EfficientTextBox(tempBox);
                    StreamReader     sr       = new StreamReader(filename);
                    bool             isHeader = true;
                    while (true)
                    {
                        string line = sr.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        if (isHeader)
                        {
                            string trimmed = line.TrimStart();
                            if (trimmed.Length == 0 || trimmed.StartsWith("// "))
                            {
                                continue;
                            }
                            else
                            {
                                isHeader = false;
                            }
                        }
                        PrintWithSyntaxHighlighting(etb, line);
                    }
                    etb.Flush();
                    sr.Close();
                    sourceTextBox.Rtf = tempBox.Rtf;
                }
                //sourceTextBox.ResumeLayout(true);
            }
            finally
            {
                ResumeLayout(true);
            }
            //this.PerformLayout();
        }