Ejemplo n.º 1
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);
            }
        }