1

我有一个创建两个链接的类查看器FastColoredTextBoxes。我希望两个框一起水平滚动。我有这个代码:

public class Viewer : Panel
{
     public FastColoredTextBox HeaderRow = new FastColoredTextBox();
     public FastColoredTextBox Editor = new FastColoredTextBox();    

     public Viewer(int _Top, int _Left, int _Height, int _Width, bool _HasHeaderRow, Control control)
     {
         this.Editor.Scroll += new ScrollEventHandler(Editor_Scroll);
     }

     void Editor_Scroll(object sender, ScrollEventArgs e)
     {
          if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)
          {
              this.HeaderRow.HorizontalScroll.Value = this.Editor.HorizontalScroll.Value;
          }
          this.HeaderRow.UpdateScrollbars();
      }
 }

它不起作用。我以前从未尝试将事件附加到类实例中的控件。如果我在我的表单中声明控件并附加一个非常相似的事件(减去.this),它就可以正常工作。谢谢你。

4

1 回答 1

0

i think that for the next time try to tell yourself " what could it be?" and maybe debug a little, like a breackpoint for example. as you probably understood, you had a little mistake in the line

this.HeaderRow.HorizontalScroll.Value = this.HeaderRow.HorizontalScroll.Value;

you meant to write

HeaderRow.HorizontalScroll.Value = Editor.HorizontalScroll.Value;

you just got mixed between the two or something, which happens to all of us. but the first thing i would do is to think and debug it, check the values and let someone look at it. only then post it here.

于 2013-08-04T13:19:20.997 回答