0

我想滚动 3 个不同的TextBoxes.

我在这里找到了一些方法。但在 VS2012 中我不能使用Windows.Forms非常烦人的。我确实尝试添加引用,但我发现没有Windows.Form,这是屏幕截图:

在此处输入图像描述 在此处输入图像描述

所以我找到了一个使用滚动条的想法,可以吗?

4

2 回答 2

1

为了使用windows.forms命名空间,您需要将System.windows.forms库添加到项目中:右键单击References(解决方案资源管理器)-> Add Reference-> .NET-Tab -> 选择System.Windows.Forms并单击确定。

然后,您可以在需要的每个文件中导入 System.Windows.Forms 命名空间。

于 2012-12-10T12:47:46.067 回答
1

http://www.gbogea.com/2009/07/08/how-to-keep-two-scrollviewers-in-sync-in-wpf

有代码。如果站点出现故障,将在此处复制粘贴作为镜像:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*" />
        <ColumnDefinition Width="1*" />
        <ColumnDefinition Width="1*" />
    </Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="0" Name="scrollViewerLeft" ScrollChanged="scrollViewerLeft_ScrollChanged">
    <ListBox>
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
        ...
        <ListBoxItem>100</ListBoxItem>
    </ListBox>
</ScrollViewer>
<ScrollViewer Grid.Column="1" Name="scrollViewerMiddle">
    <ListBox>
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
        ...
        <ListBoxItem>100</ListBoxItem>
    </ListBox>
 </ScrollViewer>
 <ScrollViewer Grid.Column="2" Name="scrollViewerRight">
    <ListBox>
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
        ...
        <ListBoxItem>100</ListBoxItem>
    </ListBox>
 </ScrollViewer>
</Grid>

以及背后的代码:

private void scrollViewerLeft_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    scrollViewerMiddle.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
    scrollViewerRight.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
}
private void scrollViewerMiddle_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    scrollViewerLeft.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
    scrollViewerRight.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
}
private void scrollViewerRight_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    scrollViewerLeft.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);
    scrollViewerMiddle.ScrollToVerticalOffset((sender as ScrollViewer).VerticalOffset);

}
于 2012-12-10T12:54:32.073 回答