wpf scale to textBox, textBox can not display cursor when i click textBox
Asked Answered
G

2

1

First, I Zoom(ScaleTransform) the TextBox, then mouse to click on the TextBox. Sometimes can display the cursor, and sometimes can notdisplay the cursor. Looking for a solution to solution to the problem. I hope that I can show the cursor after I scale the TextBox.

 <Grid>
    <StackPanel>
        <TextBox Width="200"></TextBox>
        <TextBox Width="100"></TextBox>
        <TextBox Width="300"></TextBox>
        <TextBox Width="100"></TextBox>
        <TextBox Width="100"></TextBox>
        <TextBox Width="100"></TextBox>
    </StackPanel>
    <Grid.LayoutTransform>
        <ScaleTransform ScaleX="0.3" ScaleY="0.65"></ScaleTransform>
    </Grid.LayoutTransform>
</Grid>
Grecism answered 29/12, 2010 at 3:53 Comment(2)
You have yet to accept a single answer to any of your previous 11 questions.Wrath
You already asked this question: #4551851Hydroponics
H
1

A TextBox, especially a TextBox, is going to look bad and behave badly when scaled down. If you want your TextBox to look good and behave well, then use FontSize to reduce it and your font rendering and your cursor management will work better.

Hydroponics answered 29/12, 2010 at 7:13 Comment(0)
D
0

From an msdn answer I found:

The best workaround I work out is to apply an inverse transform on the TextBox and change the FontSize against the transform scale. You can wrap the TextBox with a Grid to maintain it's layout.

You can use the following code to see the effect. The FontSize in this sample is hardcoded to 10. You can use DataBinding to bind it to the scaletransform and use a converter to calculate a font size.

<Grid Background="AliceBlue">
<StackPanel>
<Border Height="100">
  <Canvas>
    <TextBox Canvas.Left="50" Canvas.Top="40" Width="500" Height="100" Background="Silver" Text="A Quick Red Fox Jumped Over A Lazy Brown Dog." FontSize="20"/>
    <Canvas.RenderTransform>
      <ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
    </Canvas.RenderTransform>
  </Canvas>
</Border>
<Border Height="100">
  <Canvas>
    <Grid Canvas.Left="50" Canvas.Top="40" Width="500" Height="100">
      <TextBox Background="Silver" Text="A Quick Red Fox Jumped Over A Lazy Brown Dog." FontSize="10" LayoutTransform="{Binding ElementName=scale, Path=Inverse}"/>
    </Grid>
    <Canvas.RenderTransform>
      <ScaleTransform x:Name="scale" ScaleX="0.5" ScaleY="0.5"/>
    </Canvas.RenderTransform>
  </Canvas>
</Border>

You can see the full thread here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/aeaa3e28-a7da-4208-9676-771231c1a954?prof=required

Discourteous answered 14/4, 2011 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.