I'm looking for an "aha!" moment troubleshooting why the following works in one project, but in building a newer, more efficient version the same structure does not update the text in textBox1 with the result of openFileDialog1.
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
textBox1.Text = openFileDialog1.FileName;
}
I copied and pasted my code from Project 1 to Project 2, so I'm just not sure where the breakdown could be. The rest of the project does execute properly, so openFileDialog1 is completing successfully and allowing me to click button2 to encode a valid RSS xml file from the input given in openFileDialog1. The only thing not working is textBox1.Text displaying the FileName chosen in openFileDialog1. Any ideas as to where the breakdown is are appreciated!
Related
I have the following button1 Click method:
private void button1_Click(object sender, RoutedEventArgs e)
{
string createstringvalue = MyCustomMethod();
}
When the user clicks the button1 it generates a custom string.
I want to use this custom string as an argument in a custom method used by the button2 Click method.
private void button2_Click(object sender, RoutedEventArgs e)
{
bool commandExecuted = CustomMethod2(createstringvalue);
if (commandExecuted)
{
MessageBox.Show("Selected file was loaded successfully");
}
}
Currently I get an ERROR:
The name createstringvalue does not exist in the current context
I apologize if my question is quite simple. I try to learn C# , so I try different concepts.
Please mark the question as duplicate, and I will close it, if it is already answered and post in the comments the duplicate SO question.
You can make a variable outside your click event as Loocid mentioned, or you can directly read the value in button2:
private void button2_Click(object sender, RoutedEventArgs e)
{
bool commandExecuted = CustomMethod2(MyCustomMethod());
if (commandExecuted) //or: if (CustomMethod2(MyCustomMethod()))
{
MessageBox.Show("Selected file was loaded successfully");
}
}
At the top of the class string createstringvalue; Define the variable as
later
private void button1_Click(object sender, RoutedEventArgs e)
{
createstringvalue = MyCustomMethod();
}
I want to make a windows form using C# to check if a file exist.
I've tried this one:
private void test_Click(object sender, EventArgs e)
{
var app1 = (#"C:\Users\frangon\Desktop\Spectrum-Check.EXE");
test.Text = File.Exists(app1).ToString();
}
If possible, I don't want to click it. I just want it to show as "True" if the file exist, or "False" if the file doesn't exist.
You can add an event to trigger when the form loads:
And then in your code behind:
private void Form1_Load(object sender, EventArgs e)
{
string app1 = #"C:\Users\frangon\Desktop\Spectrum-Check.EXE";
test.Text = File.Exists(app1).ToString();
}
private void droplesson_SelectedIndexChanged(object sender, EventArgs e)
{
if(e.Equals("LESSON1"));
reload("LESSON1.txt");
if(e.Equals("LESSSON2"));
reload("LESSON2.txt");
if(e.Equals("LESSON3"));
reload("LESSON3.txt");
if(e.Equals("LESSON4"));
reload("LESSON4.txt");
if (e.Equals("LESSON5"));
reload("LESSON5.txt");
}
Above code is not working. I want to change the dropdown menu such that when i select the particular lesson it reload that lesson.enter image description here
You added ';' at the end of every line, including the 'if' lines, soo all of the 'reload' calls got executed...
This is how your code should look:
private void droplesson_SelectedIndexChanged(object sender, EventArgs e)
{
if(e.Equals("LESSON1"))
reload("LESSON1.txt");
if(e.Equals("LESSSON2"))
reload("LESSON2.txt");
if(e.Equals("LESSON3"))
reload("LESSON3.txt");
if(e.Equals("LESSON4"))
reload("LESSON4.txt");
if (e.Equals("LESSON5"))
reload("LESSON5.txt");
}
I'm using Visual Studio, so I already have drag-and-dropped some pictureBoxes in there, and they have names and pictures. I just want to be able to click them and have a label say the name of the person in the picture that was clicked.
This is what I currently have (for the pictureBox only)
private void captainFalcon_Click(object sender, EventArgs e)
{
Label.Show("Captain Falcon");
}
FINAL EDIT: Everything is working now, I just followed everyone's suggestions!
Is this what you need?
private void captainFalcon_Click(object sender, EventArgs e)
{
Label.Text = "Captain Falcon";
}
Something like below will work.
private void pictureBox1_Click(object sender, EventArgs e)
{
label1.Text = "Captain Falcon";
}
Obviously change the control names (pictureBox1 and label1) to match yours.
Use
private void captainFalcon_Click(object sender, EventArgs e)
{
xxxxxx.Text ="Captain Falcon";
}
and instead of xxxxx use your label name.
Select your label on designer, look at its properties, and use its "(Name)" property.
For example if your label name is characterName, then your code will be
characterName.Text ="Captain Falcon";
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
}
}