乱数ジェネレーター アプリを作成しました。ユーザーは、min、max、および amount から gen に整数を入力できます。3 つのボタンがあります。出力を生成し、クリアし、保存します。保存以外はすべて動作します。
私はこれに約6時間取り組んでいますが(冗談ではありません)、まだ理解できません。このスレッドを見つけましたが、実装方法がわかりません: How to store a integer value in isolated storage in wp7?
コードは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Random_Number_Generator_by_Bailey.Resources;
using System.Windows.Input;
using System.IO.IsolatedStorage;
namespace Random_Number_Generator_by_Bailey
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
if (IsolatedStorageSettings.ApplicationSettings.Contains("minstorage"))
{
min1 = (int)IsolatedStorageSettings.ApplicationSettings["minstorage"];
string min1text = min1.ToString();
MinNumInput.Text = min1text;
}
// Retrieve settings
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private int randomNumber(int min, int max)
{
Random random = new Random(Guid.NewGuid().GetHashCode());
return random.Next(min, max);
}
public void Randomize_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
int tester2;
if (!Int32.TryParse(MinNumInput.Text, out tester2))
{
OutputBox.Text = "You did not specify an integer for \"Minimum Number\" ";
return;
}
int tester3;
if (!Int32.TryParse(MaxNumInput.Text, out tester3))
{
OutputBox.Text = "You did not specify an integer for \"Maximum\" ";
return;
}
int tester;
if (!Int32.TryParse(AmountToGenInput.Text, out tester))
{
OutputBox.Text = "You did not specify an integer for \"Amount to generate\" ";
return;
}
int gen;
gen = Convert.ToInt32(AmountToGenInput.Text);
gen = int.Parse(AmountToGenInput.Text);
int min1;
min1 = Convert.ToInt32(MinNumInput.Text);
min1 = int.Parse(MinNumInput.Text);
int max1;
max1 = Convert.ToInt32(MaxNumInput.Text);
max1 = int.Parse(MaxNumInput.Text);
if (gen <= 100 && gen > 0)
{
for (int i = 0; i < gen; i++)
{
int random = randomNumber(min1, max1);
OutputBox.Text += " " + random;
}
}
else
{
if (gen > 100) { OutputBox.Text = "You cannot generate more than 100 numbers."; }
if (gen < 0) { OutputBox.Text = "You cannot generate less than 0 numbers."; }
}
}
private void ClearTextBox_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
OutputBox.Text = "";
}
private void SaveParameters(object sender, System.Windows.Input.GestureEventArgs e)
{
int gen;
gen = Convert.ToInt32(AmountToGenInput.Text);
gen = int.Parse(AmountToGenInput.Text);
int min1;
min1 = Convert.ToInt32(MinNumInput.Text);
min1 = int.Parse(MinNumInput.Text);
int max1;
max1 = Convert.ToInt32(MaxNumInput.Text);
max1 = int.Parse(MaxNumInput.Text);
//If the variables need to be strings:
//string gen = AmountToGenInput.Text;
//string min1 = MinNumInput.Text;
//string max1 = MaxNumInput.Text;
// Store the value
IsolatedStorageSettings.ApplicationSettings["minstorage"] = min1;
}
// Sample code for building a localized ApplicationBar
//private void BuildLocalizedApplicationBar()
//{
// // Set the page's ApplicationBar to a new instance of ApplicationBar.
// ApplicationBar = new ApplicationBar();
// // Create a new button and set the text value to the localized string from AppResources.
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);
// // Create a new menu item with the localized string from AppResources.
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}
誰かが私を助けてくれれば、それは素晴らしいことです。ありがとうございました。