Hi folks,
My Splash screen did appear upon execution of my program, and then fade out, but now its not working and I can't figure it out, but I know its simple! :o Can someone help debug it please?
My time is set to 'Enabled' and Interval '1000' in properties...... :(
This is the code:
public partial class MainForm : Form
{
SplashScreen SplashForm = new SplashScreen();
int timerClock = 0;
What EXACTLY happens when you DEBUG it, the first step is putting a breakpoint at each method and then SINGLE STEPPING through the code.
funnyusername
December 26th, 2008, 05:37 PM
Thanks for the reply CPUWizard, go easy on me, I'm only learning! :(
There are no errors, the splashscreen appears, then about 1 second later the MainForm appears and the Splash screen is gone.
The splash screen is supposed to appear and fade out for a few seconds before the MainForm appears. I think I've just messed up the timing's related to the Timer.Tick event, but can't get it back and its melting my brain!!! :eek:
marceln
December 26th, 2008, 05:40 PM
In timer1_Tick strange things happen. I am surprised it ever worked.
What you do is close the splash when timerClock = 20 but fade it when timerClock >= 40.
It should be something like:
This way the splash will fade out for 20 seconds, with -.05 units each second. When it is nearly transparent it will be closed and the main form will be displayed.
TheCPUWizard
December 26th, 2008, 05:42 PM
And learning the debugger is something you aparently skipped. You should have practived the debugger as soon as you wrote:
using system;
class Test
{
static int Main(string [] args)
{
int x = 1;
x = x + 1;
Console.WriteLine(x);
}
}
You CAN NOT program if you do not learn how to use the tools. You would not attempt to build a house without learning how to use a hammer and a saw.....
..BACK to The Beginning for you.
funnyusername
December 26th, 2008, 05:45 PM
Ok, some changes....A timer interval of 1000 is one tenth of a second....
Change initial timerClock if statement to 0 to activate opacity reducing because it is equal to 1 when it appears at the start:
if (timerClock >= 0)
After 6 seconds I want the program to load the MainForm, so 6 seconds x 10 = 60 opacity changes, therefore the opacity reduction should be .1:
SplashForm.Opacity = SplashForm.Opacity - .1;
After each opacity reduction of .1 the timer will increment....++.....correct...
If the timerClock reaches 6 seconds I want the splashform to close and the mainform to appear...soooo:
if (timerClock == 60)
{
SplashForm.Close();
this.Opacity = 100;
timer1.Enabled = false;
}
.....hmmph! It still doesn't work..... :(
funnyusername
December 26th, 2008, 05:48 PM
I am learning......did you get out of the wrong side of the bed? (Just kidding.... :D)
Your changes to the timer didn't work either.... :(
marceln
December 26th, 2008, 05:48 PM
Wrong, a timer interval of 1000 is 1 second (as in 1000 milliseconds).
Your changes to the timer didn't work either....
They should. And I didn't change anything in the timer... What is the behavior now?
TheCPUWizard
December 26th, 2008, 05:54 PM
I am learning......did you get out of the wrong side of the bed? (Just kidding.... :D)
No, but I find it simply amazing that people (not just you) IGNORE# the FACT that the debugger is a very important requirement, EVEN FOR TRIVIAL programs.
It is plain foolishness (And I am being REAL nice) for ANYONE to not learn how to use it effectively at the very beginning.
When I give training courses, we start with 1-2 hours on the basic s of the language, then the rest of the first day (my sessions are usually 7-8 hours) on nothing but the debugger. On average students spend about 75% of their time in the one week course (35-40 hours total) in the debugger.
This is exactly how YOU should be spending your time....
1) Type in 5-10 lines of code)
2) Step through it [every line] with the debugger, look at all the variables, and see how they change
3) Repeat step #2 with a variety of input values
4) Now go back to step #1
So if your program has 50 lines of code, you should have (on average) run it through the debugger AT LEAST 5-15 times. This is assuming you made NO mistakes in logic or design. Typically this will break down to about 3 hours in the debugger for every hour typing in code and getting it to compile.
funnyusername
December 26th, 2008, 06:05 PM
Ok Ok..... :(
1000 = 1, of course, sorry.
Its still not working, and I even set the opacity of the form properties directly at 20%, but it still shows 100% opaque when the program starts....its a mystery..... :?
I apologise CPUWizard, but I'm learning from books....many books, and I've done everything they have gone through with the debugger, which I have to admit has only been a very basic overview of what Step Into, Step Over and breakpoints are. No Errors are showing up for this, so the debugger is not helping. I've walked through the code line by line myself numerous times. I promise I will try to get a book that goes into more detail on the debugger. :o
funnyusername
December 26th, 2008, 06:10 PM
Ok......something VERY weird is going on......
If I comment out the line SplashForm.Show(); it makes no difference!!!
Any ideas? Could it be in the settings somewhere to ignore my changes (Visual Studio 2008 Stnd Ed) ?
marceln
December 26th, 2008, 06:12 PM
Because it is visible by default. Take a look at the splash form's properties.
TheCPUWizard
December 26th, 2008, 06:15 PM
. No Errors are showing up for this, so the debugger is not helping. I've walked through the code line by line myself numerous times.. :o
Have you set a breakpoint at both of the methods MainForm_Load, timer1_Tick?
Have you stepped into " SplashForm.Opacity = SplashForm.Opacity - .4" when the SplashForm HAS already been closed? [ie anytine after a breakpoint on SplashForm.Close(); is called?
In the right context, this will compile and run. NO Errors.
But if the problem statement is: "What is the price of 5 items when each one costs $1.87?", stepping through it with the debugger will immediately revela two bugs.....
funnyusername
December 26th, 2008, 06:26 PM
I think we are very clear that I need more work with the debugger! :( :(
I went into my archives and located my 'SplashTrial' program from I can't remember when.... :)
Here is the code in that program WHICH WORKS FINE!!!
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 SplashDemo
{
public partial class Form1 : Form
{
Timer timer1 = new Timer();
frmSplash SplashScreen = new frmSplash();
int timerClock = 0;
Here is the code in my current program which I have changed again to match, and it DOES NOT WORK!!! :(
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 New_Program
{
public partial class MainForm : Form
{
SplashScreen SplashForm = new SplashScreen();
int timerClock = 0;
Since the code is almost identical to the one that works (with a non-significant difference) then you should have a look at how frmSplash is implemented and at it's properties in the designer. Also available for the main form. Probably you missed something.
funnyusername
December 26th, 2008, 06:36 PM
Already tried that. :(
They are both the EXACT same!!
I'm going to create a second form for the splashscreen in the same program and see if I can get it working. If I can, then I'll just ditch the one thats 'broken'! :(
JonnyPoet
December 26th, 2008, 06:43 PM
Are you sure that your delegate methods are connected to the events so they are all working ? So simple set a breakpoint into the Tick event delegates first line and look if the program stops there ? If not, the delegate isn't called so it isn't set (Look into the timers Events List in the propertiesForm ( You can also look into the forms designer.cs if the delegate is coupled to the Tick event :wave:
marceln
December 26th, 2008, 06:45 PM
Are you sure that your delegate methods are connected to the events so they are all working ? So simple set a breakpoint into the Tick event delegates first line and look if the program stops there ? If not, the delegate isn't called so it isn't set (Look into the timers Events List in the propertiesForm ( You can also look into the forms designer.cs if the delegate is coupled to the Tick event :wave:
I think the timer's tick event handler is ok. The event is connected to the handler on form load.
funnyusername
December 26th, 2008, 06:50 PM
It seems to be coupled ok. I also created a second timer, and copied the code for the tick event into that one, and executed with that timer instead, but no joy. The timer.Tick seems to be ignored......its like it goes through the code executing fine, but ignores any reference to the timer, and then just loads the main form. I tried commenting out the this.opacity = 100 aswell and the main form still shows........are we sure that the code is correct:
I think the timer's tick event handler is ok. The event is connected to the handler on form load.
But we DONT know that the Form_Load method is actually connected in the DESIGNER file.
Of course, if the OP would just follow the wuggestions, and post results we would be able to determine if THAT method was actually getting fired off....
funnyusername
December 26th, 2008, 06:58 PM
So simple set a breakpoint into the Tick event delegates first line and look if the program stops there ?
All my breakpoints are being ignored. I set them, run in Debug mode, and it doesn't stop.
(Look into the timers Events List in the propertiesForm
It is set as timer2_Tick in the timer 'Tick' event.
( You can also look into the forms designer.cs if the delegate is coupled to the Tick event :wave:
How do I do this....MainForm.cs(Design) or MainForm.cs? :eek: CPUWizard your rapidly making me afraid to ask questions...... :(
TheCPUWizard
December 26th, 2008, 07:07 PM
All my breakpoints are being ignored. I set them, run in Debug mode, and it doesn't stop.
Breakpoints are never "Ignored".... Either:
1) You are setting them on code which is not part of the project (the red circle will change to a ring when the program is running.
OR
2) The code is never being executed. And "Suprise"...doe that is not executed does not have an effect.
WHERE are you assigning the Load event to MainForm_Load...
The code should look like:
this.Load += new EventHandler(MainForm_Load);
This code should be in MainForm.Designer.cs.
If it is not, go back (do NOT manually edit the file) and look at the Events tab on the properties for the form, and see what is there for the Load event.....
[ps: If you had just set the breakpoints and reported that thery were not being hit, we could have been at this point an hour and a half ago.....]
funnyusername
December 26th, 2008, 07:12 PM
Incidentially, I do appreciate the help, and I apologise if it appears differently.
CPUWizard, with over 11,000 posts, you obviously give a lot of your time to helping others, and I understand that it must be frustrating when people like me come on, who are learning from books instead of experts, and have not done everything in the best possible order. Sorry if my post above seemed ungrateful, but I think we established that I am not as up to speed with the debugger as I obviously should be, and I have been following the steps in each suggestion above as best I can. Thankyou for your help, if you can advise on the problem at hand I would be grateful, and I WILL try to learn more about the debugger. But right now the debugger is the least of my worries! :) Thanks.
I created a brand new shiny empty project. Created a second form, used the code from my 'broken' project, and everything worked fine.
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 NewAttempt
{
public partial class Form1 : Form
{
SplashFrm SplashForm = new SplashFrm();
int timerClock = 0;
....I understand that it must be frustrating when people like me come on, who are learning from books instead of experts ...
Not at all...People who are learning for a good book, and following it carefully are the best. I DO get fustrated (and that is being nice) with people who think they can learn from random samples picked up over the internet.
Zip up yourt project (not the bin or obj directories) and post it. I will pin down what you are missing, then help YOU walk through finding the problem....
funnyusername
December 26th, 2008, 07:20 PM
Ok, just saw your reply. Im Program.cs I have:
namespace New_Program
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
The MainForm properties Load event shows: <i>MainForm_Load</i>
In MainForm.Designer.cs I can't see that line, it doesn't seem to be there.
funnyusername
December 26th, 2008, 07:23 PM
Zip up yourt project (not the bin or obj directories) and post it. I will pin down what you are missing, then help YOU walk through finding the problem....
I can't post it, even though its at a very early stage. Perhaps I can e-mail it to you and simply trust you not to share it? I'll pm you my email address. If you can pin it down I would appreciate the walk through. Thankyou.
Its very upsetting.....I can't understand why the same code works fine in two other projects..... :(
funnyusername
December 26th, 2008, 08:21 PM
Hello all,
Well the noobie is very embarassed! :o The issues seems to have been a corrupt build environment, and a rebuild fixed it! :) I guess running a rebuild is one of those basic things which I've just learned, and won't forget in a hurry. Thankyou all for helping, and especially TheCPUWizard who offered his email and time, and then identified this immediately. Cheers CPUWizard (I make a practise not to use peoples real names on the internet without permission, so please don't take offence).
Well, I'm off to learn some more through trial and error. Can anyone suggest a good C# book on amazon, that has a decent amount of info on debugging?
Thanks again. :)
L8rs.
funnyusername
December 26th, 2008, 08:24 PM
PS: I dont know how to rate people for helping, so I guess a thankyou will have to do. THANKYOU ALL, I appreciate it. :)
marceln
December 26th, 2008, 08:27 PM
PS: I dont know how to rate people for helping, so I guess a thankyou will have to do. THANKYOU ALL, I appreciate it. :)
it's the "ballance" icon in the upper-right corner of every post. :)
TheCPUWizard
December 26th, 2008, 08:42 PM
Cheers CPUWizard (I make a practise not to use peoples real names on the internet without permission, so please don't take offence).
TheCPUWizard is my real name (technically a trademark for the past quarter of a century ;) the name you say in the e-mail is just a psuedonym my mother gave me 50 years ago. :D:D:D:wave:
JonnyPoet
December 27th, 2008, 03:45 AM
Hello all,
Well the noobie is very embarassed! :o The issues seems to have been a corrupt build environment, and a rebuild fixed it! :) ....
Well, I'm off to learn some more through trial and error. Can anyone suggest a good C# book on amazon, that has a decent amount of info on debugging?
.What you are talking about in your last post seems all to me to be a broken delegate ( not connected to the form ) Otherwise your breakpoints are never ignored. As you have added the Tick delegate in the MainForm_Load delegate the next thing I would have done, if I would have had your situation is to set a breakpoint in the first line of the MainForm_Load delegate. If this also is ignored then you can be totally sure this event isn't fired. So as any form fires this event you can be sure it is not added to the MainForms Load event. Then I would look into the designer . This is a separate document since VS 2005 and its name is ( if the Forms name is MainForm) MainForm.designer.cs
If you look to your documents tree you will see that the Form has a '+' there. Expand the tree and you will see the document.
Open the code and you will find a section signed in a way like ' Automatic created code - dont touch' ( I dont know the correct English text, as my enviroment is german - so I can only retranslate the german text :D ) Open this text and you will find what you have created by drawing controls to the form with the designer.
Adding a delegate to an event always has the format
controlName.XYEvent += new xyEventHandler (controlName_xyEvent)
If your Form is named 'MainForm' the load Event is set like
this.Load += new System.EventHandler(this.MainMDI_Load);
Additional: Never be shy to ask simple questions. Even if someone sometimes sounds a bitt strict, this may happen, but believe me, its normally for your best.You will learn by those people to ask very exact questions and this is also very helpful to get the corrrect answers.
If you still have your old projectbuild anywhere you may find what has been wrong and this will also be a great lessn for you. Study the designer created code and you will understand a lot more about your own program.
BTW is there a reason to add the Tick event in the load event instead of in the designers code - InitializeComponent() directly.? ( I havn't studied your whole code yet ) :wave:
JonnyPoet
December 27th, 2008, 03:50 AM
The MainForm properties Load event shows: <i>MainForm_Load</i>
In MainForm.Designer.cs I can't see that line, it doesn't seem to be there.If you dont see it and it doesn't fire, IT IS NOT THERE, such simple. That was the built error ! :wave:
TheCPUWizard
December 27th, 2008, 06:09 AM
The OP mailed me the files, and I reviewed them....
The source files were fine. The problem was that the executable that was running was NOT built from the sources [exact reason unknown - as a rebuild fixed the problem].
The real first clue to this was when the OP sated that "BreakPoints were being ignored". Further investigation showed that they were NOT active because they were not matched up to the source (they showd as little reg "rings" reather than solid red "dots")
JonnyPoet
December 27th, 2008, 07:03 AM
The OP mailed me the files, and I reviewed them....
I see... strangeVS behavoiur. I remember only one time have had a similar behaviour in VS2005 when I had three projects conneced together ( 2x dlls and the main project)[/quote]I did some changes in the dlls code and pressed 'recreate projectmap' The project gives me a warning during debugging and told me that it cannot step into the dlls code because they are not up to date. ??? But I have pressed to recreate the pojectmap. Then I clicked to the dlls project file and recreated the dll itself and it was done. But IMHO if I have three projects added to gether and pressing 'recreate projectmap it should recompile the whole solution, but obviously it is not. ( there is no button in the menue which uses 'solution' in German VS.) So I think VS builing problems are very seldom.
funnyusername
December 27th, 2008, 02:08 PM
(snip!)...Then I would look into the designer.....(snip!).....Study the designer created code and you will understand a lot more about your own program.
BTW is there a reason to add the Tick event in the load event instead of in the designers code - InitializeComponent() directly.? ( I havn't studied your whole code yet ) :wave:
Thanks, I'll look back over that and try to go deeper. :) When I 'double-click' my timer in the IDE its default event is the timer.tick and the code is automatically placed there.
JonnyPoet
December 27th, 2008, 02:34 PM
...When I 'double-click' my timer in the IDE its default event is the timer.tick and the code is automatically placed there.Yes thats correct, but in any questions of a problem of nor working delegates I'm always looking into the designers code if all is correct here. So the question now is:
Have you added the delegate twice ? One times using IDE and clicking there so its added to the form in the designer and a second time in the Form Load event as I can see this in your posts ?
TheCPUWizard
December 27th, 2008, 02:44 PM
Yes thats correct, but in any questions of a problem of nor working delegates I'm always looking into the designers code if all is correct here. So the question now is:
Have you added the delegate twice ? One times using IDE and clicking there so its added to the form in the designer and a second time in the Form Load event as I can see this in your posts ?
Yes [at line 111 in the designer....] , it is enabled, interval=1000, and the event wired up in the designer.
Then in the Form Load event, is is sped up (interval=100), enabled (redundant) and wired up (redundant)
Sloppy, Definately. But not problematic. Remember the identity of a delegate is the source and target. And you can not add duplicate events (ie cduplicating the add, will NOT cause the event to fire twice as often).
IT HAD NOTHING TO DO WITH THE PROBLEM
JonnyPoet
December 27th, 2008, 03:13 PM
IT HAD NOTHING TO DO WITH THE PROBLEMThis is correct. It has nothing to do with the built error.
....And you can not add duplicate events (ie cduplicating the add, will NOT cause the event to fire twice as often).Try it, It fires twice as often. I just added a timer to a form and a Label and added the same delegate twice just as it was done. One time in the designer and one time in the form load event. Both are added with keyword new so they have the same pattern but are two delgate objects added. I did a counter for one step every second and show the results on a Label. It seems to step in steps of two. Because the event always is fired twice.
// Test project
public partial class Form1 : Form {
private int i = 0;
public Form1() {
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e) {
label1.Text = i.ToString();
i++;
}
private void Form1_Load(object sender, EventArgs e) {
timer1.Tick +=new EventHandler(timer1_Tick);
timer1.Enabled = true;
}
}
// and in InitializeComponents
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
....
So this was maybe the problem for it was vanished to quick.
;)
funnyusername
December 27th, 2008, 05:12 PM
Your right, but I don't think that was causing my problem, because the rebuild fixed it without me changing the code. I don't know why (Obviously) but I'm sure you do! I just located the line in the Initialize components, ran the project and counted approx 3 seconds for my fade. :)
I commented out the line in Initialize Components and ran again and my fade was approx 6 seconds.
I have now removed the timer settings in the Load event, and just left them in the Initialize Components.
I have deleted the tick += in the Initialize Components.
Thanks again. :)
JonnyPoet
December 27th, 2008, 06:19 PM
Your right, but I don't think that was causing my problem, because the rebuild fixed it without me changing the code.As I told before CPUWizard is correct, Double setting the delegate has nothing to do with the built error, this only causes that the fade out is half the time
I don't know why (Obviously) but I'm sure you do! I just located the line in the Initialize components, ran the project and counted approx 3 seconds for my fade. :) Yep that was what I wanted to tell you. That quick fade out is caused because the delegate is added twice so it also is called twice at every tick.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.