【发布时间】:2018-08-10 22:34:01
【问题描述】:
我想同步两个Winforms Richtextboxes 的滚动。当 RTB2 被 scolled 时,RTB1 需要一直精确对齐。
我试图在这里转换这个 c#-Code LINK (second answer),但到目前为止失败了。所以我需要帮助。
现在它会产生多个错误:
Type [ScrollBarCommands] was not found...
Type [ScrollBarType] was not found....
Type [Message] was not found...
Also "illegal conversions" and so on.
这是一个示例脚本:
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object system.Windows.Forms.Form
$form.size = "400,400"
$rtb1 = New-Object system.Windows.Forms.RichTextBox
$rtb1.size = "190,350"
$rtb1.location = "200,1"
$rtb1.text = (1..300 | out-string)
$form.controls.add($rtb1)
$rtb2 = New-Object system.Windows.Forms.RichTextBox
$rtb2.size = "190,350"
$rtb2.location = "1,1"
$rtb2.text = (1..300 | out-string)
$rtb2.scrollbars = "none"
$form.controls.add($rtb2)
$code = @'
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 );
'@
Add-Type -Name WinUtils -MemberDefinition $code -Namespace User32
$rtb1.add_VScroll({
[uint32]$nPos = [User32.WinUtils]::GetScrollPos( $rtb1.Handle, [ScrollBarType]::SbVert )
[uint32]$npos = $nPos -shl 16
[uint32]$wParam = [ScrollBarCommands]::SB_THUMBPOSITION -bor $nPos
[User32.WinUtils]::SendMessage( $rtb2.Handle, [Message]::WM_VSCROLL, $wParam , [ref]0)
})
$form.showdialog()
编者,请注意:不是重复的,这是关于**Powershell的。 :)**
【问题讨论】:
标签: c# winforms powershell event-handling richtextbox