-2

私のプロジェクトでは、テキストボックス用のスタンドアロンのスクロールバーが必要です。そこで、カスタマイズしたスクロールバーを作成しました。組み込みのスクロールバーの代わりに、テキストボックスでカスタマイズしたスクロールバー(水平と垂直の両方)を使用する方法はありますか?

以下の私のサンプルコードを見つけてください。(元のコードでは、テキストボックスとスクロールバーはスキニング可能です。実際のコードをここに投稿することはできません...)

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.
        } 
    }
}

}

4

1 に答える 1

1

問題は解決しました。カスタマイズしたスクロールバーでテキストボックスの元のスクロールバーをマスクしました。GetScrollInfo APIは、スクロールバーを同期するために使用されます。

于 2012-11-24T08:08:48.287 に答える