Dont know what the problem is wether Value is not being stored or not being retrieved from isolated settings
Page1.Xaml
Here I am storing data
public void Stop_Click(object sender, RoutedEventArgs e)
{
PhoneApplicationService.Current.State["high"] = count;
}
Here I want to retrive it!
Page2.Xaml
private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
{
TP.Text = (string)PhoneApplicationService.Current.State["high"];
}
Store your data like this :
public void Stop_Click(object sender, RoutedEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
if (!settings.Contains("high"))
{
settings.Add("high", count);
}
else
{
settings["high"] = count;
}
settings.Save();
}
And then retrieve stored settings data like this :
private void PhoneApplicationPage_Loaded_1(object sender, RoutedEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("high"))
{
TP.Text = settings["high"].ToString();
}
}
Hope this helps.
This type of saving data is only for "multitasking" purposes such as when user leaves your app but does not close it by back button. Also system can kill the app if it is in background and user opened another apps (I think the limit is 8 apps in background).
Your approach should work fine when app is not closed and then resumed by multitasking menu for example.
If you want to store data for long-term then use IsolatedStorageSettings as "Mak" answered.
You can find more info on MSDN - http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff817008%28v=vs.105%29.aspx
Related
I need that all data which I can see now in Find_ list View are online added to C:\Users\Public\WattLOG.txt file
Then I Will Access to this file with another program and read all events.
When there comes new line, I need to store it immediately in file.
private void Find_listView_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Search_listView_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
I am creating a program using WinForms so users can input info into textboxes on one form which then are saved into a Listbox on another form. I would like to be able to edit the items saved in the listbox by opening the original form on a button click. Really struggling with it as I can't think of the code and I can't seem to find a solution.
My Code:
private void btnAdd_Click(object sender, EventArgs e)
{
RoomDisplayForm newRoomDisplayForm = new RoomDisplayForm();
newRoomDisplayForm.ShowDialog();
if(newRoomDisplayForm.DialogResult == DialogResult.OK)
{
listBoxRooms.Items.Add(newRoomDisplayForm.value);
}
newRoomDisplayForm.Close();
}
private void btnRemove_Click(object sender, EventArgs e)
{
this.listBoxRooms.Items.RemoveAt(this.listBoxRooms.SelectedIndex);
}
private void btnEdit_Click(object sender, EventArgs e)
{
}
So i've got a Add and Remove button which work perfectly just need a solution to the edit button.
Thanks in advance
I'm guessing newRoomDisplayForm.value is a property or a public member inside the form. You just need to do something like this:
private void btnEdit_Click(object sender, EventArgs e)
{
if(listBoxRooms.SelectedIndex < 0) return;
var tmpValue = listBoxRooms.Items[listBoxRooms.SelectedIndex].ToString();
RoomDisplayForm newRoomDisplayForm = new RoomDisplayForm();
newRoomDisplayForm.value = tmpValue;
newRoomDisplayForm.ShowDialog();
//TODO: inside "newRoomDisplayForm" set the value to the textbox
// ie.: myValueTextBox.Text = this.value;
if(newRoomDisplayForm.DialogResult == DialogResult.OK)
{
// replace the selected item with the new value
listBoxRooms.Items[listBoxRooms.SelectedIndex] = newRoomDisplayForm.value;
}
}
Hope it helps!
You can simply remove the listitem in that specific position, create a new item and add it again. it's kind of replacement.
I Create login form and want to put "remember me" check box on it.
But every time i open program it doesn't change.
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
Project.Properties.Settings.Default.rememberMe = true;
Project.Properties.Settings.Default.Save();
}
else
{
Project.Properties.Settings.Default.rememberMe = false;
Project.Properties.Settings.Default.Save();
}
}
Also i want to save user login information, should i save them in app setting just like remember me setting or there is better way?
You're saving the settings, but you need to retrieve those settings too.
Subscribe to the Form's load event and set the value of the CheckBox.
private void Form1_Load(object sender, EventArgs e)
{
checkBox1.Checked = Project.Properties.Settings.Default.rememberMe;
}
Also, and this is just common practice, but your code could be shorter:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Project.Properties.Settings.Default.rememberMe = checkBox1.Checked;
Project.Properties.Settings.Default.Save();
}
I navigated to a page where I want to be able to see the date i got from the Database and to edit that date if it is needed. When I change the date, it always go back to the date that was set by the database previously. How do I solve this. Below are my code:
private void dateData_Loaded(object sender, RoutedEventArgs e)
{
dateData.Value = DateTime.Parse(NavigationContext.QueryString["Date"]);
}
private void dateData_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
{
dateData.Value = (DateTime)dateData.Value;
}
I Think the loaded event is getting called every time you are changing the date and you are assigning the date you are getting from your querystring parameters. So try something like this And check if it works
private void dateData_Loaded(object sender, RoutedEventArgs e)
{
if(NavigationContext.QueryString.ContainsKey("Date"))
{
dateData.Value = DateTime.Parse(NavigationContext.QueryString["Date"]);
NavigationContext.QueryString.Remove("Date");
}
}
I cannot figure this out
i'm making a windows form application with visual basic in c#
i have a scan button and it scans everything in the folder and lists all of the files in the listbox
if you click it another time the list of files appear again
how can you make it so you can only press the scan button once, and then you can press it again if you click the browse button?
the browse button is to select the folder you want to scan
thanks
This is pretty trivial
private void ScanButtonClick(object sender, EventArgs e)
{
// do something
(sender as Button).Enabled = false;
}
private void BrowseButtonClick(object sender, EventArgs e)
{
ScanButton.Enabled = true;
}
Its a bit unclear if you're writing in C# or vb.net, but since the question is tagged as C#...
private void btnScan_Click(object sender, EventArgs e) {
btnScan.Enabled = false;
// other code here
}
private void btnBrowse_Click(object sender, EventArgs e) {
btnScan.Enabled = true;
//other code here
}
I tried this in my windows form application in C# and it works fine!
private void button3_Click_1(object sender, EventArgs e)
{
int count = 0;
count++;
//add your code here
if (count == 1) {
button3.Enabled = false;
//only one click allowed
}
}