CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    Join Date
    Jul 2008
    Posts
    169

    [RESOLVED] Splash Form Timer.Tick - not Working

    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! Can someone help debug it please?

    My time is set to 'Enabled' and Interval '1000' in properties......

    This is the code:

    Code:
    public partial class MainForm : Form
        {
            SplashScreen SplashForm = new SplashScreen();
            int timerClock = 0;
    
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void MainForm_Load(object sender, EventArgs e)
            {
                SplashForm.Show();
    
                timer1.Enabled = true;
                timer1.Tick += new System.EventHandler(this.timer1_Tick);
    
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (timerClock >= 40)
                {
                    SplashForm.Opacity = SplashForm.Opacity - .4;
                }
                timerClock++;
                if (timerClock == 20)
                {
                    SplashForm.Close();
                    this.Opacity = 100;
                    timer1.Enabled = false;
                }
            }

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Splash Form Timer.Tick - not Working

    What EXACTLY happens when you DEBUG it, the first step is putting a breakpoint at each method and then SINGLE STEPPING through the code.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jul 2008
    Posts
    169

    Re: Splash Form Timer.Tick - not Working

    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!!!

  4. #4
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Splash Form Timer.Tick - not Working

    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:
    Code:
                if (timerClock < 20)
                {
                    SplashForm.Opacity = SplashForm.Opacity - .05;
                }
                timerClock++;
                if (timerClock == 20)
                {
                    SplashForm.Close();
                    this.Opacity = 100;
                    timer1.Enabled = false;
                }
    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.

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Splash Form Timer.Tick - not Working

    And learning the debugger is something you aparently skipped. You should have practived the debugger as soon as you wrote:
    Code:
    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Jul 2008
    Posts
    169

    Re: Splash Form Timer.Tick - not Working

    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:
    Code:
    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:
    Code:
    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:
    Code:
    if (timerClock == 60)
                {
                    SplashForm.Close();
                    this.Opacity = 100;
                    timer1.Enabled = false;
                }
    .....hmmph! It still doesn't work.....

  7. #7
    Join Date
    Jul 2008
    Posts
    169

    Re: Splash Form Timer.Tick - not Working

    I am learning......did you get out of the wrong side of the bed? (Just kidding.... )

    Your changes to the timer didn't work either....

  8. #8
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Splash Form Timer.Tick - not Working

    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?

  9. #9
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Splash Form Timer.Tick - not Working

    Quote Originally Posted by funnyusername View Post
    I am learning......did you get out of the wrong side of the bed? (Just kidding.... )
    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.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  10. #10
    Join Date
    Jul 2008
    Posts
    169

    Re: Splash Form Timer.Tick - not Working

    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.

  11. #11
    Join Date
    Jul 2008
    Posts
    169

    Re: Splash Form Timer.Tick - not Working

    Ok......something VERY weird is going on......

    If I comment out the line
    Code:
    SplashForm.Show();
    it makes no difference!!!

    Any ideas? Could it be in the settings somewhere to ignore my changes (Visual Studio 2008 Stnd Ed) ?

  12. #12
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Splash Form Timer.Tick - not Working

    Because it is visible by default. Take a look at the splash form's properties.

  13. #13
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Splash Form Timer.Tick - not Working

    Quote Originally Posted by funnyusername View Post
    . 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..
    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?

    The debugger is NOT about "errors showing up...

    Consider the following code:
    Code:
    decimal price = 1.95M;
    decimal quantity = 3M;
    decimal total = price*quantity;
    Console.WriteLine(total);
    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.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  14. #14
    Join Date
    Jul 2008
    Posts
    169

    Re: Splash Form Timer.Tick - not Working

    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!!!

    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 SplashDemo
    {
        public partial class Form1 : Form
        {
            Timer timer1 = new Timer();
            frmSplash SplashScreen = new frmSplash();
            int timerClock = 0;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                SplashScreen.StartPosition = FormStartPosition.CenterScreen;
                SplashScreen.Show();
    
                this.Opacity = 0;
                this.StartPosition = FormStartPosition.CenterScreen;
    
                timer1.Interval = 100;
                timer1.Enabled = true;
                timer1.Tick += new System.EventHandler(this.timer1_Tick);
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (timerClock >= 20)
                {
                    SplashScreen.Opacity = SplashScreen.Opacity - .04;
                }
                timerClock++;
                if (timerClock == 60)
                {
                    SplashScreen.Close();
                    this.Opacity = 100;
                    timer1.Enabled = false;
                }
            }
        }
    }
    Here is the code in my current program which I have changed again to match, and it DOES NOT WORK!!!

    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 New_Program
    {
        public partial class MainForm : Form
        {
            SplashScreen SplashForm = new SplashScreen();
            int timerClock = 0;
    
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void MainForm_Load(object sender, EventArgs e)
            {
                SplashForm.Show();
                this.Opacity = 0;
    
                timer1.Interval = 100;
                timer1.Enabled = true;
                timer1.Tick += new System.EventHandler(this.timer1_Tick);
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (timerClock >= 20)
                {
                    SplashForm.Opacity = SplashForm.Opacity - .04;
                }
                timerClock++;
                if (timerClock == 60)
                {
                    SplashForm.Close();
                    this.Opacity = 100;
                    timer1.Enabled = false;
                }
            }
            
            private void consumableToolStripMenuItem_Click(object sender, EventArgs e)
            {
                NewConsumable newConForm = new NewConsumable();
                newConForm.ShowDialog();
            }
        }
    }

  15. #15
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Splash Form Timer.Tick - not Working

    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.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured