Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hai all,
I have a very simple question.I want my RichTextBox to be in the size of my mainwindow.Please have a look at my code:
VB
Class MainWindow


    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        RichTextBox1.Width = Me.Width : RichTextBox1.Height = Me.Height
    End Sub
End Class

Her all works fine when the window loads,but when I maximize it the size of the textbox do not change.It's size remains same that is the the size of the window when it was loaded.In Winforms,I used to fix this by assigning its Anchor to Top,Bottom,Left,Right.But in WPF I don't find such a property.Anyone kindly please solve my problem!
Thanks in advance!
Posted

Handle the SizeChanged event with the same code?

VB
Private Sub Window_SizeChanged(sender As Object, e As SizeChangedEventArgs)

End Sub
 
Share this answer
 
Comments
Ashfaq Bin Rahman 16-Mar-13 4:58am    
No,again the problem occurs?!
My new code is:
Private Sub MainWindow_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Me.SizeChanged
If WindowState.Maximized Then
txt.Width = Me.Width - 15 : txt.Height = Me.Height
End If

End Sub
Thanks Mike!I got it done!
In window size changed event,I made it like this:
VB
Private Sub MainWindow_SizeChanged(ByVal sender As Object, ByVal e As System.Windows.SizeChangedEventArgs) Handles Me.SizeChanged
       If WindowState = WindowState.Maximized Then
           txt.Width = Windows.WindowState.Maximized
           txt.Height = Me.ActualHeight : txt.Width = Me.ActualWidth
       End If

   End Sub

It's working fine!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900