.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
does GetRectFromCharacterIndex work?????
does GetRectFromCharacterIndex work?????
- this does not seems to work
TextBox2.Text = TextBox1.GetRectFromCharacterIndex(TextBox1.Text.Length).Width & "/" & TextBox1.GetRectFromCharacterIndex(TextBox1.Text.Length).Height & "=" & TextBox1.Text.Length
it does not matters how much text i write in thext box but the .wdith and heigh of the rect is fixed while the TextBox1.Text.Length gives the right results
why is that
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="471" Width="858">
<Grid>
<Button Height="23" HorizontalAlignment="Right" Margin="0,124,186,0" Name="Button1" VerticalAlignment="Top" Width="75">Button</Button>
<TextBox Margin="35,37,357,91" Name="TextBox1" AcceptsReturn="True" AcceptsTab="True"
TextChanged="TextBox1_TextChanged" ></TextBox>
<TextBox Height="65" HorizontalAlignment="Right" Margin="0,30,40,0" Name="TextBox2" VerticalAlignment="Top" Width="201" />
</Grid>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
TextBox2.Text = TextBox1.GetRectFromCharacterIndex(TextBox1.Text.Length).Width & "/" & TextBox1.GetRectFromCharacterIndex(TextBox1.Text.Length).Height & "=" & TextBox1.Text.Length
Beep()
End Sub
Answers
- Hi Mark,
The MSDN document says:
Because this method returns a rectangle that represents an edge of the character, the width of the rectangle is 0.
It's by design that the GetRectFromCharacterIndex method should return a rectangle of 0 width.
What are you trying to do? If you mean the same thing in this thread(http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/2b8e8f9b-b8a6-4a2e-8c9e-4987f2e6ab44 ), please check my sample in it.
If you have any questions or concerns, please feel free to let me know.
Best Regards,
Zhi-Xin
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!- Marked As Answer byZhi-Xin YeMSFT, ModeratorWednesday, November 11, 2009 10:07 AM
All Replies
- Hi Mark,
The MSDN document says:
Because this method returns a rectangle that represents an edge of the character, the width of the rectangle is 0.
It's by design that the GetRectFromCharacterIndex method should return a rectangle of 0 width.
What are you trying to do? If you mean the same thing in this thread(http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/2b8e8f9b-b8a6-4a2e-8c9e-4987f2e6ab44 ), please check my sample in it.
If you have any questions or concerns, please feel free to let me know.
Best Regards,
Zhi-Xin
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!- Marked As Answer byZhi-Xin YeMSFT, ModeratorWednesday, November 11, 2009 10:07 AM


