Quantcast
Channel: Help with timers and buttons
Viewing all articles
Browse latest Browse all 6

Help with timers and buttons

$
0
0

I am an ex program (quite a bit of VB6 back in the day) that needs to brush off some cobwebs and create a small application for work.  Basically the app will display 4 image stacks (basically 4 separate powerpoints) at one time and slowly go through each one at a set interval.  So at 00:00 all 4 quadrants would have 4 buttons that would all display slide 1, at 00:03 all 4 quadrants would have slide 2 and so fourth.

At the moment I have 4 buttons that are displaying the first slide statically but I cannot integrate a timer.  I think this is a permissions issue with multithreading but the timer is within the source file of the form and I do not know how to get around this permission problem.  I do have a timer running but I cannot have it's function update a control within the form.  Any assistance would be greatly appreciated.

Thank you

BR

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;
using System.Timers;

namespace ACHAS_Support_Portal_Beta
{

    public partial class frmMain : Form
    {
        //public System.Timers.Timer timer = new System.Timers.Timer(10000);

        public frmMain()
        {
            InitializeComponent();

            //timer.Enabled = true;
            //timer.Elapsed += new System.Timers.ElapsedEventHandler(Func_Timer);
            int reswidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            int resheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

            lblBtn1Cnt.Location = new Point(-10, -10);
            lblBtn2Cnt.Location = new Point(-10, -10);
            lblBtn3Cnt.Location = new Point(-10, -10);
            lblBtn4Cnt.Location = new Point(-10, -10);


            btn1.Size = new Size(reswidth / 2 - 20, resheight / 2 - 20);
            btn1.Location = new Point(10, 10);
            btn2.Size = new Size(reswidth / 2 - 20, resheight / 2 - 20);
            btn2.Location = new Point(reswidth / 2 + 10, 10);
            btn3.Size = new Size(reswidth / 2 - 20, resheight / 2 - 20);
            btn3.Location = new Point(10, resheight / 2 + 10);
            btn4.Size = new Size(reswidth / 2 - 20, resheight / 2 - 20);
            btn4.Location = new Point(reswidth / 2 + 10, resheight / 2 + 10);
            btn1.BackgroundImage = Image.FromFile(@"C:\Assets\Power Point 1\slides\Slide1.JPG");
            btn2.BackgroundImage = Image.FromFile(@"C:\Assets\Map\map button.jpg");
            btn3.BackgroundImage = Image.FromFile(@"C:\Assets\Power Point 3\slides\Slide1.JPG");
            btn4.BackgroundImage = Image.FromFile(@"C:\Assets\Power Point 4\slides\Slide1.JPG");
    }

        private void Form1_Load(object sender, EventArgs e)
        {


        }
        private void Frmmain_shown(object sender, EventArgs e)
        {
            // Shot size = screen size
            Size shotSize = Screen.PrimaryScreen.Bounds.Size;
            // the upper left point in the screen to start shot
            // 0,0 to get the shot from upper left point
            Point upperScreenPoint = new Point(0, 0);
            // the upper left point in the image to put the shot
            Point upperDestinationPoint = new Point(0, 0);
            // create image to get the shot in it
            Bitmap shot = new Bitmap(shotSize.Width, shotSize.Height);
            // new Graphics instance 
            Graphics graphics = Graphics.FromImage(shot);
            // get the shot by Graphics class 
            graphics.CopyFromScreen(upperScreenPoint, upperDestinationPoint, shotSize);
            // return the image

        }

        private void btn1_Click(object sender, EventArgs e)
        {
            int reswidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            int resheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            var frmSecond = new frmChild();
            frmSecond.WindowState = FormWindowState.Maximized;
            frmSecond.webBrowser1.Navigate(@"C:\Assets\Power Point 1\index.html");
            //System.Windows.Forms.MessageBox.Show("it is " + MyGlobalValue);
            frmSecond.btnPrevious.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnPrevious.Location = new Point(reswidth / 2 - reswidth / 15 - reswidth / 15 - reswidth / 15, resheight - resheight / 14);
            frmSecond.btnExit.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnExit.Location = new Point(reswidth / 2 - reswidth / 30, resheight - resheight / 14);
            frmSecond.btnNext.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnNext.Location = new Point(reswidth / 2 + reswidth / 15 + reswidth / 15, resheight - resheight / 14);
            frmSecond.lblCount.Text = "1";
            frmSecond.Show();

        }

        private void btn2_Click(object sender, EventArgs e)
        {
            int reswidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            int resheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            var frmSecond = new frmChild();
            frmSecond.WindowState = FormWindowState.Maximized;
            frmSecond.webBrowser1.Navigate(@"C:\Assets\Map\source\index.html");
            // System.Windows.Forms.MessageBox.Show("it is " + SomeVariable);
            frmSecond.btnPrevious.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnPrevious.Location = new Point(reswidth / 2 - reswidth / 15 - reswidth / 15 - reswidth / 15, resheight - resheight / 14);
            frmSecond.btnExit.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnExit.Location = new Point(reswidth / 2 - reswidth / 30, resheight - resheight / 14);
            frmSecond.btnNext.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnNext.Location = new Point(reswidth / 2 + reswidth / 15 + reswidth / 15, resheight - resheight / 14);
            frmSecond.lblCount.Text = "2";
            frmSecond.Show();
        }

        private void btn3_Click(object sender, EventArgs e)
        {
            int reswidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            int resheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            var frmSecond = new frmChild();
            frmSecond.WindowState = FormWindowState.Maximized;
            frmSecond.webBrowser1.Navigate(@"C:\Assets\Power Point 3\index.html");
            //System.Windows.Forms.MessageBox.Show("it is " + resheight);
            frmSecond.btnPrevious.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnPrevious.Location = new Point(reswidth / 2 - reswidth / 15 - reswidth / 15 - reswidth / 15, resheight - resheight / 14);
            frmSecond.btnExit.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnExit.Location = new Point(reswidth / 2 - reswidth / 30, resheight - resheight / 14);
            frmSecond.btnNext.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnNext.Location = new Point(reswidth / 2 + reswidth / 15 + reswidth / 15, resheight - resheight / 14);
            frmSecond.lblCount.Text = "3";
            frmSecond.Show();
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            int reswidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
            int resheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
            var frmSecond = new frmChild();
            frmSecond.WindowState = FormWindowState.Maximized;
            frmSecond.webBrowser1.Navigate(@"C:\Assets\Power Point 4\index.html");
            //System.Windows.Forms.MessageBox.Show("it is " + resheight);
            frmSecond.btnPrevious.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnPrevious.Location = new Point(reswidth / 2 - reswidth / 15 - reswidth / 15 - reswidth / 15, resheight - resheight / 14);
            frmSecond.btnExit.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnExit.Location = new Point(reswidth / 2 - reswidth / 30, resheight - resheight / 14);
            frmSecond.btnNext.Size = new Size(resheight / 15, resheight / 15);
            frmSecond.btnNext.Location = new Point(reswidth / 2 + reswidth / 15 + reswidth / 15, resheight - resheight / 14);
            frmSecond.lblCount.Text = "4";
            frmSecond.Show();
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void Func_Timer(object source, System.Timers.ElapsedEventArgs e)
        {
            int var_cnt1 = Int32.Parse(lblBtn1Cnt.Text);
            //System.Windows.Forms.MessageBox.Show("it is ");

            if (File.Exists(@"C:\Assets\Power Point 1\slides\Slide" + var_cnt1 + ".JPG"))
            {
                btn1.BackgroundImage = Image.FromFile(@"C:\Assets\Power Point 1\slides\Slide" + var_cnt1 + ".JPG");
                var_cnt1 = var_cnt1 + 1;
                this.lblBtn1Cnt.Text = var_cnt1.ToString();
            }

        }

    }

}


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images