locked
Setting a Foucs on Text Box Control based on MessageBox Result "Yes" RRS feed

  • Question

  • Hi,

    I have 3 Text Box Control and one Button Control. After Clicking on the Button it prompts MessageBox with Yes/No after clikcing "Yes" I want to set the focus on the 2nd text box.

    Regards,
    Suresh

    Tuesday, September 18, 2012 8:52 AM

Answers

  • I have 3 Text Box Control and one Button Control. After Clicking on the Button it prompts MessageBox with Yes/No after clikcing "Yes" I want to set the focus on the 2nd text box.

    Which message box are you using ?

    if it is default html browser message box then it will return bool property, catch the bool and check if it is true try to focus the second textbox

    textbox2.focus();

    if you are using custom message might be inherited from childwindow, then close click event you can set the focus to next textbox.

    Wednesday, September 19, 2012 12:25 AM
  • <UserControl x:Class="SilverlightApplication42.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <TextBox Height="23" HorizontalAlignment="Left" Margin="39,165,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="126,61,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="225,165,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="149,208,0,0" Name="textBox3" VerticalAlignment="Top" Width="120" />
        </Grid>
    </UserControl>


    Code  Behind:

    namespace SilverlightApplication42
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                MessageBoxResult result =
                MessageBox.Show("Would you like  to focus TextBox 2 ?","MessageBox Example", MessageBoxButton.OKCancel);
                if (result == MessageBoxResult.OK)
                {
                    textBox2.Focus();
    
                }
            }
        }
    }
    


    Saturday, September 22, 2012 3:21 AM

All replies

  • textBox2.Focus();

    Tuesday, September 18, 2012 5:51 PM
  • I have 3 Text Box Control and one Button Control. After Clicking on the Button it prompts MessageBox with Yes/No after clikcing "Yes" I want to set the focus on the 2nd text box.

    Which message box are you using ?

    if it is default html browser message box then it will return bool property, catch the bool and check if it is true try to focus the second textbox

    textbox2.focus();

    if you are using custom message might be inherited from childwindow, then close click event you can set the focus to next textbox.

    Wednesday, September 19, 2012 12:25 AM
  • <UserControl x:Class="SilverlightApplication42.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <TextBox Height="23" HorizontalAlignment="Left" Margin="39,165,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
            <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="126,61,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="225,165,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" />
            <TextBox Height="23" HorizontalAlignment="Left" Margin="149,208,0,0" Name="textBox3" VerticalAlignment="Top" Width="120" />
        </Grid>
    </UserControl>


    Code  Behind:

    namespace SilverlightApplication42
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                MessageBoxResult result =
                MessageBox.Show("Would you like  to focus TextBox 2 ?","MessageBox Example", MessageBoxButton.OKCancel);
                if (result == MessageBoxResult.OK)
                {
                    textBox2.Focus();
    
                }
            }
        }
    }
    


    Saturday, September 22, 2012 3:21 AM