相关疑难解决方法(0)

在C#中同步多行文本框位置

我有一个C#应用程序,其中有两个并排的多行文本框,每个文本框位于拆分容器的一侧.我想同步它们的垂直滚动,这样当用户向上或向下滚动其中一个文本框时,另一个文本框分别在同一方向滚动.有没有办法做到这一点?谢谢.

其他信息 - 7/26/10

我在MSDN网站上找到了一些有趣的API:

TextBox.GetFirstVisibleLineIndex方法
TextBox.GetLastVisibleLineIndex方法
TextBox.ScrollToLine方法

那里的文档看起来很有希望,但是当我尝试使用它时,我的编译器(Microsoft Visual C#2008 Express Edition)就会抱怨,即使在添加PresenationFramework作为引用并插入using System.Windows.Controls;文件顶部之后:

错误1'System.Windows.Forms.TextBox'不包含'GetFirstVisibleLineIndex'的定义,并且没有可以找到接受类型'System.Windows.Forms.TextBox'的第一个参数的扩展方法'GetFirstVisibleLineIndex'(你错过了吗?使用指令或程序集引用?)

其他信息 - 7/27/10

我正在努力实现Jay的实现新控件的建议,但是我无法将eventhandler绑定到控件中.这是我到目前为止所拥有的:

public partial class MyFormApplication : Form
{
  public MyFormApplication() // MyFormApplication constructor
  {
     this.InitializeComponent();

     this.textBox1.Dispose(); // Replacing with textBoxSync1
     this.textBox2.Dispose(); // Replacing with textBoxSync2

     // Draw textBoxSync1
     this.textBoxSync1.AcceptsReturn = true;
     this.textBoxSync1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
        | System.Windows.Forms.AnchorStyles.Left)
        | System.Windows.Forms.AnchorStyles.Right)));
     this.textBoxSync1.BackColor = System.Drawing.SystemColors.Control;
     this.textBoxSync1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     this.textBoxSync1.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.textBoxSync1.Location = new …
Run Code Online (Sandbox Code Playgroud)

c# scroll synchronization textbox

6
推荐指数
1
解决办法
4715
查看次数

两个Richtextbox(C#)的同步滚动

我需要一些帮助.目前我正在使用C#中的脚本编辑器,我有两个丰富的文本框:programTextBox,其中整个文本是和linesTextBox,它计算并显示行数.

我希望他们同时滚动.我做了一些搜索,实际上我找到了一些有效的代码,但是如果有一些问题.这是代码:

public enum ScrollBarType : uint
{
    SbHorz = 0,
    SbVert = 1,
    SbCtl = 2,
    SbBoth = 3
}
public enum Message : uint
{
    WM_VSCROLL = 0x0115
}
public enum ScrollBarCommands : uint
{
    SB_THUMBPOSITION = 4
}
[DllImport("User32.dll")]
public extern static int GetScrollPos(IntPtr hWnd, int nBar);
[DllImport("User32.dll")]
public extern static int SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
Run Code Online (Sandbox Code Playgroud)

...

private void programTextBox_VScroll(object sender, EventArgs e)
{
    int nPos = GetScrollPos(programTextBox.Handle, (int)ScrollBarType.SbVert);
    nPos <<= 16;
    uint …
Run Code Online (Sandbox Code Playgroud)

c# richtextbox cursor winforms synchronized-scrolling

5
推荐指数
1
解决办法
515
查看次数