Solved

Changing picture box in C#

Posted on 2009-04-02
9
1,072 Views
Last Modified: 2013-12-17
Hello,
I have a application that has an animation that runs every 2 minutes to remind users to use the application, this was done in the animation creation of the .gif.  What I want to have happen is when a user clicks the submit button another image comes up for 5 to 10 seconds and then reverts back to the original place image.  

How would I write and where would I put this if possible?
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;
using System.Collections;
using System.Xml;
using System.ServiceModel;
using System.Net;
 
namespace Trigger_Tracker
{
    public partial class Form1 : Form
    {//form move on click and drag
        bool FormMoving;
        Point initialPoint;
        TriggerTrackerPictureBox frmPicture;
 
        public Form1()
        {//form move on click and drag
            InitializeComponent();
            comboBox1.SelectedIndex = 0;
            FormMoving = false;
 
            frmPicture = new TriggerTrackerPictureBox();
            frmPicture.localForm = this;
            frmPicture.Owner = this;
            frmPicture.Show();
            frmPicture.Width = 68;
            frmPicture.Height = 65;
            SetPositionOfPictureForm();
        }
 
        private void SetPositionOfPictureForm()
        {
            frmPicture.Top = this.Top + 26;
            frmPicture.Left = this.Left + 87;
        }
 
        private void TriggerTrackerLoad(object sender, EventArgs e)
        {
 
        }
 
        private void PolicyNumberLabel(object sender, EventArgs e)
        {
 
        }
 
        private void TrackerButton(object sender, EventArgs e)
        {
            string listGUID = "A93E1A7E-67D0-4D7D-A4ED-803D7DFE684B";
            string viewGUID = "6B2F3EF2-4B0C-41E1-B87E-0C3185B587DD";
            //string viewGUID2 = "6B2F3EF2-4B0C-41E1-B87E-0C3185B587DD";
 
            int ItemCounter = 1;
            ServiceList.Lists listService = new ServiceList.Lists();
           // RetentionLists.ListsSoapClient listService = new RetentionLists.ListsSoapClient();
 
            //////
           listService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
           //listService.ChannelFactory.Credentials.Windows.ClientCredential   = System.Net.CredentialCache.DefaultNetworkCredentials;
 
            XmlNode activeItemData = listService.GetListItems(listGUID, viewGUID, null, null, "100", null);
            XmlDocument xDoc = new XmlDocument();
            string tmpString = activeItemData.InnerXml.Replace("\r\r", "");
            xDoc.LoadXml(tmpString);
            XmlNamespaceManager nsManager = new XmlNamespaceManager(xDoc.NameTable);
            nsManager.AddNamespace("z", "#RowsetSchema");
            nsManager.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
 
            XmlNodeList xNode = xDoc.SelectNodes("/rs:data/z:row", nsManager);
 
            foreach (XmlNode tmpNode in xNode)
                ItemCounter++;
 
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append("<Method ID='" + ItemCounter + "' Cmd='New'>");
            strBuilder.Append("<Field Name='Attachments'>" + "0" + "</Field>");
            strBuilder.Append("<Field Name='Title'>" + PolicyNumber.Text + "</Field>");
            strBuilder.Append("<Field Name='Reason'>" + comboBox1.Text + "</Field>");
            strBuilder.Append("</Method>");
 
            string strBatch = strBuilder.ToString();
 
            XmlDocument newDoc = new XmlDocument();
            XmlElement newElement = newDoc.CreateElement("Batch");
            newElement.SetAttribute("OnError", "Continue");
            newElement.SetAttribute("ViewName", viewGUID);
            newElement.InnerXml = strBatch;
            
            XmlNode returnNode = listService.UpdateListItems(listGUID, newElement);
 
            this.comboBox1.Text = "Please Select....";
            this.PolicyNumber.Text = "";
            this.PolicyNumber.Mask = "0000000000";
 
            comboBox1.Focus();
        }
 
        private void PolicyNumberTextBox(object sender, EventArgs e)
        {
 
        }
 
 
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            
        }
 
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {           
            
        }
 
        private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {
 
        }
 
 
        public void Form1_MouseUp(object sender, MouseEventArgs e)
        {//form move on click and drag
            FormMoving = false;
        }
 
        public void Form1_MouseMove(object sender, MouseEventArgs e)
        {//form move on click and drag
            if (FormMoving)
            {
                if ((Left + e.X - initialPoint.X) <= 0)
                    Left = 0;
                else if ((Right + e.X - initialPoint.X) >= Screen.PrimaryScreen.Bounds.Right)
                    Left = Screen.PrimaryScreen.Bounds.Right - Width;
                else
                    Left = Left + e.X - initialPoint.X;
                if ((Top + e.Y - initialPoint.Y) <= 0)
                    Top = 0;
                else if ((Bottom + e.Y - initialPoint.Y) >= Screen.PrimaryScreen.Bounds.Bottom)
                    Top = Screen.PrimaryScreen.Bounds.Bottom - Height;
                else
                    Top = Top + e.Y - initialPoint.Y;
            }
            SetPositionOfPictureForm();
        }
 
        public void Form1_MouseDown(object sender, MouseEventArgs e)
        {//form move on click and drag
            FormMoving = true;
            initialPoint = new Point(e.X, e.Y);
        }
 
        public void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {//form move on click and drag
            FormMoving = true;
            initialPoint = new Point(e.X, e.Y);
        }
 
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
        }
 
        private void pictureBox1_MouseHover(object sender, EventArgs e)
        {
        }
 
        public void label1_MouseHover(object sender, EventArgs e)
        {
            FormMoving = false;
        }
 
        public void label1_MouseUp(object sender, MouseEventArgs e)
        {
            FormMoving = false;
        }
 
        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
 
        }
 
        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
 
        }
 
        public void Form1_MouseHover(object sender, EventArgs e)
        {
            this.Opacity = 1;
        }
 
        public void Form1_MouseLeave(object sender, EventArgs e)
        {
            if(!PolicyNumber.Focused)
                this.Opacity = .25;
        }
 
        public void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.Opacity = 1;
        }
 
        public void pictureBox1_MouseHover_1(object sender, EventArgs e)
        {
            this.Opacity = 1;
        }
 
        public void Form1_Click(object sender, EventArgs e)
        {
            comboBox1.Focus();
        }
    }
}

Open in new window

0
Comment
Question by:Andrew Bass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 24056312
Hi NinjasVsPirates;

First place a Timer control on the form then you implement code as the code snippet shows.

Fernando
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
 
    // Variables to hold the two images for the picture box
    private Image imageMain;
    private Image imageTemp;
    
    private void Form1_Load(object sender, EventArgs e)
    {
        // Load the images into memory
        imageMain = Image.FromFile(@"C:\temp\imageMain.jpg");
        imageTemp = Image.FromFile(@"C:\temp\imageTemp.jpg");
        // Set the picture box main image here
        pictureBox1.Image = imageMain;
        // Set the timer interval to 5 seconds, each value 1000 = 1 second.
        timer1.Interval = 5000;
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        // In the click event that changes the image, set the image to the other one
        pictureBox1.Image = imageTemp;
        // Enable the timer to start running
        timer1.Enabled = true;
    }
 
    private void timer1_Tick(object sender, EventArgs e)
    {
        // After the set interval this method is called by the system
        // Disable the timer from triggering again
        pictureBox1.Enabled = false;
        // Reset the image back to the main image
        pictureBox1.Image = imageMain;
    }
 
}

Open in new window

0
 
LVL 16

Expert Comment

by:CuteBug
ID: 24056328
When the user click the button,
1. change the image in the picturebox with new image
2. start a timer which fires the event at 5 or 10 seconds as per your requirement.

When the timer event fires,
1. stop the timer
2. change the image of the picture box back to the original image.

http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24056411
Hi CuteBug, That is exactly what I showed in code.
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 16

Expert Comment

by:CuteBug
ID: 24056508
Hi Fernando,
    When I typed my answer... your comment was not visible...
    I thought i was the first one to answer...

    I guess my page wasnt refreshed... :)

regards,
CuteBug
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24056634
Not a problem.  ;=)
0
 
LVL 1

Author Comment

by:Andrew Bass
ID: 24062397
Thanks Fernado, thanks as well cutebug even if you were not first :)
0
 
LVL 1

Author Closing Comment

by:Andrew Bass
ID: 31566038
Have a great weekend! Thanks :)
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24065240
Not a problem, glad I was able to help.  ;=)
0
 
LVL 16

Expert Comment

by:CuteBug
ID: 24065967
u r welcome :)
0

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question