-2
在我的項目中,我需要一個用於我的文本框的獨立滾動條。所以我創建了一個自定義滾動條。任何想法如何在文本框中使用自定義滾動條(水平和垂直)而不是內置滾動條?C#中的獨立滾動條文本框
請在下面找到我的示例代碼。 (在原代碼的文本框和滾動條的換膚,我不能在這裏張貼實際的代碼...)
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.
}
}
}
}
我們也不能告訴你,直到你添加相關的代碼到你的文章。 –
我通過放置文本框和垂直滾動條創建了一個控件。當我滾動滾動條時,應該滾動文本框中的內容。如何通過滾動我的獨立滾動條來滾動文本框? – Kaizen