locked
How to get only a char of keyboard in Windows Phone

    Question

  • Hi, I new with dev on Windows Phone. So, I need help.

    First in my college I use Java and the professor gave a task, build a hangman. I do, and now I would like of make in Windows Phone. Only understand, I'll not publish in Store.

    Than I started, but I'm having a little diffcult with make connections betewen C# and XAML.

    So, first question:

    It's possible I get only char in keyboard and next he close by self?

    Second:

    I would like change color of Retangle, but in C#. I found a method Fill, but I don't understand how can I use.

    In moment that's it.

    Sorry if my English it's not enough, still. I study a lot to improve more.

    Thank's


    Friday, April 17, 2015 8:21 PM

Answers

  • Hi,I get only char in keyboard and next he close by self? Use textbox validation to accept user i/p as

    a character if press any other button then application close.(use --

    Application.Current.Terminate();)

    )

    private void textbox_KeyPress(Object sender, KeyPressEventArgs e) { if(!char.IsLetter(e.KeyChar)) { e.Handled = true; MessageBox.Show("Enter only letters");

    Application.Current.Terminate(); } }

    Second:

    I would like change color of Retangle, but in C#. I found a method Fill, but I don't understand how can use-- drag/create xaml control (rectangle) following way and  if user tap rectangle the change

    rectangle color.see  following code for these....

    <Rectangle x:name="myrect" HorizontalAlignment="Left" Height="48" Margin="50,94,90,90" Stroke="Black" VerticalAlignment="Top" Width="73" Tap="colorchange_Tapped"/>
    private void colorchange_Tapped( object sender , System.windows.Inpute.GestureEvents e )
    {
        myrect.Fill = new SolidColorBrush(Colors.Blue);
    }
    Don't forget to mark the right answer and vote up if helps you.


    Sunday, April 19, 2015 11:55 AM
  • Hi, thank's. It was very helpful!

    In part of retangle is necessary a change:

    myRect.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(100, 255,0,0));

    And in keyboard, I guess I wasn't clear, but I found other method.  I wanted close/hide the keyboard.

    Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();

    But your aswer was helpful. Thanks again.

    Sunday, April 19, 2015 2:55 PM

All replies

  • Hi,I get only char in keyboard and next he close by self? Use textbox validation to accept user i/p as

    a character if press any other button then application close.(use --

    Application.Current.Terminate();)

    )

    private void textbox_KeyPress(Object sender, KeyPressEventArgs e) { if(!char.IsLetter(e.KeyChar)) { e.Handled = true; MessageBox.Show("Enter only letters");

    Application.Current.Terminate(); } }

    Second:

    I would like change color of Retangle, but in C#. I found a method Fill, but I don't understand how can use-- drag/create xaml control (rectangle) following way and  if user tap rectangle the change

    rectangle color.see  following code for these....

    <Rectangle x:name="myrect" HorizontalAlignment="Left" Height="48" Margin="50,94,90,90" Stroke="Black" VerticalAlignment="Top" Width="73" Tap="colorchange_Tapped"/>
    private void colorchange_Tapped( object sender , System.windows.Inpute.GestureEvents e )
    {
        myrect.Fill = new SolidColorBrush(Colors.Blue);
    }
    Don't forget to mark the right answer and vote up if helps you.


    Sunday, April 19, 2015 11:55 AM
  • Hi, thank's. It was very helpful!

    In part of retangle is necessary a change:

    myRect.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb(100, 255,0,0));

    And in keyboard, I guess I wasn't clear, but I found other method.  I wanted close/hide the keyboard.

    Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();

    But your aswer was helpful. Thanks again.

    Sunday, April 19, 2015 2:55 PM