You're getting caught out by the automatic code in the Form1.designer.cs file. To solve this you need to change every occurance of button1_Click to button1_Click_1. The best way to do this is to right click on button1_Click and select "Refactor > Rename"
-
-
Alternatively, you can look for the line button1.Click += new EventHandler(button1_click) and change it to reflect the new name of your handler method. It should be in the InitializeComponent method that the designer creates.
Or instead of double-clicking, select the button and choose the lightning bolt in the properties window and type your own name for the click handler.
-
@evildictaitor:Thanks for the advice.
-
@spivonious:Thank you. It works!
-
I have another problem, if you could help me.
I wrote a test questions and I used a timer.But a have a problem with it.
Even if I finish the test before the time is up, the timer continues to go on.And it happens to show me the message "Time is up" while I'm resolving another quiz.
(I mention that even if it appears MessageBox.Show("Time is up") it doesn't affect the timer in the other quiz.That timer continues to go on)
I made a collection for the questions.And at the end of the questions I have something like
if (number_of_the_question > questions.Count)
{
MessageBox.Show("points: " + points);
}Is it a possibility to make a corelation between message box and the stopping of the timer ?
Or, is there any way to make timer to stop if I finish the test before the time is up?
Thank you.
-
@valentina28: Is it the Timer component from the toolbox? Set .Enabled = false when the user finishes the test.
You really should separate the test logic from the UI code. Read up on basic object-oriented design.
-
@spivonious:Yes, the Timer component is from the toolbox.Thank you so much! Now it works.
-
Hi everyone!
I have a problem with my c# program.
I have a test with 10 questions.And also , I have 10 images added into an ImageList.My questions are randomly selected to be displayed for each quiz I resolve. I would like to have each question with its picture. How could I make a correlation between current_question and its picture from ImageList?
Thank you so much!
-
@valentina28: Use the same key when adding the image and test question to their respective collections. Or, better yet, make your own class called "TestQuestion" and give it "Question" and "Image" properties. Then you don't have to worry about keeping them synched.
-
@spivonious:I know that they can seem stupid questions. Please understand me that I am a beginner to C#.
1.I have a collection for questions
Collection<question> questions = new Collection<question>();
and also apublic class questions() {......}
The ImageList is from the Toolbox. The pictures from the ImageList appear in a PictureBox when I press the button Next_question.I don't have any collection for ImageList.
Should I create a collection for ImageList? What should I have in this collection?
2.For
public class TestQuestion
{}
How could I give to this class "Image" and "Question" properties ?
I am sorry again if my questions are stupid.Thanks for understanding!
-
@valentina28: There's no such thing as a stupid question, but I would suggest getting a book on beginning C# rather than relying on forums.
public class TestQuestion { public System.Drawing.Image TestImage { get; set; } public string TestQuestion { get; set; } }You'd then set it up like this:
TestQuestion myQuestion = new TestQuestion(); myQuestion.TestQuestion = "What is your name?"; myQuestion.TestImage = new System.Drawing.Bitmap("C:\name.bmp"); -
@spivonious:Thank you for your help! Can you recommend me any books?
-
4 days ago, spivonious wrote
myQuestion.TestImage =newSystem.Drawing.Bitmap("C:\name.bmp")Might want to be a bit careful there - either use an unescaped string literal (@"C:\name.bmp"), properly escape the slash ("C:\\name.bmp") or use forward slashes ("C:/name.bmp") - otherwise you're actually saying C <colon> <new-line> ame.bmp, (which will always throw an exception because \n is an illegal filename character).
-
@evildictaitor:Thank you! I will remember this. Unfortunately, at this time I don't know how to make a correlation between this code and my questions ....I take them from a Notepad file. Also, my questions are randomly selected to be displayed for each quiz I resolve.
-
Hi! I have a problem with my c# program. I will be very grateful if you could help me.
I have a test with 10 questions. When I resolve the test for the first time my questions.Count=10; When I resolve the test for the second time my questions.Count=20;
That's bad, because when I resolve the test for the second or third time my quiz repeats questions (I think each time I resolve a quiz, the program reads the data from my file all over again and add it to my collection. )
I have
Collection<question> = questions new Collection<question> ();
declared at the beginning of thepublic partial class Form3 : Form
.Thank you so much! -
@valentina28: It's hard to know without seeing more of your code, but you probably need to reset the collection before loading in new questions.
questions.Clear()
-
What's probably happening is that you define your collection somewhere
Collection<Question> questions = new List<Question>();
and later add the questions to it:
questions.Add(new Question("1"));
questions.Add(new Question("2"));
questions.Add(new Question("3"));Either as spivonious says, do a
questions.Clear();
questions.Add(new Question("1"));
questions.Add(new Question("2"));
questions.Add(new Question("3"));before the first questions.Add(), or move your questions' constructor next to where you initialize it:
questions = new List<Question>();
questions.Add(new Question("1"));
questions.Add(new Question("2"));
questions.Add(new Question("3")); -
@spivonious, @evildictaitor thank you so much!
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.