0

I want to scroll 3 different TextBoxes.

I found some way in here. but in VS2012 I cannot using Windows.Forms which very annoying. I did try to add references but I found no Windows.Form there this is the screenshot:

enter image description here enter image description here

So I found an idea to use scrollbar, is it possible?

Community
  • 1
  • 1
Andy Surya
  • 117
  • 3
  • 9

2 Answers2

1

in order to use the windows.forms namespace you need to add the System.windows.forms library to your project: Rightclick References (Solution Explorer) -> Add Reference -> .NET-Tab -> select System.Windows.Forms and click ok.

Then you can import the System.Windows.Forms Namespace in every File you'll need it.

dognose
  • 20,360
  • 9
  • 61
  • 107
1

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

there is the code. will copy paste here as mirror if the site goes down:

<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>

and the code behind:

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);

}
JP Hellemons
  • 5,977
  • 11
  • 63
  • 128