[英]how to set up class instance control events?
I have a class Viewer that creates two linked FastColoredTextBoxes
. 我有一个创建两个链接的
FastColoredTextBoxes
的类Viewer。 I want the two boxes to scroll together horizontally. 我希望两个框一起水平滚动。 I have this code:
我有以下代码:
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();
}
}
It doesn't work. 没用 I've never tried to do attach events to controls in a class instance before.
我以前从未尝试过将事件附加到类实例中的控件上。 If I declare the controls in my form and attach a very similar event (minus the .this's) it works fine.
如果我在表单中声明控件并附加一个非常类似的事件(减去.this),则它会很好地工作。 Thank you.
谢谢。
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.
并可能进行一些调试,例如像breackpoint。 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.
然后将其发布在这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.