b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

richtextbox 滚动

电脑杂谈  发布时间:2016-12-28 00:02:58  来源:网络整理
richtextbox 滚动

{S0}滚动周围RichTextBox控制

你们有些人可能会说关于现在,什么...!???!.那么,请继续阅读。因为其实我有一个需要垂直滚动在同一时间多个RichTextBox控件只有RichTextBoxes,滚动控制所有三他们。应该容易吧!是没有,至少从什么到目前为止,我发现。

我想在这一点上说,我欢迎所有在这个问题上,我可以得到的CP用户的输入。当我在互联网搜索,我发现这方面的资料很少。背景

(和其他控件)在RichTextBox,滚动消息VSCROLL / hscroll和THUMBPOSITION滚动条是不是相互关联的,正如人们所期望的的。在垂直线变化,或横向字符向左或向右滚动,VSCROLL / HSCROLL消息火灾事件和滚动条的动作,但新的拇指位置永远不会被发送。相反,RichTextBox的情况下,火灾事件RichTextBox1_VScroll(或_HScroll),但仍没有拇指的位置信息。这意味着在我的情况,"拇指不知道,其余的手在做什么。"

这到目前为止,是我来处理滚动他们。我还没有尝试过,但我认为这将也与其他文本控件,因为我没有看到这部分横向使用,包括下面的文章在CP。

MFC / C控制的一般 - 两个列表控件之间的同步滚动由亚历山大Khudyakov - 使用代码

它需要使用两个Windows API函数,GetScrollPosPostMessageA,和臭名昭著的NativeWindow类。

我选择了在最后一分钟不使用NativeWindow类发送GetScrollPos和PostMessageA消息,因为一个三线,神秘的解释SDK文档中说:"应用程序不应该,而不是直接发送这些消息,他们应该使用GetScrollPos的功能。一个窗口,通过它接收此消息WindowProc函数。应用实现一个自定义的滚动条控制必须应对这些消息GetScrollPos功能才能正常工作。"这适用于NativeWindow类,我还不知道,但我努力寻找答案,如果有人知道断手。我的原意是只使用NativeWindow类。

我处理的GetScrollPos和PostMessageA使用RichTextBox的VScroll / HSCROLL事件。

和WM_VSCROLL / WM_HSCROLL消息的处理NativeWindow类。{C}兴趣点

有一些小的毛刺,要注意的,如果你申请RichTextBoxes垂直线数或水平的字符数是不同的。滚动条将得到同步,直到拇指不会重新同步或Up事件再次被激发,时而动,在RichTextBox您选择的最后一个位置。在水平滚动它会使较短的明显"换血"。但是,这不是一个问题,在我的应用程序这为所有的垂直线数和水平的字符计数是相同的。

此外,不要关闭属性表中的滚动条,隐藏在面板控制或类似的事情。 "事件将不会触发禁用的滚动条和"未设置对象"一个方便的消息将出现!现在,我在做什么:

{S1}

我提交的页面顶部,因为它显示两个滚动的方向以及他们如何互动起来。完整的代码清单


Option Explicit On 



Imports System

Imports System.IO

Imports System.Data

Imports System.Text

Imports System.Drawing

Imports System.Collections

Imports System.Windows.Forms

Imports System.Windows.Forms.Message

Imports System.Runtime.InteropServices.Marshal



Public Class Form1

    Inherits System.Windows.Forms.Form



    '"Windows Form Designer generated code removed here"



    '===================================================================

    ' for NativeWindow and PostMessageA

    '===================================================================

    Private Const WM_HSCROLL = &H114

    Private Const WM_VSCROLL = &H115

    Private Const WM_MOUSEWHEEL = &H20A

    Private Const WM_COMMAND = &H111

    Private Const WM_USER = &H400

    '===================================================================

    ' for GetScroll and PostMessageA

    '===================================================================

    Private Const SBS_HORZ = 0

    Private Const SBS_VERT = 1

    Private Const SB_THUMBPOSITION = 4

    '===================================================================

    ' for SubClassing

    '===================================================================

    Private WithEvents sClass1 As Subclass

    Private WithEvents sClass2 As Subclass

    Private WithEvents sClass3 As Subclass



    Private Sub Form1_Load(ByVal sender As System.Object, _

      ByVal e As System.EventArgs) Handles MyBase.Load

        ' clear the rtb text

        RichTextBox1.Text = ""

        RichTextBox2.Text = ""

        RichTextBox3.Text = ""

        ' setup the sSubclass

        sClass1 = New Subclass(RichTextBox1.Handle)

        sClass2 = New Subclass(RichTextBox2.Handle)

        sClass3 = New Subclass(RichTextBox3.Handle)

        Dim i As Integer



        ' put some formated text in the RichTextBox's

        While i < 100

            RichTextBox1.AppendText(" this is a string " & i & vbCrLf)

            RichTextBox2.AppendText(" this is a string " & i & vbCrLf)

            RichTextBox3.AppendText(" this is a string " & i & vbCrLf)

            If i Mod 4 = 0 Then

                RichTextBox1.AppendText( _

                 " this is a longer string to force HScroll " & i & vbCrLf)

                RichTextBox2.AppendText( _

                 " this is a longer string to force HScroll " & i & vbCrLf)

                RichTextBox3.AppendText( _

                 " this is a longer string to force HScroll " & i & vbCrLf)

            End If

            i += 1

        End While

    End Sub

    Public Sub sClass_WindowProcedure( _ 

    ByRef uMsg As Message) Handles sClass1.WindowProcedure, _

     sClass2.WindowProcedure, sClass3.WindowProcedure

        Select Case uMsg.Msg

            Case WM_VSCROLL ' WM_VSCROLL Message's for RTB's

                If uMsg.HWnd.Equals(RichTextBox1.Handle) Then

                    'Debug.WriteLine(GetLowWord(uMsg.WParam.ToInt32))

                    RemoveHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                    Dim msg1 As Message

                    Dim msg2 As Message

                    msg1 = uMsg.Create(RichTextBox2.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    msg2 = uMsg.Create(RichTextBox3.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    sClass2.SendWndProc(msg1)

                    sClass2.SendWndProc(msg2)

                    AddHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                End If

                If uMsg.HWnd.Equals(RichTextBox2.Handle) Then

                    RemoveHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                    Dim msg1 As Message

                    Dim msg2 As Message

                    msg1 = uMsg.Create(RichTextBox1.Handle, _

                      uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    msg2 = uMsg.Create(RichTextBox3.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    sClass2.SendWndProc(msg1)

                    sClass2.SendWndProc(msg2)

                    AddHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                End If

                If uMsg.HWnd.Equals(RichTextBox3.Handle) Then

                    RemoveHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                    Dim msg1 As Message

                    Dim msg2 As Message

                    msg1 = uMsg.Create(RichTextBox1.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    msg2 = uMsg.Create(RichTextBox2.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    sClass2.SendWndProc(msg1)

                    sClass2.SendWndProc(msg2)

                    AddHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                End If

            Case WM_HSCROLL ' WM_HSCROLL Message's for RTB's

                If uMsg.HWnd.Equals(RichTextBox1.Handle) Then

                    'Debug.WriteLine(GetLowWord(uMsg.WParam.ToInt32))

                    RemoveHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                    Dim msg1 As Message

                    Dim msg2 As Message

                    msg1 = uMsg.Create(RichTextBox2.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    msg2 = uMsg.Create(RichTextBox3.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    sClass2.SendWndProc(msg1)

                    sClass2.SendWndProc(msg2)

                    AddHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                End If

                If uMsg.HWnd.Equals(RichTextBox2.Handle) Then

                    RemoveHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                    Dim msg1 As Message

                    Dim msg2 As Message

                    msg1 = uMsg.Create(RichTextBox1.Handle, _ 

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    msg2 = uMsg.Create(RichTextBox3.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    sClass2.SendWndProc(msg1)

                    sClass2.SendWndProc(msg2)

                    AddHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                End If

                If uMsg.HWnd.Equals(RichTextBox3.Handle) Then

                    RemoveHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                    Dim msg1 As Message

                    Dim msg2 As Message

                    msg1 = uMsg.Create(RichTextBox1.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    msg2 = uMsg.Create(RichTextBox2.Handle, _

                     uMsg.Msg, uMsg.WParam, uMsg.LParam)

                    sClass2.SendWndProc(msg1)

                    sClass2.SendWndProc(msg2)

                    AddHandler sClass2.WindowProcedure, _

                     AddressOf sClass_WindowProcedure

                End If

        End Select

    End Sub



    Private Sub RichTextBox1_VScroll(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles RichTextBox1.VScroll

        Dim RTB1Position As Integer

        RTB1Position = GetScrollPos(RichTextBox1.Handle, SBS_VERT)

        PostMessageA(RichTextBox2.Handle, WM_VSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTB1Position, 0)

        PostMessageA(RichTextBox3.Handle, WM_VSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTB1Position, 0)

    End Sub

    Private Sub RichTextBox2_VScroll(ByVal sender As Object,_

     ByVal e As System.EventArgs) Handles RichTextBox2.VScroll

        Dim RTB2Position As Integer

        RTB2Position = GetScrollPos(RichTextBox2.Handle, SBS_VERT)

        PostMessageA(RichTextBox1.Handle, WM_VSCROLL,_

         SB_THUMBPOSITION + &H10000 * RTB2Position, 0)

        PostMessageA(RichTextBox3.Handle, WM_VSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTB2Position, 0)

    End Sub

    Private Sub RichTextBox3_VScroll(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles RichTextBox3.VScroll

        Dim RTBosition As Integer

        RTBosition = GetScrollPos(RichTextBox3.Handle, SBS_VERT)

        PostMessageA(RichTextBox1.Handle, WM_VSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTBosition, 0)

        PostMessageA(RichTextBox2.Handle, WM_VSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTBosition, 0)

    End Sub

    Private Sub RichTextBox1_HScroll(ByVal sender As Object,_

     ByVal e As System.EventArgs) Handles RichTextBox1.HScroll

        Dim RTB1Position As Integer

        RTB1Position = GetScrollPos(RichTextBox1.Handle, SBS_HORZ)

        PostMessageA(RichTextBox2.Handle, WM_HSCROLL,_

         SB_THUMBPOSITION + &H10000 * RTB1Position, 0)

        PostMessageA(RichTextBox3.Handle, WM_HSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTB1Position, 0)

    End Sub

    Private Sub RichTextBox2_HScroll(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles RichTextBox2.HScroll

        Dim RTB2Position As Integer

        RTB2Position = GetScrollPos(RichTextBox2.Handle, SBS_HORZ)

        PostMessageA(RichTextBox1.Handle, WM_HSCROLL,_

         SB_THUMBPOSITION + &H10000 * RTB2Position, 0)

        PostMessageA(RichTextBox3.Handle, WM_HSCROLL,_

         SB_THUMBPOSITION + &H10000 * RTB2Position, 0)

    End Sub



    Private Sub RichTextBox3_HScroll(ByVal sender As Object,_

     ByVal e As System.EventArgs) Handles RichTextBox3.HScroll

        Dim RTBosition As Integer

        RTBosition = GetScrollPos(RichTextBox3.Handle, SBS_HORZ)

        PostMessageA(RichTextBox1.Handle, WM_HSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTBosition, 0)

        PostMessageA(RichTextBox2.Handle, WM_HSCROLL, _

        SB_THUMBPOSITION + &H10000 * RTBosition, 0)

    End Sub

    '===================================================================

    ' API Function: GetScrollPos

    '===================================================================

    Private Declare Function GetScrollPos Lib "user32.dll" ( _

        ByVal hWnd As IntPtr, _

        ByVal nBar As Integer) As Integer

    '===================================================================

    ' API Function: PostMessageA

    '===================================================================

    Private Declare Function PostMessageA Lib "user32.dll" ( _

        ByVal hwnd As IntPtr, _

        ByVal wMsg As Integer, _

        ByVal wParam As Integer, _

        ByVal lParam As Integer) As Boolean

    '===================================================================

    ' Temporary Functions for the Debugger

    '===================================================================

    Public Function GetLowWord(ByRef pintValue As Int32) As Int32

        Return pintValue And &HFFFF

    End Function

    Public Function GetLowWord(ByRef pudtValue As IntPtr) As Int32

        Return GetLowWord(pudtValue.ToInt32)

    End Function

    Public Function GetHighWord(ByRef pintValue As Int32) As Int32

        If (pintValue And &H80000000) = &H80000000 Then

            Return ((pintValue And &H7FFF0000) \ &H10000) Or &H8000&

        Else

            Return (pintValue And &HFFFF0000) \ &H10000

        End If

    End Function

    '===================================================================

    ' End Temporary Functions for the Debugger

    '===================================================================

End Class



Public Class Subclass

    '===================================================================

    ' NativeWindow Subclassing

    '===================================================================

    Inherits System.Windows.Forms.NativeWindow

    Public Event WindowProcedure(ByRef uMsg As Message)



    Public Sub New(ByVal pWindowHandle As IntPtr)

        MyBase.AssignHandle(pWindowHandle)

    End Sub



    Protected Overrides Sub WndProc( _

     ByRef uMsg As System.Windows.Forms.Message)

        MyBase.WndProc(uMsg)

        RaiseEvent WindowProcedure(uMsg)

    End Sub



    Public Sub SendWndProc(ByRef uMsg As System.Windows.Forms.Message)

        MyBase.WndProc(uMsg)

    End Sub



End Class

请随时让我知道如果我重新发明轮子这里,也有可能是一种更好的方式,我可以使用的反馈。历史 提交:周一,7月26日,2004年

我是一名编程爱好者,

谢谢orcode.com为我们提供一个学习和分享的平台。

嗨,我已经在我的文本框是不同的大小和字体大小的情况是不同的,但内容是一样的,如何syncc这个

关于

阿伦

谢谢你,

非常好,我完成了我与你的示例代码程序。richtextbox 滚动我想synchr。几个文本框,其中只有一个(主)有一个垂直滚动条和其他应当遵循

我觉得这是在最初设计中的一个错误。由于所有其他所有酒吧的消防移动时,手动控制程序是一个无限循环受阻。然后在Form1终止是不可能的。

的问候,

Rolfo1

您的欢迎。是的,原来的代码是对VS 7.1,但如果你的消息"滚动测试代码VB2005"你会发现我在VB发布的VS 2005的测试代码。它也将在VS2008。谢谢

张贴在这里找到了:

该代码修复滚动的问题,我看到。下面是一个完整的的代码示例。

请注意,这并不解决键盘输入,将光标移动周围,只有鼠标拖动滚动条。

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Runtime.InteropServices;

 

namespace ScrollSynching

{

    /// <summary>

    /// RichTextBox that you can synch scrolling with other RichTextBox controls 

    /// 

    /// @author David M. Schulze

    /// </summary>

    public partial class RichTextBoxSynchScroll : RichTextBox

    {

 

        #region ScrollMessages

        /// <summary>

        /// Windows scrolling messages

        /// </summary>

        private enum ScrollMessages : uint

        {

            WM_HSCROLL = 0x0114,

            WM_VSCROLL = 0x0115

        }

        #endregion

 



        #region richedit.h Flags

        /// <summary>

        /// Constants coming out of the richedit.h header file

        /// </summary>

        private enum RichEditFlags : int

        {

            EM_GETSCROLLPOS = 0x400 + 221,

            EM_SETSCROLLPOS = 0x400 + 222

        }

        #endregion

 

        /// <summary>

        /// Used to adjust scrolling due to 65536 pixels limit

        /// </summary>

        private double _Yfactor = 1.0d;

 



        /// <summary>

        /// Windows SendMessage 

        /// </summary>

        /// <param name="hWnd"></param>

        /// <param name="msg"></param>

        /// <param name="wParam"></param>

        /// <param name="lParam"></param>

        /// <returns></returns>

        [System.Runtime.InteropServices.DllImport("User32", EntryPoint = "SendMessageA", ExactSpelling = false, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]

        private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, ref Point lParam);

 

        /// <summary>

        /// Default Constructor

        /// </summary>

        public RichTextBoxSynchScroll()

        {

            InitializeComponent();

        }

 

        

        /// <summary>

        /// Property to get/set the controls scroll position

        /// 

        /// You are going to run into problems if the textbox is larger that 65536 pixels.

        /// Thus the need to use YFactor

        /// </summary>

        public Point ScrollPos

        {

            get

            {

                Point scrollPoint = new Point();                

                SendMessage(this.Handle, (int)RichEditFlags.EM_GETSCROLLPOS, IntPtr.Zero, ref scrollPoint);

                return scrollPoint;

            }

            set

            {

                Point original = value;

                if (original.Y < 0)

                    original.Y = 0;

                if (original.X < 0)

                    original.X = 0;

 

                Point factored = value;

                factored.Y = (int)((double)original.Y * _Yfactor);

 

                Point result = value;

 

                SendMessage(this.Handle, (int)RichEditFlags.EM_SETSCROLLPOS, IntPtr.Zero, ref factored);

                SendMessage(this.Handle, (int)RichEditFlags.EM_GETSCROLLPOS, IntPtr.Zero, ref result);

 

                int loopcount = 0;

                int maxloop = 100;

                while (result.Y != original.Y)

                {

                    // Adjust the input.

                    if (result.Y > original.Y)

                        factored.Y -= (result.Y - original.Y) / 2 - 1;

                    else if (result.Y < original.Y)

                        factored.Y += (original.Y - result.Y) / 2 + 1;

 

                    // test the new input.

                    SendMessage(this.Handle, (int)RichEditFlags.EM_SETSCROLLPOS, IntPtr.Zero, ref factored);

                    SendMessage(this.Handle, (int)RichEditFlags.EM_GETSCROLLPOS, IntPtr.Zero, ref result);

 

                    // save new factor, test for exit.

                    loopcount++;

                    if (loopcount >= maxloop || result.Y == original.Y)

                    {

                        _Yfactor = (double)factored.Y / (double)original.Y;

                        break;

                    }

                }

            }

        }

 

        /// <summary>

        /// Static list of scroll bars that we wish to keep in synch

        /// </summary>

        static List<RichTextBoxSynchScroll> synchedScrollBarsList = null;

 

        /// <summary>

        /// Add RichTextBoxSynchScroll controls so we can make them scroll together

        /// </summary>

        /// <param name="ctrl"></param>

        static public void AddToSynch(RichTextBoxSynchScroll ctrl)

        {

            if((ctrl == null) || (ctrl.Handle == IntPtr.Zero))

            {

                throw new ArgumentNullException("ctrl is null");

            }

 

            if (synchedScrollBarsList == null)

            {

                synchedScrollBarsList = new List<RichTextBoxSynchScroll>(2);

            }

 

            synchedScrollBarsList.Add(ctrl);

        }

 

        /// <summary>

        /// Remove RichTextBoxSynchScroll controls from synching

        /// </summary>

        /// <param name="ctrl"></param>

        static public void RemoveFromSynch(RichTextBoxSynchScroll ctrl)

        {

            if ((ctrl == null) || (ctrl.Handle == IntPtr.Zero))

            {

                throw new ArgumentNullException("ctrl is null");

            }

 

            if (synchedScrollBarsList != null)

            {

                if (synchedScrollBarsList.Contains(ctrl))

                {

                    synchedScrollBarsList.Remove(ctrl);

                }

                else

                {

                    throw new ArgumentOutOfRangeException("ctrl not currently synched");

                }

            }

        }

 

        /// <summary>

        /// Override the windows message loop so I can tell when scrolling happens

        /// That way I can set all the other controls to the same scroll position

        /// </summary>

        /// <param name="m"></param>

        protected override void WndProc(ref Message m)

        {

            if (m.Msg == (int)ScrollMessages.WM_VSCROLL)

            {

                foreach (RichTextBoxSynchScroll scrollBar in synchedScrollBarsList)

                {

                    if (scrollBar != this)

                    {

                        scrollBar.ScrollPos = this.ScrollPos;

                    }

                }

            }

 

            if (m.Msg == (int)ScrollMessages.WM_HSCROLL)

            {

                foreach (RichTextBoxSynchScroll scrollBar in synchedScrollBarsList)

                {

                    if (scrollBar != this)

                    {

                        scrollBar.ScrollPos = this.ScrollPos;

                    }

                }

            }

 

            base.WndProc(ref m);

        }

 

    }

 

}

我使用的Visual C 2005 Express版(Whidbey的),我试图转换旧的C语法,但我在这部分stucked:

/ / ================================================ ==================={ BR}/ / NativeWindow的子类

/ / ================================================ ===================

__gc的子类:公开制度::视窗:形式:NativeWindow的

{

市民:

__delegate无效WindowsEventHandler(对象发件人,消息* uMsg)

__event WindowsEventHandler * NativeWindowsEvent

子类(IntPtr的pWindowHandle)

{

这个GT; AssignHandle(pWindowHandle);

}

SendWndProc无效(系统:视窗:形式:消息* uMsg)

{

__super:的WndProc(uMsg)

}

保护:无效的WndProc(系统:视窗:形式:消息* uMsg)

{

__super:的WndProc(uMsg)

(NativeWindowsEvent = 0)

NativeWindowsEvent(这一点,uMsg);}

}

转换:

/ / ================================================ ==================={ BR}/ / NativeWindow的子类

/ / ================================================ ===================

文献的子类:公开制度::视窗:形式:NativeWindow的

{

市民:委托无效WindowsEventHandler(对象^发件人,消息^ uMsg)

事件WindowsEventHandler ^ NativeWindowsEvent;

子类(IntPtr的pWindowHandle){

这个GT; AssignHandle(pWindowHandle);

}

SendWndProc无效(系统:视窗:形式:消息^ uMsg){

这个GT的WndProc(uMsg)/ / __super:的WndProc(uMsg)

}

保护:无效的WndProc(系统:视窗:形式:消息^ uMsg){

这个GT的WndProc(uMsg)/ / __super:的WndProc(uMsg)

(NativeWindowsEvent!= nullptr)

NativeWindowsEvent(这一点,uMsg);}

/ /私有:NativeWindowsEvent(对象^发件人,消息^ uMsg)

}

该错误是大胆的一部分:

错误C3918:使用需要的"项目名称::子类:NativeWindowsEvent"是一个数据成员,看到宣言"项目::子:NativeWindowsEvent"

如何解决这个问题?

非常感谢您。

短得多codeing

嗨,我试图在VS 2005编译此代码,这是行不通的这似乎挂起。

你能帮助吗?

感谢

尼斯的工作。

我想知道,如果您的解决方案仍然有效时RichTextBoxes用板取代。例如有2个小组,每个人都有一个PictureBox。但小组没有Panel.VScroll / HSCROLL事件。你有任何解决这个问题呢?感谢。

大卫叶

此解决方案:尝试从麦克obrien

对我的作品。

麦克定义一个类,它的整个工作。这个解决方案是我见过的比任何其他更为灵活。

你只需要在您的项目整合他类(clsRTFScrollSync),这个类的新实例添加到您的项目:

私人objScrollSync作为新clsRTFScrollSync

在窗体的Form_Load事件中,您要添加文本框要sychronized:

私人小组Form1_Load的(...)...

ScrollBars.Vertical objScrollSync.ScrollBarToSync =

objScrollSync.AddControl(RichTextBox1的)

objScrollSync.AddControl(RichTextBox2)

END SUB

这就是所有。

我没有签出在VB2005所有新的消息系统,但这里是在VS2005中,如果任何人想给它一个尝试新的测试代码(基于旧代码)

{BR }---------------------------------------- ---------------------{ BR}

选项

NBSP明确;

System.IO { BR}System.Data

System.Text

System.CollectionsSystem.Drawing

System.Windows.Forms的System.Windows.Forms.Message

System.Runtime.InteropServices.Marshal

公共类Form1

继承System.Windows.Forms.Form中

#地区的"Windows窗体设计器生成的代码"

的Public Sub New()

MyBase.New() NBSP

该调用是Windows窗体设计器所必需的

- ; 的InitializeComponent()

添加任何初始化后的InitializeComponent()调用

NBSP - ; 结束小组

窗体重写dispose以清理组件列表

- ; 覆盖保护重载小组的Dispose(BYVAL处置作为布尔)

如果处理,然后

- ; NBSP 然后 如果没有(组件为Nothing)

components.Dispose()

如果

NBSP结束;NBSP ; 结束如果

MyBase.Dispose(处置)

END SUB

{BR }"Windows窗体设计器

NBSP要求;System.ComponentModel.IContainer

NBSP私有组件;

NBSP 注意:以下过程是Windows窗体设计器

NBSP需要,可以使用Windows窗体Designer.nbsp修改;

。System.Windows.Forms.RichTextBox

NBSP朋友WithEvents RichTextBox1的作为;朋友WithEvents RichTextBox2 AS系统。

Windows.Forms.RichTextBox朋友WithEvents RichTextBox3作为System.Windows.Forms.RichTextBox

LT; System.Diagnostics.DebuggerStepThrough()GT;私人小组的InitializeComponent()

Me.RichTextBox1 =新System.Windows.Forms.RichTextBox

- ; Me.RichTextBox2 =新System.Windows.Forms.RichTextBox

Me.RichTextBox3 =新System.Windows.Forms.RichTextBox

- ;Me.SuspendLayout()

- ;RichTextBox1的"

NBSP Me.RichTextBox1.Location =新(24,24)

Me.RichTextBox1.Name ="RichTextBox1的"

NBSP ; - ;Me.RichTextBox1.Size =新System.Drawing.Size(128,128)

NBSP ; Me.RichTextBox1.TabIndex = 0

Me.RichTextBox1.Text ="RichTextBox1的"

NBSP ; - ; Me.RichTextBox1.WordWrap =假

NBSP ;"RichTextBox2

Me.RichTextBox2.Location =新系统(160,24)。Drawing.Point

Me.RichTextBox2.Name ="RichTextBox2"

Me.RichTextBox2.Size =新System.Drawing.Size(128,128)

Me.RichTextBox2.TabIndex = 1 { BR}Me.RichTextBox2.Text ="RichTextBox2"

Me.RichTextBox2。自动换行=假

"RichTextBox3

NBSP - ;

Me.RichTextBox3.Location =新(296,24)

Me.RichTextBox3.Name ="RichTextBox3"

Me.RichTextBox3 。大小(128,128)=新System.Drawing.Size

Me.RichTextBox3.TabIndex = 3

- ; NBSP - ; - ; Me.RichTextBox3.Text =

"RichTextBox3"Me.RichTextBox3.WordWrap =假

NBSP - ;

NBSP Form1的"

- ;

Me.AutoScaleBaseSize =新System.Drawing.Size(5,13)

- ;Me.ClientSize =新System.Drawing.Size(448,174)

Me.Controls.Add(Me. RichTextBox3)

Me.Controls.Add(Me.RichTextBox2)

Me.Controls.Add(Me.RichTextBox1)

Me.Name ="Form1的"

NBSPMe.Text ="Form1的"

Me.ResumeLayout(FALSE)

NBSP END SUB

地区====================== ============================================={ BR}"的NativeWindow和PostMessageA

- ;=========================== ========================================{ BR}NBSP作为整数=安培的私人常量WM_USER; H400

私人CONST的WM_COMMAND作为整数=&H111

私人CONST WM_HSCROLL作为整数=&H114

整数=安培私人CONST WM_VSCROLL; H115

整数=安培私人CONST EN_UPDATE; H400 NBSP

整数=安培私人CONST EM_GETTHUMB; HBE

为整数= 0 {BR私人CONST SBS_HORZ为整数}作为整数= 1

NBSP私人CONST SBS_VERT;

私人CONST SB_THUMBPOSITION = 4

================================================= =================={ BR}"子类

====== ================================================== ==========={ BR}私人WithEvents sClass1作为子类

私人WithEvents作为子类sClass2

sClass3私人WithEvents作为子类

私人WithEvents sClassF作为子类

Form1_Load的小组(BYVAL发件人作为System.Object的BYVAL作为System.EventArgs E)把手

MyBase.Load"明确RTB的文字

NBSP - ; - ; RichTextBox1.Text ="

RichTextBox2.Text ="

NBSP - ; - ; RichTextBox3.Text ="

"设置sSubclass

NBSP - ; sClass1 =新的子类(RichTextBox1.Handle)

sClass2 =新的子类(RichTextBox2.Handle)

NBSP ; - ;- ; sClass3 =新的子类(RichTextBox3.Handle)

sClassF =新的子类(Me.Handle) NBSP

DIM我为整数

"把一些格式化的RichTextBox中的

NBSP文本;虽然我LT; 100

RichTextBox1.AppendText("这是一个字符串"放大器;我放大器; vbCrLf)

RichTextBox2.AppendText("这是一个字符串"放大器;我放大器; vbCrLf)

RichTextBox3.AppendText("本是一个字符串"放大器;我放大器; vbCrLf)

如果我MOD 4 = 0,那么

- ;RichTextBox1.AppendText("这是一个较长的字符串强制HSCROLL"放大器;我安培; vbCrLf )

RichTextBox2.AppendText("这是一个较长的字符串力HSCROLL"放大器;我安培; vbCrLf)

RichTextBox3.AppendText("这是一个更长的字符串,迫使HSCROLL"放大器;我放大器; vbCrLf)

如果

NBSP结束; NBSP - ;我= 1

月底的

END SUB

公共子sClass_WindowProcedure(为ByRef作为消息uMsg)处理sClass1.WindowProcedure,sClass2.WindowProcedure,sClass3.WindowProcedure sClassF.WindowProcedure

NBSP ; - ;选择案例uMsg.Msg

RTB的案例WM_VSCROLL"WM_VSCROLL消息的

如果uMsg.HWnd.Equals(RichTextBox1.Handle)

- ;Debug.WriteLine(GetLowWord(uMsg.WParam ToInt32))

RemoveHandler sClass1。 WindowProcedure,AddressOf sClass_WindowProcedure

sClass1.SendWndProc (Message.Create(RichTextBox2.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

NBSP ; - ;sClass1.SendWndProc(Message.Create(RichTextBox3.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

NBSP ; - ;的AddHandler sClass1.WindowProcedure,AddressOf sClass_WindowProcedure

NBSP - ;如果

NBSP结束;- ;如果uMsg.HWnd.Equals(RichTextBox2.Handle)

NBSP ; - ;RemoveHandler sClass2.WindowProcedure,AddressOf sClass_WindowProcedure

NBSP ; - ;sClass2.SendWndProc(Message.Create(RichTextBox1.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

NBSP ; - ;sClass2.SendWndProc(Message.Create(RichTextBox3.Handle,uMsg.Msg uMsg.WParam,uMsg.LParam))

NBSP 的AddHandler sClass2.WindowProcedure,AddressOf sClass_WindowProcedure

结束如果

- ;如果uMsg.HWnd.Equals(RichTextBox3.Handle)

- ; NBSP ; - ;RemoveHandler sClass3.WindowProcedure,AddressOf sClass_WindowProcedure

NBSP ; - ;sClass3.SendWndProc(Message.Create(RichTextBox1.Handle,uMsg味精,uMsg.WParam,uMsg.LParam))

NBSP - ; sClass3.SendWndProc(Message.Create(RichTextBox2.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

NBSP ; - ;的AddHandler sClass3.WindowProcedure,AddressOf sClass_WindowProcedure

NBSP ;NBSP NBSP NBSP NBSP 结束如果

案例WM_HSCROLL"WM_HSCROLL消息的为RTB的

如果uMsg.HWnd.Equals(RichTextBox1.Handle){BR }Debug.WriteLine(GetLowWord(uMsg. WParam.ToInt32))

RemoveHandler sClass1 WindowProcedure,AddressOf sClass_WindowProcedure

sClass1。 SendWndProc(Message.Create(RichTextBox2.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

- ;sClass1.SendWndProc(Message.Create(RichTextBox3.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

- ;的AddHandler sClass1.WindowProcedure,AddressOf sClass_WindowProcedure

- ;如果

NBSP结束;NBSP ; - ;如果uMsg.HWnd.Equals(RichTextBox2.Handle)

- ;RemoveHandler sClass2.WindowProcedure,AddressOf sClass_WindowProcedure

- ;sClass2.SendWndProc(Message.Create(RichTextBox1.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

- ;sClass2.SendWndProc(Message.Create(RichTextBox3.Handle,uMsg。味精,uMsg.WParam,uMsg.LParam))

- ; 的AddHandler sClass2.WindowProcedure,AddressOf sClass_WindowProcedure

结束如果{BR }如果uMsg.HWnd.Equals(RichTextBox3.Handle)

- ;RemoveHandler sClass3.WindowProcedure,AddressOf sClass_WindowProcedure

- ;sClass3.SendWndProc(Message.Create(RichTextBox1.Handle uMsg.Msg,uMsg.WParam,uMsg.LParam))

sClass3.SendWndProc(Message.Create(RichTextBox2.Handle,uMsg.Msg,uMsg.WParam,uMsg.LParam))

- ;的AddHandler sClass3.WindowProcedure,AddressOf sClass_WindowProcedure

- ;结束如果

案例的WM_COMMAND"Form1的命令

如果uMsg.LParam.Equals(RichTextBox1.Handle){BR }"Debug.WriteLine("低:"放大器; GetLowWord(uMsg.WParam.ToInt32))

- ; "Debug.WriteLine("高"放大器; GetHighWord(uMsg.WParam.ToInt32))

NBSP ; - ;DIM rtbUpdate为整数= GetHighWord(uMsg.WParam.ToInt32)

NBSP - ;EN_UPDATE通知消息被发送时,

- ;NBSP,"因此,我们将寻找EN_UPDATE事件消息

NBSP - ;如果rtbUpdate = EN_UPDATE"(1024)

NBSP ; - ;EM_GETTHUMB消息检索{BR的位置}"在垂直滚动条的滚动框(拇指)

NBSP ; - ;"(TODO:在为什么没有水平的消息,我可以找到)

NBSP - ;DIM MSG1作为消息

- ;uMsg.Msg = EM_GETTHUMB

- ;MSG1 = Message.Create(RichTextBox1.Handle uMsg.Msg,IntPtr.Zero,IntPtr.Zero)

NBSP - ;发送消息

NBSP ; - ;RemoveHandler sClass1.WindowProcedure,AddressOf sClass_WindowProcedure

NBSP - ;sClass1.SendWndProc(MSG1)

- ;的AddHandler sClass1.WindowProcedure,AddressOf sClass_WindowProcedure

- ;Debug.WriteLine("Msg1.Result: "AMP; msg1.Result.ToInt32)

- ;"确保我们重新发送邮件rtb1情况下,我们是

NBSP rtb2或rtb3;NBSP - ;SetScrollPos(RichTextBox1.Handle,SBS_VERT,msg1.Result.ToInt32,TRUE)

- ;SetScrollPos(RichTextBox2.手柄,SBS_VERT,msg1.Result.ToInt32,TRUE)

NBSP - ;SetScrollPos(RichTextBox3.Handle,SBS_VERT,msg1.Result.ToInt32,TRUE)

- ;如果

NBSP结束;NBSP - ;结束如果

最终选择

END SUB

私人函数GetScrollPos LIB"USER32.DLL"(_

#的IntPtr HWND,_ {BR }BYVAL NBAR为整数)为整数

私人声明函数SetScrollPos LIB"USER32.DLL" (_

#的IntPtr HWND,_,

BYVAL NBAR为整数_

BYVAL非营利组织作为整数,_

BYVAL bRedraw为布尔)作为整数

私人函数PostMessageA LIB"USER32.DLL"(_

作为IntPtr的BYVAL HWND _

BYVAL WMSG为整数,_

BYVAL wParam的整数,_

BYVAL lParam的整数)为整数

NBSP"HSCROLL NBSP

分RichTextBox1_HScroll(BYVAL发件人为对象,BYVAL e由于)处理RichTextBox1.HScroll

NBSP 如果Control.MouseButtons = Windows.Forms.MouseButtons.Left然后退出小组

如果Me.RichTextBox1.ContainsFocus然后

NBSP{

{

的InitializeComponent()

}

[DllImport("USER32.DLL")]

[DllImport("USER32.DLL")]

{

返回

{

}

}

{

{

}

}

{

返回

{

}

}

{

{

}

}

{

}

{

}

{

}

{

{

{

{

}

{

}

打破;

}

{

{

}

{

}

打破;

}

{

{

{

}

}

{

{

}

}

打破;

}

}

}

}

{

{

}

{

}

{

}

谢谢你,

您好,

{A5}

{A6}

{A7}

任何想法?

/ / Form1.h{

使用命名空间系统;

使用命名空间System::数据;

使用命名空间System::绘图;

使用命名空间System::集合

使用命名空间System::视窗:表格;

使用命名空间System:运行:InteropServices;

{

市民:

{

}

{

}

{

}

}

[DllImport("USER32.DLL")]

[DllImport("USER32.DLL")]

/ / /

/ / /摘要为Form1

/ / /

/ / /警告:如果你改变这个类的名字,你将需要改变

/ / /"资源文件名"属性的托管资源编译器工具

/ / /这个类依赖于所有。resx文件关联。否则,

/ / /设计器将不能够交互本地化

正确/ / /与此窗体关联的资源。

/ / /

公共__gc类Form1的公开制度:视窗:表格:表格

{

市民:

Form1的(无效)

{

的InitializeComponent()

}

保护:

无效的Dispose(布尔处置)

{

{

}

}

}

/ / /

{

> SuspendLayout()

/ /

/ /

/ /

/ /

/ /

/ /

/ /

/ / Form1的

/ /

本 - > ResumeLayout(FALSE);

}

}

{

}

}

}

{

{{

{

}

{

}

打破;

}

} {

{

}

}

{

}

{

}

{

}

{

}

{

}

{

}

{

{

} } {

{

}

}

}

}

#包括"stdafx.h中"

{返回0;}

使用系统;丢个System.IO;使用System.Data这;使用System.Text;使用System.Drawing;使用System.Collections;使用System.Windows.Forms;使用System.Runtime.InteropServices; {{ {} {{}}} { } {} { }{}}} {{}{}{}{}{}{}}} {}}{} {} {} {} {} {} {} }{}}} {{} {} {


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23631-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...