Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
粘贴添加滚动条的文本时,C#WinForms UNDO(CRTL-Z)不起作用_C#_Winforms - Fatal编程技术网

粘贴添加滚动条的文本时,C#WinForms UNDO(CRTL-Z)不起作用

粘贴添加滚动条的文本时,C#WinForms UNDO(CRTL-Z)不起作用,c#,winforms,C#,Winforms,我添加了一个TextChanged函数来允许文本框的自动滚动行为, 它工作正常,快捷方式也可以工作,但当我粘贴了大于文本框大小的文本时,撤消(CTRL-Z)不起作用 这似乎是因为滚动条出现,然后出于某种原因,程序在剪贴板中没有过去的操作(粘贴)或类似的性质 这个函数中有什么我需要更改的吗?或者我是否需要找到一种方法来迭代剪贴板上的事件(如果可能的话)。我已经发布了用于创建AutoScroll效果的函数(在下面找到)。谢谢你的帮助 void TextBoxClass_TextChanged(obj

我添加了一个
TextChanged
函数来允许文本框的自动滚动行为, 它工作正常,快捷方式也可以工作,但当我粘贴了大于文本框大小的文本时,撤消(CTRL-Z)不起作用

这似乎是因为滚动条出现,然后出于某种原因,程序在剪贴板中没有过去的操作(粘贴)或类似的性质

这个函数中有什么我需要更改的吗?或者我是否需要找到一种方法来迭代剪贴板上的事件(如果可能的话)。我已经发布了用于创建AutoScroll效果的函数(在下面找到)。谢谢你的帮助

void TextBoxClass_TextChanged(object sender, EventArgs e)
{
    System.Drawing.Size textBoxRect = System.Windows.Forms.TextRenderer.MeasureText(
        this.Text, this.Font, new System.Drawing.Size(this.Width, int.MaxValue),
        System.Windows.Forms.TextFormatFlags.WordBreak | System.Windows.Forms.TextFormatFlags.TextBoxControl);
    try
    {
        if (textBoxRect.Height > this.Height)
        {
            this.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
            // I ADDED below line to make it stay scrolled to bottom..
            // ..when the scrollBars appear
            this.ScrollToCaret();
        }
        else
            this.ScrollBars = System.Windows.Forms.ScrollBars.None;
    }
    catch (System.ComponentModel.Win32Exception)
    {
        // this sometimes throws "failure to create window handle" error
        // This might happen if the TextBox is unvisible and/or
        // too small to display a toolbar.
    }
}

在文本框中添加属性键预览True这是正常的。分配Scrollbars属性将强制Winforms从头开始重新创建本机控件。底层.NET方法是Control.RecreateHandle()。当你密切关注时,你会看到文本框闪烁了几分之一秒。除了闪烁之外,它还有更多的副作用,是的,撤消缓冲区内容丢失。没有简单的解决方法,您无法还原撤消缓冲区。@Kutty在TextBox中找不到此属性。“我在表单中找到了它,并将其设置为真,但没有改变任何东西。”汉斯。谢谢你的信息。我想我会尝试在KeyDown事件中设置一个字符串来保存文本,然后在按下CTRL-Z时重新创建撤消。您考虑过使用RichTextBox吗?它应该具有内置的功能