I am working on a project where I want to save the text that is in the textbox when im closing the application, and when I open the application again I want it to be there.
I am trying to save the text data in the app.config as you can see in the code below but when I close the application and run it, the text I put in is not there.
Im really confused because when the form loads it runs this
textbox1.Text = Properties.Settings.Default.SavedText;
and it should pull up the "saved text" which is being saved when the form is calling the Closing event
Properties.Settings.Default.SavedText = textbox1.Text;
Properties.Settings.Default.Save();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework;
using MetroFramework.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : MetroForm
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textbox1.Text = Properties.Settings.Default.SavedText;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.SavedText = textbox1.Text;
Properties.Settings.Default.Save();
}
}
}
I was also getting these errors before and I tried showing the potential fixes and use them but they didnt solve the issue with the text not saving.
This were the potential fixes.
I solved the issue by going into my project properties and adding this to the project settings. SavedText > String > User.
Related
I am trying to make a program that once a "fake" progress bar expires, the background image of the form changes to another one. This is my first time using forms as a GUI, so I would really appreciate the help. If possible, please explain how the code works. I'm using Visual Studio 2017. Here's how the code looks like.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Form_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.progressBar1.Increment(1);
}
}
}
in this event you have to check if the progressbar value is 100
it'll be like :
private void timer1_Tick(object sender, EventArgs e)
{
if(progressBar1.Value<100) // set progressBar max value to 100
{
// if the value smaller than 100, will increment.
this.progressBar1.Increment(1);
}
else{
timer1.Stop(); // Important to stop the timer
// here you change the background image of the form.
this.BackgroundImage = // choose ur image location.
}
}
I am working on a very basic project where I can copy something to the clipboard and it saves it in a RichTextBox in my application. I've made it loop through and check the clipboard every 0.5 seconds with a timer but how do I make the first copy stay in the TextBox because what it does now is:
-I copy something to the clipboard
-It sends it to the TextBox
-When I copy something else it overwrites it
How do I make them add one after the other?
This is what I got so far;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CBR
{
public partial class mainFrm : Form
{
public mainFrm()
{
InitializeComponent();
}
private void mainFrm_Load(object sender, EventArgs e)
{
}
private void clipboardUpdater_Tick(object sender, EventArgs e)
{
richTextBox1.Text = Clipboard.GetText();
}
}
}
Seems like this is what you're looking for;
private void clipboardUpdater_Tick(object sender, EventArgs e)
{
if (!richTextBox1.Text.Contains(Clipboard.GetText()))
{
richTextBox1.Text += Clipboard.GetText();
}
}
If you want to seperate each paste, replace the statement with this;
richTextBox1.Text += " " + Clipboard.GetText();
I am developing a C# application using Visual Studio 2015
it has 2 forms, on form1 I have a button that when clicked
shows form2, now what I would like to do is print form2
after it has fully loaded, I am using the printform control
on form2 to do this, if I use this on the the form_load event
it prints a blank page and then shows the form, I have
also tried using it on form_Shown, however this prints a box
where the elements are but not the element itself as if they have
not finished loading, there is probably a better way to do this
but I am new to C# so still learning
Below is an example of the code that I have on form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyApp
{
public partial class Form2: Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.Shown += new System.EventHandler(this.Form2_Shown);
}
private void Form2_Shown(object sender, EventArgs e)
{
printForm.Print();
}
}
}
The Shown event fires a wee bit too early. The form's frame and background is painted but the rest follows later. Painting is a low priority task that occurs only when nothing else needs to be done, firing the Shown event happens first.
The workaround is simple, just ask the form to finish updating itself by calling its Update() method. Fix:
private void Form2_Shown(object sender, EventArgs e)
{
this.Update();
printForm.Print();
}
I have a weird error, when I try to open a filedialog it goes back to visual studio and that's it, it just closes the form.
Here is my entire code, its just a test form with 1 button on it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Week7_Oprd1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OpenFileDialog ofd = new OpenFileDialog();
private void button1_Click(object sender, EventArgs e)
{
ofd.ShowDialog();
}
}
}
So after messing around with it for endless time I asked one of my teachers to help me.
The problem was that the debug was set to run with any cpu.
after setting it to x64 it worked.
I'm using .NET visual C# 2008 and in my webbrowser, I added click event handler to capture what html tag name I've clicked.
But then I lost control to the webbrowser.
When I start the application, in the webbrowser, I cannot enter texts into text field in the browser. It still accepts mouse clicks to the links though.
I've found few people having this issue in forums but no solution is found.
What am I doing wrong?
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace IERecorder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private mshtml.HTMLDocument doc = null;
private void Form1_Load_1(object sender, EventArgs e)
{
txtRecord.Items.Add("start...");
txtRecord.Items.Add("start2...");
webBrowser1.Navigate("http://www.google.com");
}
private void webBrowser1_DocumentComplete(object sender, WebBrowserDocumentCompletedEventArgs e)
{
txtRecord.Items.Add(e.Url.ToString() + " loaded...");
if (doc == null)
{
doc = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
mshtml.HTMLDocumentEvents2_Event iEvent;
iEvent = (mshtml.HTMLDocumentEvents2_Event)doc;
iEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);
}
}
private bool ClickEventHandler(mshtml.IHTMLEventObj e)
{
txtRecord.Items.Add("clicked ==>" + e.srcElement.tagName);
txtRecord.Items.Add("clicked2 ==>" + e.srcElement.getAttribute("name", 0));
txtRecord.Items.Add("clicked3 ==>" + e.srcElement.innerHTML);
return true;
}
}
}
Its a framework related issue, It will not work on framework 3.5. Change the project framework to 4.5.2, It will work.
I don't see a text field in your code? Did you mean the google search box?
This is a screenshot of what I was able to reproduce with the code that you supplied. I was able to search for stackoverflow and browse to it. I would doublecheck that your event handlers are still wired up correctly.