mercredi 26 mars 2014

Create 1D Arrary with n text boxes in Windows Phone 8


Vote count:

0




I wanna create an 1D array with n text boxes in Windows Phone 8 ( I had succeeded in Windows Form ) 1)In MainPage.xaml :



<TextBox x:Name="tbx_a" HorizontalAlignment="Left" Height="40" Margin="29,265,0,0" TextWrapping="Wrap" Text="a:" VerticalAlignment="Top" Width="40" FontFamily="Arial"/>
<Button x:Name="btn_Random" Content="Random" HorizontalAlignment="Left" Margin="147,385,0,0" VerticalAlignment="Top" Height="65" FontFamily="Microsoft YaHei" FontSize="20" Click="btn_Random_Click"/>
<Button x:Name="btn_Array" Content="Create" HorizontalAlignment="Left" Margin="284,385,0,0" VerticalAlignment="Top" Height="65" Width="130" FontFamily="Microsoft YaHei" FontSize="20" Click="btn_Array_Click"/>


2) In MainPage.xaml.cs :



public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
TextBox[] Node;

int[] a;

int n ; // Number of boxes User wanna see in screen

**Label[] label_box; //Label of box: 15,23, 82, etc...:First problem here : DON'T HAVE LABEL NAMESPACE**

public void create_array ()
{

label_box = new Label[n]; // From problem above
a = new int[n];
Node = new TextBox[n];

tbx_a.Width = 20;
tbx_a.Height = 20;
tbx_a.FontSize = 18 ;

for (int i=0; i< n ; i++)
{
//NODE
a[i] = i;
Node[i] = new TextBox();

Node[i].Text = a[i].ToString();

Node[i].Width = 20;
Node[i].Height = 20;
Node[i].Foreground = new SolidColorBrush(Colors.White);
Node[i].Background = new SolidColorBrush(Colors.Red);

***this.Controls.Add (Node[i]); // Second problem : DON'T HAVE CONTROLS NAMESPACE***

label_box[i] = new Label();
label_box[i].Text = a[i].ToString();

label_box[i].Width = 20;
label_box[i].Height = 20;

***this.Controls.Add(label_box[i]); // Second problem above***
}
}

private void btn_Random_Click(object sender, RoutedEventArgs e)
{
Random r = new Random();
for (int i = 0; i < n; i++)
{
a[i] = r.Next(100);
Node[i].Text = a[i].ToString();
}
}

private void btn_Array_Click(object sender, RoutedEventArgs e)
{
create_array();
}
}


3) I wanna see result in my phone screen after I input n = 8 and choose random button :



[23][01][57][92][71][08][38][49]


PLEASE HELP ME :(



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire