Exemple #1
0
        /// <summary>
        /// 当示例类型更改时调用
        ///
        /// </summary>
        protected void OnExampleTypeChanged()
        {
            Type[] types = this.exampleType.Assembly.GetTypes();
            this.tutorialsTree.Nodes.Clear();
            this.tutorialsTree.ShowNodeToolTips = true;

            foreach (string text in Categories)
            {
                TreeNode treeNode = this.tutorialsTree.Nodes.Add(text);
                treeNode.Tag  = (object)text;
                treeNode.Name = text;
            }
            foreach (Type exampleClass in types)
            {
                if (!(exampleClass.GetMethod(RunMethodName) == (MethodInfo)null))
                {
                    string           text1            = "Examples";
                    ExampleAttribute exampleAttribute = this.GetExampleAttribute(exampleClass);
                    if (exampleAttribute != null)
                    {
                        text1 = exampleAttribute.Category;
                    }
                    TreeNode treeNode1 = (TreeNode)null;
                    foreach (TreeNode treeNode2 in this.tutorialsTree.Nodes)
                    {
                        if (text1.Equals(treeNode2.Tag))
                        {
                            treeNode1 = treeNode2;
                        }
                    }
                    if (treeNode1 == null)
                    {
                        treeNode1      = this.tutorialsTree.Nodes.Add(text1);
                        treeNode1.Tag  = (object)text1;
                        treeNode1.Name = text1;
                    }
                    string text2 = exampleClass.Name;
                    if (exampleAttribute != null && exampleAttribute.Prefix != null)
                    {
                        text2 = exampleAttribute.Prefix + " " + text2;
                    }
                    TreeNode treeNode3 = treeNode1.Nodes.Add(text2);
                    if (exampleAttribute != null)
                    {
                        treeNode3.ToolTipText = exampleAttribute.Description;
                    }
                    treeNode3.Tag = (object)exampleClass;
                }
            }
            this.tutorialsTree.ExpandAll();
            foreach (TreeNode nd in this.tutorialsTree.Nodes)
            {
                this.SortChildNodesByName(nd);
            }
            if (this.tutorialsTree.Nodes.Count <= 0 || this.tutorialsTree.Nodes[0].Nodes.Count <= 0)
            {
                return;
            }
            this.tutorialsTree.SelectedNode = this.tutorialsTree.Nodes[0].Nodes[0];
        }
Exemple #2
0
        protected void OnSelectionChanged()
        {
            Type selectedExample = this.SelectedExample;

            if (selectedExample == (Type)null)
            {
                return;
            }
            this.SuspendLayout();
            this.exampleSummaryBox.Clear();
            this.exampleSummaryBox.SelectionColor = Color.DarkBlue;
            this.exampleSummaryBox.SelectionFont  = new Font(FontFamily.GenericSansSerif, 11f, FontStyle.Bold);
            this.exampleSummaryBox.AppendText(selectedExample.Name + Environment.NewLine);
            ExampleAttribute exampleAttribute = this.GetExampleAttribute(selectedExample);

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

            if (exampleAttribute != null)
            {
                text = exampleAttribute.Description;
            }
            this.exampleSummaryBox.AppendText(text);
            this.exampleSummaryBox.Size    = this.exampleSummaryBox.GetPreferredSize(this.exampleSummaryBox.Size);
            this.exampleSummaryBox.Height += 30;
            this.exampleSummaryBox.Refresh();
            string sourceCodeFilename = this.GetSourceCodeFilename(selectedExample);

            this.DoubleBuffered = true;
            try
            {
                if (sourceCodeFilename == null)
                {
                    this.sourceTextBox.Text = "";
                    this.sourceTextBox.AppendText("源码没有找到(Example source code was not found).  " + Environment.NewLine
                                                  + "在源文件-属性-复制到输出目录 修改为 始终复制 " + 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 rtb = new RichTextBox();
                    rtb.Font          = this.sourceTextBox.Font;
                    rtb.SelectionTabs = this.sourceTextBox.SelectionTabs;
                    EfficientTextBox targetTextBox = new EfficientTextBox(rtb);
                    StreamReader     streamReader  = new StreamReader(sourceCodeFilename);
                    while (true)
                    {
                        string s = streamReader.ReadLine();
                        if (s != null)
                        {
                            this.PrintWithSyntaxHighlighting(targetTextBox, s);
                        }
                        else
                        {
                            break;
                        }
                    }
                    targetTextBox.Flush();
                    streamReader.Close();
                    this.sourceTextBox.Rtf = rtb.Rtf;
                }
            }
            finally
            {
                this.ResumeLayout(true);
            }
        }