locked
Changing Font programmatically RRS feed

  • Question

  • Simple problem... I think.

    I'm trying to change the Font size of a Textbox.  Here is the code that Yann kindly gave to me...

    Dim controlProxy = Me.FindControl("Control Name")

                AddHandler controlProxy.ControlAvailable, _

                    Sub(sender As Object, e As ControlAvailableEventArgs)

                       Dim control = CType(e.Control, TextBlock)

                       With control

                          

                           .Foreground = New SolidColorBrush(Color.FromArgb(200, 0, 126, 230))

                           .FontSize = Convert.ToDouble(14.0)

                           .FontFamily = New FontFamily("Tahoma")

                       End With

                   End Sub

    It compiles fine but I get a run time error...  Unable to cast object of type 'System.Windows.Controls.TextBox' to type 'System.Windows.Controls.TextBlock'.

     

    Monday, April 29, 2013 10:34 AM

Answers

  • Hi,

      Dim control = CType(e.Control, TextBlock) ???

    Maby it should not be a TextBlock.

    Just guessing.

    Sven


    Sven Elm

    • Marked as answer by Jyuma1 Monday, April 29, 2013 2:23 PM
    Monday, April 29, 2013 11:51 AM

All replies

  • Hi,

      Dim control = CType(e.Control, TextBlock) ???

    Maby it should not be a TextBlock.

    Just guessing.

    Sven


    Sven Elm

    • Marked as answer by Jyuma1 Monday, April 29, 2013 2:23 PM
    Monday, April 29, 2013 11:51 AM
  • Good guess.  :)  s/b Textbox.  

    Working fine now.

    Thanks

    Monday, April 29, 2013 2:23 PM
  • Nice...

    Bye

    Sven


    Sven Elm

    Monday, April 29, 2013 2:30 PM