Does WinForms have a similar control like scrollviewer in WPF?
I would like to achieve something like below in WinForms
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="178" Width="306" Visibility="Visible">
<ScrollViewer HorizontalScrollBarVisibility="Auto" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Margin="5" Grid.Column="0" Grid.Row="0">Value 1:</Label>
<Label Margin="5" Grid.Column="0" Grid.Row="1">Value 2:</Label>
<Label Margin="5" Grid.Column="0" Grid.Row="2">Value 3:</Label>
<RichTextBox Margin="5" Grid.Column="1" Grid.Row="0" MinWidth="100" />
<RichTextBox Margin="5" Grid.Column="1" Grid.Row="1" MinWidth="100" />
<RichTextBox Margin="5" Grid.Column="1" Grid.Row="2" MinWidth="100" />
</Grid>
</ScrollViewer>
</Window>
A single scrollbar per windows/forms, child control does not have any scrollbar
and child control are auto expand accordingly to the contain of that control.
When user type word in the control like textbox, current focus position are always visible in the screen.
Thanks
| | matrixgoh Monday, June 01, 2009 4:42 PM | Hi matrixgoh,
The better solution is host WPF control into Winform application. Please look at this example. http://msdn.microsoft.com/en-us/library/ms742215.aspx
You need an ElementHost in your form. Here is the code to host it(you can find it in the sample). // Create the ElementHost control for hosting the // WPF UserControl. ElementHost host = new ElementHost(); host.Dock = DockStyle.Fill;
// Create the WPF UserControl. HostingWpfUserControlInWf.UserControl1 uc = new HostingWpfUserControlInWf.UserControl1();
// Assign the WPF UserControl to the ElementHost control's // Child property. host.Child = uc;
// Add the ElementHost control to the form's // collection of child controls. this.Controls.Add(host);
Hope this helps.
PS: 4G ram should be great, do you have a dual core CPU?
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorMonday, June 15, 2009 8:29 AM
-
| | Kira Qian Wednesday, June 03, 2009 3:50 AM | Hi matrixgoh,
No, it cannot support both.
Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byKira QianMSFT, ModeratorMonday, June 15, 2009 8:29 AM
-
| | Kira Qian Wednesday, June 03, 2009 7:36 AM | Hi matrixgoh,
The Panel control in Winform should be the closer control to ScrollView in WPF.
You can drag a panel from the Toolbox in Visual Studio designer, set its AutoScroll property to true.
Does it meet your needs?
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. | | Kira Qian Wednesday, June 03, 2009 2:28 AM | Hi,Kira Qian
Actually ScrollViewer in WPF is dam cool stuff, is not like panel control in winforms.
I did simple customize to a multiline textbox auto resize height when user type.
It was work fine, panel control scrollbar auto appear when textbox height is larger.
the user need to manually adjust the scrollbar to the bottom for continue typing in the textbox, because the current lines in the textbox is now below the panel viewable zone.
if user use keyboard arrow up and down key to navigate to that particular lines in the textbox, panel will not scroll accordingly.
Where all this is work in WPF...
I think WPF really meet the user experience expectation, it just got one problem; slow running with my notebook.
| | matrixgoh Wednesday, June 03, 2009 3:07 AM | Hi matrixgoh,
Yes, you are correct. WPF is recognize as the most powerful desktop develop technology. The function and appearance of winform control does not as rich as WPF. Even when you override the method of the control to extend its function, it won't as smooth as WPF built in control.
But when running a WPF application, it need to explain baml file located in assembly, that cost time for a comput without good hardware support. So base on my experience, if a laptop can run Vista smoothly, it sure can run WPF smoothly.
Here is a document talking about WPF performance. http://msdn.microsoft.com/en-us/library/aa970683.aspx
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. | | Kira Qian Wednesday, June 03, 2009 3:25 AM | Kira Qian,
I running Windows Server 2008 64bits with 4GB Ram I feel slow when running the WPF application,to develop WPF is event worse.
Users are running Windows XP, that why I still prefer using winforms, I just need one of the function in WPF. | | matrixgoh Wednesday, June 03, 2009 3:29 AM | Hi matrixgoh,
The better solution is host WPF control into Winform application. Please look at this example. http://msdn.microsoft.com/en-us/library/ms742215.aspx
You need an ElementHost in your form. Here is the code to host it(you can find it in the sample). // Create the ElementHost control for hosting the // WPF UserControl. ElementHost host = new ElementHost(); host.Dock = DockStyle.Fill;
// Create the WPF UserControl. HostingWpfUserControlInWf.UserControl1 uc = new HostingWpfUserControlInWf.UserControl1();
// Assign the WPF UserControl to the ElementHost control's // Child property. host.Child = uc;
// Add the ElementHost control to the form's // collection of child controls. this.Controls.Add(host);
Hope this helps.
PS: 4G ram should be great, do you have a dual core CPU?
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorMonday, June 15, 2009 8:29 AM
-
| | Kira Qian Wednesday, June 03, 2009 3:50 AM | Kira Qian,
I try this before, ScrollViewer control is not allow to have winforms controls as a child control inside the scrollviewer.
I think WPF work slow is becasue of Windows Server 2008 | | matrixgoh Wednesday, June 03, 2009 4:13 AM | Hi matrixgoh,
I don't mean add winform control into scrollviewer, design the whole scrollviewer and its contained controls in WPF, then host the whole WPF control into Winform. So your main application is winform. It should run fast. Do you understand it?
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. | | Kira Qian Wednesday, June 03, 2009 4:41 AM | Kira Qian,
But I need to use RichTextBox in WinForms where allow user to have attachment where I think this cannot be done with WPF RichTextBox.
Any suggestion that using ScrollViewer and contained WinForms controls?
If I do so will the scrollbar still work? | | matrixgoh Wednesday, June 03, 2009 7:33 AM | Hi matrixgoh,
No, it cannot support both.
Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byKira QianMSFT, ModeratorMonday, June 15, 2009 8:29 AM
-
| | Kira Qian Wednesday, June 03, 2009 7:36 AM |
|