我有一个创建两个链接的类查看器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),它就可以正常工作。谢谢你。