在我的项目中,我的文本框需要一个独立的滚动条。所以我创建了一个自定义滚动条。知道如何在文本框中使用我的自定义滚动条(水平和垂直)而不是内置滚动条?
请在下面找到我的示例代码。(在原始代码中,文本框和滚动条是可换肤的。我不能在这里发布实际代码......)
public partial class EditControl : Control
{
int BORDERWIDTH = SystemInformation.Border3DSize.Width;
int SCROLLBARWIDTH = SystemInformation.VerticalScrollBarWidth;
CustomTextBox editCtrl;
VScrollBar vScrollBar = null;
public EditControl()
{
InitializeComponent();
editCtrl = new CustomTextBox();
this.Width = 200 + SCROLLBARWIDTH;
this.Height = 140;
editCtrl.Width = this.Width - SCROLLBARWIDTH;
editCtrl.Height = this.Height;
editCtrl.Multiline = true;
editCtrl.Left = Left;
vScrollBar = new VScrollBar();
vScrollBar.Height = this.Height;
vScrollBar.Location = new Point(editCtrl.Width, 1);
vScrollBar.Scroll += new ScrollEventHandler(vScrollBar_Scroll);
this.Controls.Add(editCtrl);
this.Controls.Add(vScrollBar);
}
private void vScrollBar_Scroll(object sender, ScrollEventArgs e)
{
//Code to scroll the text box
//editCtrl.ScrollTo(position);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
editCtrl.Width = this.Width - SCROLLBARWIDTH;
editCtrl.Height = this.Height;
}
public partial class CustomTextBox : TextBox
{
public CustomTextBox()
{
//InitializeComponent();
}
public void ScrollTo(int Position)
{
//Code to scroll the contents.
}
}
}
}