• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2049
  • Last Modified:

Displaying Icon over an Image

To further my knowledge and understanding of what it is that I am creating based on my prior two questions. What I need to be able to do now is overlay an icon on an image.

I have create a form application that will do a number of things one of the forms within the application will read a folder and display the thumbnail images within that folder. Then when you double click on an image a second form will appear and allow the user to see that image in full view along with zoom (& eventually pan but that isn't working at the moment). Either way now what I would like to be able to do is state that if picture 'A.2' is clicked on icon image '004' will appear ontop image in vector '48'  or something along those lines. I would also like the icon to be able to zoom and pan with the images it is on top of if at all possible.

Not sure ow to go about this I was thinking it would just be a matter of creating a switch with the case for each image inside the folder or a series of if else statements. Any thought? If you want to see the code for the other two forms I create just let me know I just wasn't sure how important that is to this topic so I didn't post it to start with.
0
seahna
Asked:
seahna
  • 34
  • 29
8 Solutions
 
Kelvin McDanielSr. Developer/ConsultantCommented:
You can use one of the following... I'm partial to #1 because you don't need anything special to do it. #2 through #5 depend on plugins that may not be present of visitor machines.

1. CSS (example provided)
2. Silverlight
3. Flash
4. Java (yukk!)
================================================
In a <style> tag or external .css file:
------------------------------------------------
.imageContainer div.caption
{
	color:Red;
	font-weight:bold;
	left:100px;
	position:absolute;
	top:300px;
}

================================================
Code in file:
------------------------------------------------
<div class="imageContainer">
    <asp:Image ID="Image1" ImageUrl="~/Images/people.png" runat="server" />
    <div class="caption">This is a test.</div>
</div>

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Does zoom need to be dynamic, or is it going to be a static value? If it needs to be dynamic then you're going to want to change out the "This is a test." with either a Label control or use JavaScript to update the "caption" div InnerHtml on the fly.
0
 
seahnaAuthor Commented:
Not sure I understand you but I think that is because you don't understand me. The software I am developing is a security management tool. I am importing maps (my images) layouts of builds then overtop those maps I need icon images that represent specific things like doors, intercom stations and other device connected to the management tool. Thee attached code is what I have so far for the other two forms that are working in conjunction to what I am now trying to create.

Form 1 is the form that read a folder and displays the thumbnails images of the maps on the screen then when you double click on a thumbnail a second form will appear on the screen.

Form 2 is the form that displays the full image of the map that was double clicked in the prior Form 1. Here is where I want to make an added change stating that if 'map 1' was click icon image representing a door will appear on 'some location of the map' and icon image blah... and any other icon image associated with that map image. The problem here is I need the application to scan an XML file to retrieve the information.

Basically I want Form 1 to scan an XML document to see what folder it needs to scan to display the thumbnails it would be nice to have the thumbnails display the icon images as well but that is minor details that can be corrected latter. Next when a map image is clicked on Form 2 appears with the associated icons on it that were read from the same XML Code

A large part of this I have figured out as you can see by the code attached. The only part I don't understand is getting the application to scan the XML file, understand that it needs to scan the folder specified in the XML file to display the thumbnails, and then when a thumbnail is clicked on display that image with the associated icon images.

I hope you understand me.
Form 1
-------------------------------------------------------------------------

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 AV4._1_ClientTool.Dialogs1.View
{
    public partial class Maps : Form
    {
        public Maps()
        {
            InitializeComponent();
        }
        //form global variables
        ImageList thumbs = new ImageList();
        Size ThumbSize = new Size(64, 64);
        PictureBox pb = new PictureBox();
        Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1();


        #region Thumbnails

        private void Maps_Load(object sender, EventArgs e)
        {
            thumbs.ImageSize = ThumbSize;
            thumbs.ColorDepth = ColorDepth.Depth32Bit;
            listView1.View = System.Windows.Forms.View.LargeIcon;
            listView1.LargeImageList = thumbs;
 
            string path = @"C:\Projects\AV4.1\Images";

            PictureBox pb = new PictureBox();
            pb.Size = thumbs.ImageSize;
            pb.SizeMode = PictureBoxSizeMode.Zoom;
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
            foreach (System.IO.FileInfo fi in di.GetFiles("*.jpg"))
            {
                Bitmap bmp = new Bitmap(pb.Width, pb.Height);
                pb.Image = Image.FromFile(fi.FullName);
                pb.DrawToBitmap(bmp, pb.ClientRectangle);
                thumbs.Images.Add(bmp);
                ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileNameWithoutExtension(fi.Name), thumbs.Images.Count - 1);
                lvi.Tag = fi.FullName;
                listView1.Items.Add(lvi);
            }
            foreach (System.IO.FileInfo fi in di.GetFiles("*.bmp"))
            {
                Bitmap bmp = new Bitmap(pb.Width, pb.Height);
                pb.Image = Image.FromFile(fi.FullName);
                pb.DrawToBitmap(bmp, pb.ClientRectangle);
                thumbs.Images.Add(bmp);
                ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileNameWithoutExtension(fi.Name), thumbs.Images.Count - 1);
                lvi.Tag = fi.FullName;
                listView1.Items.Add(lvi);
            }
        }
        #endregion

        #region Full Image Popup
                private void listView1_DoubleClick(object sender, EventArgs e)
        {
            Point pt = listView1.PointToClient(Cursor.Position);
            ListViewItem lvi = listView1.GetItemAt(pt.X, pt.Y);

            if (lvi != null)
            {
                Image tmp = Image.FromFile((string)lvi.Tag);
                Bitmap bmp = new Bitmap(tmp);
                tmp.Dispose();

                frm.Text = lvi.Text;
                frm.pictureBox1.Image = bmp;

                frm.Show();
            }
        }
        #endregion

    }
}

-------------------------------------------------------------------------
Form 2
-------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Media;
using System.Drawing.Imaging;


namespace AV4._1_ClientTool.Dialogs1.Display
{
    public partial class Map1 : Form
    {
        private double ZOOMFACTOR = 1.25;	// = 25% smaller or larger
        private int MINMAX = 5;				// 5 times bigger or smaller than the ctrl

        public Map1()
        {
            InitializeComponent();

            this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

        }
        #region Zooming Methods

        /// <summary>
        /// Make the PictureBox dimensions larger to effect the Zoom.
        /// </summary>
        /// <remarks>Maximum 5 times bigger</remarks>
        private void ZoomIn()
        {
            if ((pictureBox1.Width < (MINMAX * panel1.Width)) &&
                (pictureBox1.Height < (MINMAX * panel1.Height)))
            {
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * ZOOMFACTOR);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

                           }
        }

        /// <summary>
        /// Make the PictureBox dimensions smaller to effect the Zoom.
        /// </summary>
        /// <remarks>Minimum 5 times smaller</remarks>
        private void ZoomOut()
        {
            if ((pictureBox1.Width > (panel1.Width / MINMAX)) &&
                (pictureBox1.Height > (panel1.Height / MINMAX)))
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width / ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height / ZOOMFACTOR);

                            }
        }

        #endregion

        #region Mouse Events
        private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                ZoomOut();
            }
            else
            {
                ZoomIn();
            }
        }
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            if (pictureBox1.Focused == false)
            {
                pictureBox1.Focus();
            }
        }
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.panel1.Focus(); // give the form focus instead
        }
        #endregion

        #region Button Events
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ZoomIn();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ZoomOut();
        }
        #endregion
    }
}

Open in new window

0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
Kelvin McDanielSr. Developer/ConsultantCommented:
Well, the XML part is easy. I think that's actually a separate issue than the icon loading and movement.

For the XML you'll need to decide upon some type of unique key, which could simply be the name of the file itself, that you'll use to identify one node set from another. Here's sample code showing how to read an XML file. What I've done is create a 2 classes; 1) is a custom object to hold strongly-typed values, and 2) contains a method that accepts the key talked about a few sentences earlier and uses that value to find the proper node to load data from.

using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace ClassLibrary1
{
    public class Class1
    {
        private static List<IconItem> IconSet = new List<IconItem>();

        private static void ProcessXml(string targetMap) // target map can be what you want; it's the key I spoke of
        {
            using (var stream = new StreamReader(@"C:\Projects\AV4.1\XML\mappings.xml")) // I made up this path and file; change it
            {
                var xml = new XmlDocument();
                xml.Load(stream);

                if (xml.ChildNodes.Count > 0)
                    IconSet.Clear();

                foreach (var node in xml.ChildNodes)
                {
                    var obj = (XmlNode)node;
                    if (obj.Attributes["Id"].Value != targetMap) continue;

                    foreach (var item in obj.Attributes)
                    {
                        var attribute = (XmlAttribute)item;
                        var iconObj = new IconItem();
                        switch (attribute.Name)
                        {
                            case "FileName":
                                iconObj.FileName = attribute.ToString();
                                break;
                            case "IconName":
                                iconObj.IconName = attribute.ToString();
                                break;
                            case "CoordinateX":
                                var cX = default(int);
                                int.TryParse(attribute.ToString(), out cX);
                                iconObj.CoordinateX = cX;
                                break;
                            case "CoordinateY":
                                var cY = default(int);
                                int.TryParse(attribute.ToString(), out cY);
                                iconObj.CoordinateX = cY;
                                break;
                        }
                        IconSet.Add(iconObj);
                    }
                    break; // no need to continue; we've found the right node
                }
            }
        }
    }

    public class IconItem
    {
        public string FileName { get; set; }
        public string IconName { get; set; }
        public int CoordinateX { get; set; }
        public int CoordinateY { get; set; }
    }
}

Open in new window

0
 
seahnaAuthor Commented:
Ok let me study what you have provided me and I will get back to you as soon as I can. Thanks.
0
 
seahnaAuthor Commented:
Ok I understand what you are saying I think. However I am not sure how to apply it to what I have. I believe in "Form 1" I need to create some kind of process to read an XML file. I would assume that this would need to be public so that "Form 2" can read it as well. "Form 1" reads this XML file and based off the data sotred in the XML "Form 1" displyas the thumbnail images and the application move forward from there. A little explanation would be great if you could please....

I also noticed that in your code you broke up the x and y coord's I didn't in my XML code let me know if if might be better I change this part to something like this:

<XCoord> 245</XCoord>
<YCoord>380</YCoord>
<?xml version="1.0" encoding="utf-8"?>
<Setup>
  <Options>
    <Maps>
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
      <Map>
        <Image>Testing image.bmp</Image>
        <Icon>icon idle.bmp</Icon>
        <IconLocation>766,445</IconLocation>
      </Map>
      <Map>
        <Image>Testing image 2.bmp</Image>
        <Icon>icon idle.bmp</Icon>
        <IconLocation>245,388</IconLocation>
      </Map>
    </Maps>
  </Options>
</Setup>

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
It has  occurred to me that in my first post I assumed you were dealing with web pages. It's clear to me now that you're dealing with WinForms. This post takes this into consideration.

Regarding breaking up the coordinates: either technique is fine, just pick one and stick with it.  :)  I avoid splitting anything I don't have to... but that's personal choice.

Regarding where the code "lives", instead of putting the code for the processing in Form1, I suggest that you put it in a separate Class Library (project)... which will properly separate the concerns. Consider this; if Form1 is ever closed and/or disposed then you'll lose any data stored there. However, if it's in a external/separate static object then it will persist until explicity disposed or the application is closed.

The processing for this external object should also be external to Form1... since Form1 really has nothing to do with it, and Form1 should only display data anyway. In this methodology (which is N-Tier), both Form1 and Form2 are "dumb" and only show what you tell them to show.

To answer your question directly, here's what I think:
1. Somewhere in Program.cs, run the method in the external Class Library that processes the XML file, caches the results; that way it's immediately available when needed for Form2.

2. Form1 goes through its process as you have it already in the code you provided.

3. Form2 gets the key from Form1 and queries the cache for all icons matching this key. Matching items are passed back for display on Form2.

I've got an example project that illustrates what I'm talking about. Unfortunately, EE isn't being very friendly about essential files so if you want it you'll need to email me at the address in my profile.
0
 
seahnaAuthor Commented:
ok I would love to look at the project you can send it to me sarai.schmidt@zenitel.com. Thank you ahead of time for offering to help me so much once you send it I'll look at it and come back and ask you any questions I may have.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Success! I figured out how to get the uploader to accept a complete project.

To get this project to open properly, then build, you need to rename the following file as shown:
BitmapTest.zip --> BitmapTest\BitmapTest\Properties\ --> rename "Settings.settings.txt" to "Settings.settings"
BitmapTest.zip
0
 
seahnaAuthor Commented:
Ok I am still studying what you e-mailed me ...Congratz btw... I will let you know what I figure out.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Was just informed of a great service for us EE users... You can disregard the previous link I posted above, because it requires that you modify a file or two to get things build-able again.

Use this link instead; it is build-able and run-ready right out of the box:
https://filedb.experts-exchange.com/incoming/ee-stuff/7825-BitmapTest.zip
0
 
seahnaAuthor Commented:
Ok got a questions in the program.cs file you have the line:

BusinessTier.IconFactory.PopulateIconSet(@"mappings.xml");

Instead of coding it to directly read the XML file because this location is suppose to be change able and I have other area of the application to read the XML file from the app.config file via a key. I have been point to the key by using:

using System.Configuration;

and

private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"];

Would this work in this situation where I change you line of code to refernce this file using something like this:

BusinessTier.IconFactory.PopulateIconSet("ConfigFileName");


So far this is the only question I have I am still look at the other parts...thanks again
app.config file
------------------------------------------------------------------------
<configuration>
  <appSettings>
    <add key="ConfigFileName" value="C:/Projects/AV4.1/DefaultConfig.xml" />
  </appSettings>
</configuration>

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Almost. You'll want to drop those quotes when you reference the variable.

*** This part will stay; it's fine ***
private static string ConfigFileName = ConfigurationManager.AppSettings["ConfigFileName"];

*** You had ***
BusinessTier.IconFactory.PopulateIconSet("ConfigFileName");

*** It should be ***
BusinessTier.IconFactory.PopulateIconSet(ConfigFileName);
0
 
seahnaAuthor Commented:
Sorry so long to respond I was off for the Holidays...

Ok I get most of your code. Like the BusinessTier files control the icon information. What I don't understand is how to mix this in with what I have already to control the zooming functionality. It looks like beside the BusinessTier files the only other piece of code I need is what I have attached. However I am not sure the best way to integrate this into the code I have attached above. Clarification if I am not understanding something or thoughts on this would be great.

Just so you know what I am think I thought that this piece of code should go into Form 1 I have above but just not sure how I am still studying what you have and wha tI have to figure it out.

public void ShowFile(string targetFileName)
        {
            pb.Controls.Clear();
            foreach (var item in BusinessTier.IconFactory.ImageSet)
            {
                if (item.Image != targetFileName) continue;

                pb.Image = Image.FromFile(string.Format(@"{0}\{1}", item.Path, item.Image));
                foreach (var icon in item.Icons)
                {
                    var tempIcon = Image.FromFile(icon.File);
                    var tempPicturebox = new PictureBox
                    {
                        Image = tempIcon,
                        Location = new Point(icon.CoordinateX, icon.CoordinateY),
                        Size = new Size(tempIcon.Width, tempIcon.Height),
                    };
                    pb.Controls.Add(tempPicturebox);
                }
            }
        }

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
The code you provided in your last post should definitely go in Form2 because a) it has no bearing whatsoever on the functionality of Form1, and b) it is specific to a control on Form2.

Unless I'm missing something, you  would...

1. Add the following property to Form1 (in your form global variables list):
static string targetFileName {get; set;}
       * doing this makes accessing the value from Form2 much easier and less prone to weird behavior


2. Change the following method in Form1 as shown:
#region Full Image Popup
private void listView1_DoubleClick(object sender, EventArgs e)
{
    Point pt = listView1.PointToClient(Cursor.Position);
    ListViewItem lvi = listView1.GetItemAt(pt.X, pt.Y);

    if (lvi != null)
    {
        targetFileName = (string)lvi.Tag;
        frm.Text = lvi.Text;
        frm.Show();
    }
}
#endregion


3. Add the following line to the end of the Form2 constructor:
ShowFile(Form1.targetFileName);


4. Change the ids for "pb" in your last post to "pictureBox1".


5. Make sure you do a string.IsNullOrEmpty(Form1.targetFileName) before using targetFileName in your code... otherwise you might get an exception if the property is ever empty or null.


6. Make sure you add a "break;" after "pb.Controls.Add(tempPicturebox);" in your last post... otherwise, the loop will continue even after it's made the correct file match.


That should do it.
0
 
seahnaAuthor Commented:
Ok I am getting an error on the :

ShowFile(Form1.targetFileName);

Error Message:

'AV4._1_ClientTool.Dialogs1.Display.Map1' does not contain a definition for 'targetFileName'      

I know it does have it cause I can see it in my code any ideas on this one.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
is your targetFileName set to public?
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Should be...

public static string targetFileName {get; set;}
0
 
seahnaAuthor Commented:
Ok I switched it to public static ...I was missing the public but I am stilling the same error. Maybe I have that line of  code in the wrong place where were you wanting me to place it?
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
please post or send me the appropriate code?
0
 
seahnaAuthor Commented:
Here is what I have.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Security.Principal;
using System.Xml;


namespace AV4._1_ClientTool.Dialogs1.Display
{
    public partial class Map1 : Form
    {
        private double ZOOMFACTOR = 1.25;	// = 25% smaller or larger
        private int MINMAX = 5;				// 5 times bigger or smaller than the ctrl

        public Map1()
        {
            InitializeComponent();

            this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);


        }
        
        public void ShowFile(string targetFileName)
        {
            pictureBox1.Controls.Clear();
            foreach (var item in BusinessTier.IconFactory.ImageSet)
            {
                if (item.Image != targetFileName) continue;

                pictureBox1.Image = Image.FromFile(string.Format(@"{0}\{1}", item.Path, item.Image));
                foreach (var icon in item.Icons)
                {
                    var tempIcon = Image.FromFile(icon.File);
                    var tempPicturebox = new PictureBox
                    {
                        Image = tempIcon,
                        Location = new Point(icon.CoordinateX, icon.CoordinateY),
                        Size = new Size(tempIcon.Width, tempIcon.Height),
                    };
                    pictureBox1.Controls.Add(tempPicturebox);
                                       
                }
                break;
            }
        }
        
        
        string.IsNullOrEmpty(Map1.targetFileName);

        ShowFile(Map1.targetFileName);  

        #region Zooming Methods
        /// <summary>
        /// Make the PictureBox dimensions larger to effect the Zoom.
        /// </summary>
        /// <remarks>Maximum 5 times bigger</remarks>
        private void ZoomIn()
        {
            if ((pictureBox1.Width < (MINMAX * panel1.Width)) &&
                (pictureBox1.Height < (MINMAX * panel1.Height)))
            {
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * ZOOMFACTOR);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }

        /// <summary>
        /// Make the PictureBox dimensions smaller to effect the Zoom.
        /// </summary>
        /// <remarks>Minimum 5 times smaller</remarks>
        private void ZoomOut()
        {
            if ((pictureBox1.Width > (panel1.Width / MINMAX)) &&
                (pictureBox1.Height > (panel1.Height / MINMAX)))
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width / ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height / ZOOMFACTOR);
            }
        }

        #endregion

        #region Mouse Events
        private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                ZoomOut();
            }
            else
            {
                ZoomIn();
            }
        }
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            if (pictureBox1.Focused == false)
            {
                pictureBox1.Focus();
            }
        }
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.panel1.Focus(); // give the form focus instead
        }
        #endregion

        #region Button Events
        private void toolStripictureBox1utton1_Click(object sender, EventArgs e)
        {
            ZoomIn();
        }

        private void toolStripictureBox1utton2_Click(object sender, EventArgs e)
        {
            ZoomOut();
        }
        #endregion
    }

}

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Had to move and slightly switch around lines #57 and #59 above. Assuming everything is wired up correctly, this should work.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows;
using System.Security.Principal;
using System.Xml;


namespace AV4._1_ClientTool.Dialogs1.Display
{
    public partial class Map1 : Form
    {
        private double ZOOMFACTOR = 1.25;	// = 25% smaller or larger
        private int MINMAX = 5;		// 5 times bigger or smaller than the ctrl

        public Map1()
        {
            InitializeComponent();

            this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            if (!string.IsNullOrEmpty(Map1.targetFileName))
            {
                ShowFile(Map1.targetFileName);
            }
        }
        
        public void ShowFile(string targetFileName)
        {
            pictureBox1.Controls.Clear();
            foreach (var item in BusinessTier.IconFactory.ImageSet)
            {
                if (item.Image != targetFileName) continue;

                pictureBox1.Image = Image.FromFile(string.Format(@"{0}\{1}", item.Path, item.Image));
                foreach (var icon in item.Icons)
                {
                    var tempIcon = Image.FromFile(icon.File);
                    var tempPicturebox = new PictureBox
                    {
                        Image = tempIcon,
                        Location = new Point(icon.CoordinateX, icon.CoordinateY),
                        Size = new Size(tempIcon.Width, tempIcon.Height),
                    };
                    pictureBox1.Controls.Add(tempPicturebox);
                                       
                }
                break;
            }
        }

        #region Zooming Methods
        /// <summary>
        /// Make the PictureBox dimensions larger to effect the Zoom.
        /// </summary>
        /// <remarks>Maximum 5 times bigger</remarks>
        private void ZoomIn()
        {
            if ((pictureBox1.Width < (MINMAX * panel1.Width)) &&
                (pictureBox1.Height < (MINMAX * panel1.Height)))
            {
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * ZOOMFACTOR);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }

        /// <summary>
        /// Make the PictureBox dimensions smaller to effect the Zoom.
        /// </summary>
        /// <remarks>Minimum 5 times smaller</remarks>
        private void ZoomOut()
        {
            if ((pictureBox1.Width > (panel1.Width / MINMAX)) &&
                (pictureBox1.Height > (panel1.Height / MINMAX)))
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width / ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height / ZOOMFACTOR);
            }
        }

        #endregion

        #region Mouse Events
        private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                ZoomOut();
            }
            else
            {
                ZoomIn();
            }
        }
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            if (pictureBox1.Focused == false)
            {
                pictureBox1.Focus();
            }
        }
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.panel1.Focus(); // give the form focus instead
        }
        #endregion

        #region Button Events
        private void toolStripictureBox1utton1_Click(object sender, EventArgs e)
        {
            ZoomIn();
        }

        private void toolStripictureBox1utton2_Click(object sender, EventArgs e)
        {
            ZoomOut();
        }
        #endregion
    }
}

Open in new window

0
 
seahnaAuthor Commented:
ok this doesn't make since in line 29 and 31 I am getting an error with targetFileName saying:

Error 'AV4._1_ClientTool.Dialogs1.Display.Map1' does not contain a definition for 'targetFileName'

But in line 40 where it is also called I am not getting a error
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Well, it shouldn't be...

if (!string.IsNullOrEmpty(Map1.targetFileName))

... rather, it should be ...

if (!string.IsNullOrEmpty({Form1}.targetFileName))

... where {Form1} is the Id of the form that spawns the Map1 dialog.

Try that.

0
 
seahnaAuthor Commented:
Ok I think I got it or at least I didn't get an error there. I still have one more error to correct before it will run then I will let you know. thanks again.
0
 
seahnaAuthor Commented:
Ok got all my error fixed and went to run the code and got the following message inside your IconFactory.cs file on this line:

var rootPath = xml.SelectSingleNode(XPATH_DIRECTORY).InnerText.Trim();

Null reference Exception was unhandled.


Ideas?
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Make sure the value of XPATH_DIRECTORY matches the structure of your XML file. In the code I sent, it's expecting the following:

<Setup>
  <Options>
    <Maps>
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
      <!-- ... other stuff ... -->
    </Maps>
  </Options>
</Setup>

If your structure doesn't match this, or if there's nothing in the <MapDirectory> node then you'll get that error. Also, to head off an error you may get later, make sure the path listed in <MapDirectory> is valid and actually points to where your images are.
0
 
seahnaAuthor Commented:
Ok I fat fingered something so that works now but now there is another problem. The thumbnails show up great but when I click on them to show them in full view all i get is a blank second window. I am attaching the code so we can see how it looks now with all the changes for Form 1 and Form 2.
Form 1 Creates thumbnails
----------------------------------------------------------------------------

namespace AV4._1_ClientTool.Dialogs1.View
{
    public partial class Maps : Form
    {
        public Maps()
        {
            InitializeComponent();
        }

        //form global variables
        ImageList thumbs = new ImageList();
        Size ThumbSize = new Size(64, 64);
        PictureBox pb = new PictureBox();
        Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1();
        public static string targetFileName { get; set; }


        #region Thumbnails

        private void Maps_Load(object sender, EventArgs e)
        {
            thumbs.ImageSize = ThumbSize;
            thumbs.ColorDepth = ColorDepth.Depth32Bit;
            listView1.View = System.Windows.Forms.View.LargeIcon;
            listView1.LargeImageList = thumbs;
 
            string path = @"C:\Projects\AV4.1\Images";

            pb.Size = thumbs.ImageSize;
            pb.SizeMode = PictureBoxSizeMode.Zoom;
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(path);
            foreach (System.IO.FileInfo fi in di.GetFiles("*.jpg"))
            {
                Bitmap bmp = new Bitmap(pb.Width, pb.Height);
                pb.Image = Image.FromFile(fi.FullName);
                pb.DrawToBitmap(bmp, pb.ClientRectangle);
                thumbs.Images.Add(bmp);
                ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileNameWithoutExtension(fi.Name), thumbs.Images.Count - 1);
                lvi.Tag = fi.FullName;
                listView1.Items.Add(lvi);
            }
            foreach (System.IO.FileInfo fi in di.GetFiles("*.bmp"))
            {
                Bitmap bmp = new Bitmap(pb.Width, pb.Height);
                pb.Image = Image.FromFile(fi.FullName);
                pb.DrawToBitmap(bmp, pb.ClientRectangle);
                thumbs.Images.Add(bmp);
                ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileNameWithoutExtension(fi.Name), thumbs.Images.Count - 1);
                lvi.Tag = fi.FullName;
                listView1.Items.Add(lvi);
            }
        }
        #endregion

        #region Full Image Popup
        
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            Point pt = listView1.PointToClient(Cursor.Position);
            ListViewItem lvi = listView1.GetItemAt(pt.X, pt.Y);

            if (lvi != null)
            {
                targetFileName = (string)lvi.Tag;
                frm.Text = lvi.Text;
                frm.Show();
            }
        }

        #endregion

    }
}

Form 2 displays full image
----------------------------------------------------------------------------

namespace AV4._1_ClientTool.Dialogs1.Display
{
    public partial class Map1 : Form
    {
        private double ZOOMFACTOR = 1.25;	// = 25% smaller or larger
        private int MINMAX = 5;		// 5 times bigger or smaller than the ctrl

        public Map1()
        {
            InitializeComponent();

            this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            if (!string.IsNullOrEmpty(AV4._1_ClientTool.Dialogs1.View.Maps.targetFileName))
            {
                ShowFile(AV4._1_ClientTool.Dialogs1.View.Maps.targetFileName);
            }
        }

        public void ShowFile(string targetFileName)
        {
            pictureBox1.Controls.Clear();
            foreach (var item in BusinessTier.IconFactory.ImageSet)
            {
                if (item.Image != targetFileName) continue;

                pictureBox1.Image = Image.FromFile(string.Format(@"{0}\{1}", item.Path, item.Image));
                foreach (var icon in item.Icons)
                {
                    var tempIcon = Image.FromFile(icon.File);
                    var tempPicturebox = new PictureBox
                    {
                        Image = tempIcon,
                        Location = new Point(icon.CoordinateX, icon.CoordinateY),
                        Size = new Size(tempIcon.Width, tempIcon.Height),
                    };
                    pictureBox1.Controls.Add(tempPicturebox);

                }
                break;
            }
        }

        #region Zooming Methods
        /// <summary>
        /// Make the PictureBox dimensions larger to effect the Zoom.
        /// </summary>
        /// <remarks>Maximum 5 times bigger</remarks>
        private void ZoomIn()
        {
            if ((pictureBox1.Width < (MINMAX * panel1.Width)) &&
                (pictureBox1.Height < (MINMAX * panel1.Height)))
            {
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width * ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height * ZOOMFACTOR);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }
        }

        /// <summary>
        /// Make the PictureBox dimensions smaller to effect the Zoom.
        /// </summary>
        /// <remarks>Minimum 5 times smaller</remarks>
        private void ZoomOut()
        {
            if ((pictureBox1.Width > (panel1.Width / MINMAX)) &&
                (pictureBox1.Height > (panel1.Height / MINMAX)))
            {
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Width = Convert.ToInt32(pictureBox1.Width / ZOOMFACTOR);
                pictureBox1.Height = Convert.ToInt32(pictureBox1.Height / ZOOMFACTOR);
            }
        }

        #endregion

        #region Mouse Events
        private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                ZoomOut();
            }
            else
            {
                ZoomIn();
            }
        }
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            if (pictureBox1.Focused == false)
            {
                pictureBox1.Focus();
            }
        }
        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            this.panel1.Focus(); // give the form focus instead
        }
        #endregion

        #region Button Events
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ZoomIn();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            ZoomOut();
        }
        #endregion
    }
}

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
When you debug this, is there anything in targetFileName? You want to verify this in two places...

1. AFTER you initially set the value in AV4._1_ClientTool.Dialogs1.View.Maps

2. BEFORE you try to use the value in AV4._1_ClientTool.Dialogs1.Display.Map1

Also, you need to make sure that the value of targetFileName EXACTLY matches the <FileName> node of the entry you're expecting, right on down to the whitespace. A single space in either the XML or the variable value could cause these not to match up. If there's no match then you're going to get a blank form on Map1.
0
 
seahnaAuthor Commented:
As far as I can tell this is all correct unless I am doing something wrong which is possible since I am still learning.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Without having all the necessary code exactly as you have may cause me to suggest the wrong thing.

Not to nag you -- :) -- but have you tried to debug it yet? Breakpoints could reveal volumes.

I think I see the problem though... in the example that I sent you the other day, the file extensions are INCLUDED in the mappings.xml file. In your most recent post with code, I believe that you are EXCLUDING the file extension where you set the ListViewItem Tag property with this line...

ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileNameWITHOUTExtension(fi.Name), thumbs.Images.Count - 1);

... and if you didn't take that into consideration then targetFileName probably won't match anything in mappings.xml when Map1 is spawned. It doesn't matter which way you decide to go, but make sure they match or you'll have unexpected behavior.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
And don't worry about "still learning"... a colleague of mine showed me something I should've learned a long time ago on Friday.  :)
0
 
seahnaAuthor Commented:
Its ok you not nagging me...Yes I have ran the debugger and it ran great without errors and I even placed break point and it still works great. I double check my XML code and everything look fine to me. below is the full XML doc for my project since you think my error might be here. Let me know.
<Setup>
  <Logins>
    <Login>
      <ID>admin</ID>
      <PW>admin</PW>
    </Login>
    <Login>
      <ID>user</ID>
      <PW>user</PW>
    </Login>
  </Logins>
  
  <Language>
    <English>file location here</English>
    <French>file location here</French>
    <Norwegian>file location here</Norwegian>
  </Language>

  <Options>
    <Maps>
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
      <Map>
        <FileName>Testing image.bmp</FileName>
        <Icons>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>250,175</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>270,175</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>230,175</Location>
          </Icon>
        </Icons>
      </Map>
    </Maps>
  </Options>
  
  <ACSP>
    <Primary>
      <IPAddress>10.5.105.47</IPAddress>
      <IPPort>61112</IPPort>
      <ConfigurationPath>C:\Projects\AV4.1\DefaultConfig.xml</ConfigurationPath>
    </Primary>
  </ACSP>
</Setup>

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
<Maps>
     <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
     <Map>
          <FileName>Testing image.BMP</FileName>   <~~~ as near as I can tell the problem is right here... you're still including the file extension, which I've made all CAPS.
          <!-- I left the other stuff out for clarity -->
     </Map>
</Maps>
0
 
seahnaAuthor Commented:
ok now I am a little confused in the project example you sent me you said the extention was left out in the mapping.xml doc but I just looked at it and it is still there.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Nope, to quote:

     "... in the example that I sent you the other day, the file extensions are INCLUDED in the mappings.xml file. ..."

You have two lines of code that are explicitly EXCLUDING the file extension of your image files when you set the ListViewItem Tag property for each thumbnail. I've included it below, look for the part that's in all CAPS:

     ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileNameWITHOUTExtension(fi.Name), thumbs.Images.Count - 1);

See what I mean?
0
 
seahnaAuthor Commented:
I see what you mean but I thought that line only displayed the name of the file in the thumbnail screen. Because when I changed that I still don't get an image in the second window but the displayed name in the thumbnail screen changes.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
My bad! I was pointing out the wrong line, function call, and string matching attempt!  ;)

I was right, however, that the strings you're trying to compare aren't going to match up... please skim the following on MSDN: http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.fullname.aspx . Don't worry about understanding it; I just want you to see that I'm not pulling this out of my... wherevever.  :)

In your last C# code post, this line (that is in two places in .View.Maps)...

     lvi.Tag = fi.FullName;

... is equivalent to the following based on where your image "Testing image.bmp" lives:

     lvi.Tag = "C:\Projects\AV4.1\Images\Testing image.bmp";

... this is NOT the same as...

     lvi.Tag = "Testing image.bmp";

... and this is why it's not finding a match in mappings.xml. You should use this instead:

     lvi.Tag = fi.Name;

Sorry about that bit on the file extension. Right rabbit trail, wrong hole.  :)
0
 
seahnaAuthor Commented:
Ok I understand what you are saying I believe. I am using this line of code:

lvi.Tag = fi.FullName;

and I need to use this line:

lvi.Tag = fi.Name;

...

If I understand you correctly I did this but I am still not getting anything on the second window.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
ok, can you zip those two classes and email them to me? That will help.
0
 
seahnaAuthor Commented:
Ok I will email you those two forms and send them to you.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Using your code as a base I got it working. Now that I see those two entire classes we need to switch a few strategies.

Steps:
1. In the Program.cs file, make sure the followings lines appear in the order specified ...

     BusinessTier.IconFactory.PopulateControls(WHATEVER PATH YOU HAVE HERE);
     Application.Run(new Dialogs1.View.Maps());  // or whatever form this actually points to.

... otherwise the list of images might not be read into memory until AFTER the main form CLOSES.


2. In the Maps.cs file, delete the following two lines:

     Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1() ;
     public static string targetFileName {get; set;}

* we're deleting these because this strategy won't work properly with your current code.


3. In the Maps.cs file, add the following line as the first line inside your "if (lvi != null)" statement (inside your double-click method):

     Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1((string)lvi.Tag) ;


4. In the Maps.cs file, delete the following line:

     targetFileName = (string)lvi.Tag;

* we don't need this anymore either.


5. In the Map1.cs file, modify the Map1 constructor signature as follows:

     public Map1(string targetFileName)
     {
          InitializeComponent();

          this.pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

          if (!string.IsNullOrEmpty(targetFileName))
          {
               ShowFile(targetFileName);
          }
     }

Every thing else *should* be able to run the way that you have it.
0
 
seahnaAuthor Commented:
I have good news and bad. You corrected another error I was having that if you close the Map1 window you couldn't open it again...with what you did I can now....So there is a good...However I am still not getting the image to show in full view. I am so sorry. Could I be missing anything else?
0
 
seahnaAuthor Commented:
Oh I forgot to tell you one thing you told me to put this line as the first one:

Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1((string)lvi.Tag) ;

I couldn't it gave me an error saying I couldn't use a variable before it was declared. so I had to do it as I did in the code I have attached.
private void listView1_DoubleClick(object sender, EventArgs e)
        {
            Point pt = listView1.PointToClient(Cursor.Position);
            ListViewItem lvi = listView1.GetItemAt(pt.X, pt.Y);
            Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1((string)lvi.Tag);
            
            if (lvi != null)
            {
                frm.Text = lvi.Text;
                frm.Show();
            }
        }

Open in new window

0
 
seahnaAuthor Commented:
Hey I got an idea not sure if it will work but it might...

in this line of code it is reading the image from a file direcotry:

string path = @"C:\Projects\AV4.1\Images";

Well to be honest I don't want this hard coded because this directory is eventually going to be editable by the user when I am completely done with my application. Well my idea is one of two things one can this be read from the XML file and then displayed to the thumbnail and would this possible solve some of our problems? I mean we are already calling the directory spot in the XML file here:

<Setup>
  <Options>
    <Maps>
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
      <!-- ... other stuff ... -->
    </Maps>
  </Options>
</Setup>

And have it display the thumbnails from this file?


My other thought gets rid of this intierly I am just not sure it will work or how it will work. Ok the XML file is going to have the image files listed already. Could we just tell the application to create the thumbnails off that information? Granted we would still have to store the directory of where the files were saved and by doing this the thumbnail would be loaded with the icon locations.

I think it would be something along the line of telling the application to load blank image files with blah icons in these places from this directory as thumbnails then when double clickedopen full size.


Just  a thought let me know what you think.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
No problem; I did tell you to put the "frm" code inside the "if" statement, but that's no big deal at all... you got it right on your own, and that's what counts. I do think it is a good idea to put the files directory in the XML file... to be honest, that's how I normally do it anyway (in some type of configuration file, I mean).

Did you complete the updates to Map1.cs? The change to the signature is necessary, as well as the place where it's looking for the value to use in ShowForm().

If you want, you can zip up the entire project and email it to me. I can make the necessary updates and get it back to you relatively quickly tonight. Your call, but let me know soon.  :)
0
 
seahnaAuthor Commented:
Ok I am sorry about the "if" statement I missed that completely. Ok the project file is very large so I will either have to send it to you in parts or send the major portion to you.
0
 
seahnaAuthor Commented:
I sent you an e-mail with a link to where I upload the full project to.  here it is as well:

http://www.4shared.com/file/190768406/654a4f66/AV41.html

You'll have to look at the e-mail for the password to open it though.
0
 
seahnaAuthor Commented:
Something I noticed in the code you gave me the icons and image have to be in the same folder is it possible to adjust this so that the icons are in a subdirectory of the image foler. Say by adding this to the XML file
<Setup>
  <Options>
    <Maps>
      <other stuff>
      <Icons>
        <IconDirectory>C:\Projects\AV4.1\Images\Icons</IconDirectory>
      </Icons>
     <otherstuff>
  </Options>
</Setup>
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
yes, that is possible, but you'll need to modify the method that parses the XML and the one that maps the icons accordingly.
0
 
seahnaAuthor Commented:
Ok so in IconFactory.cs file if I am understanding you code correctly I would look something like this maybe...However I know I am not completely correct cause it is causing an error.
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace BusinessTier
{
    public class IconFactory
    {
        public readonly static List<ImageItem> ImageSet = new List<ImageItem>();
        private const string MapPATH_DIRECTORY = @"Setup/Options/Maps/MapDirectory";
        private const string MapPath = @"Setup/Options/Maps/Map";

        private const string IconPATH_DIRECTORY = @"Setup/options/Maps/IconDirectory";
        private const string IconPath = @"Setup/Options/Maps/Map/Icons/Icon";

        public static void PopulateIconSet(string targetMap)
        {
            using (var stream = new StreamReader(targetMap))
            {
                var xml = new XmlDocument();
                xml.Load(stream);

                if (xml.ChildNodes.Count > 0)
                    ImageSet.Clear();

                var rootPath = xml.SelectSingleNode(MapPATH_DIRECTORY).InnerText.Trim();
                if (xml.SelectSingleNode(MapPath) == null) return;


                var rootPath2 = xml.SelectSingleNode(IconPATH_DIRECTORY).InnerText.Trim();
                if (xml.SelectSingleNode(IconPath) == null) return;


                foreach (var node in xml.SelectNodes(MapPath))
                {
                    var map = (XmlNode)node;
                    if (map.ChildNodes.Count <= 0) continue;

                    var imageObj = new ImageItem();
                    foreach (var image in xml.SelectNodes(IconPath))
                    {
                        var itemNode = (XmlNode)image;

                        switch (itemNode.Name)
                        {
                            case "FileName":
                                imageObj.Image = itemNode.InnerText;
                                imageObj.Path = rootPath;
                                imageObj.Icons = new List<IconItem>();
                                break;

                            case "Icons":
                                foreach (var icon in itemNode.ChildNodes)
                                {
                                    var iconObj = new IconItem();
                                    var iconNode = (XmlNode)icon;

                                    iconObj.File = string.Format(@"{0}\{1}", rootPath, iconNode["FileName"].InnerText);
                                    var cX = default(int);
                                    var cY = default(int);

                                    var coordinates = iconNode["Location"].InnerText.Trim().Split(',');

                                    int.TryParse(coordinates[0], out cX);
                                    int.TryParse(coordinates[1], out cY);

                                    iconObj.CoordinateX = cX;
                                    iconObj.CoordinateY = cY;

                                    imageObj.Icons.Add(iconObj);
                                }
                                break;
                        }
                    }
                    ImageSet.Add(imageObj);
                }
            }
        }

        public static string GetImageName(int index)
        {
            return index < ImageSet.Count ? ImageSet[index].Image : string.Empty;
        }
    }
}

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
It sounds to me like this XPath location...

        private const string IconPath = @"Setup/Options/Maps/Map/Icons/Icon";

... doesn't match up with the XML you specified...

<Setup>
  <Options>
    <Maps>
      <other stuff>
      <Icons>
        <IconDirectory>C:\Projects\AV4.1\Images\Icons</IconDirectory>
      </Icons>
     <otherstuff>
  </Options>
</Setup>

... if the XML is as I have posted here, the XPath location should be...

        private const string IconPath = @"Setup/Options/Maps/Icons/IconDirectory";

You may have removed a few nodes in the XML I posted above. Just make sure that the path to the <IconDirectory> node is valid in the IconPath variable.
0
 
seahnaAuthor Commented:
I am trying to make the adjustment in your demo code you sent to see how it will work before I play with it in my code for the sub-directory:

ok the exception I am getting is in this line inside the Form1.cs:

                pb.Image = Image.FromFile(string.Format(@"{0}\{1}", item.Path, item.Image));

file not found Exception \

I adjusted the XML a little and attached it and the IconFactory.cs tha tI now have.
using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace BusinessTier
{
    public class IconFactory
    {
        public readonly static List<ImageItem> ImageSet = new List<ImageItem>();
        private const string MapPATH_DIRECTORY = @"Setup/Options/Maps/MapDirectory";
        private const string MapPath = @"Setup/Options/Maps/Map";

        private const string IconPATH_DIRECTORY = @"Setup/Options/Maps/IconDirectory";
        private const string IconPath = @"Setup/Options/Maps/Map/Icons/Icon";

        public static void PopulateIconSet(string targetMap)
        {
            using (var stream = new StreamReader(targetMap))
            {
                var xml = new XmlDocument();
                xml.Load(stream);

                if (xml.ChildNodes.Count > 0)
                    ImageSet.Clear();

                var rootPath = xml.SelectSingleNode(MapPATH_DIRECTORY).InnerText.Trim();
                if (xml.SelectSingleNode(MapPath) == null) return;


                var rootPath2 = xml.SelectSingleNode(IconPATH_DIRECTORY).InnerText.Trim();
                if (xml.SelectSingleNode(IconPath) == null) return;


                foreach (var node in xml.SelectNodes(MapPath))
                {
                    var map = (XmlNode)node;
                    if (map.ChildNodes.Count <= 0) continue;

                    var imageObj = new ImageItem();
                    foreach (var image in xml.SelectNodes(IconPath))
                    {
                        var itemNode = (XmlNode)image;

                        switch (itemNode.Name)
                        {
                            case "FileName":
                                imageObj.Image = itemNode.InnerText;
                                imageObj.Path = rootPath;
                                imageObj.Icons = new List<IconItem>();
                                break;

                            case "Icons":
                                foreach (var icon in itemNode.ChildNodes)
                                {
                                    var iconObj = new IconItem();
                                    var iconNode = (XmlNode)icon;

                                    iconObj.File = string.Format(@"{0}\{1}", rootPath, iconNode["FileName"].InnerText);
                                    var cX = default(int);
                                    var cY = default(int);

                                    var coordinates = iconNode["Location"].InnerText.Trim().Split(',');

                                    int.TryParse(coordinates[0], out cX);
                                    int.TryParse(coordinates[1], out cY);

                                    iconObj.CoordinateX = cX;
                                    iconObj.CoordinateY = cY;

                                    imageObj.Icons.Add(iconObj);
                                }
                                break;
                        }
                    }
                    ImageSet.Add(imageObj);
                }
            }
        }

        public static string GetImageName(int index)
        {
            return index < ImageSet.Count ? ImageSet[index].Image : string.Empty;
        }
    }
}

XML

<?xml version="1.0" encoding="utf-8"?>
<Setup>
  <Options>
    <Maps>
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory>
      <IconDirectory>C:\Projects\AV4.1\Images</IconDirectory>
      <Map>
        <FileName>Testing image.jpg</FileName>
        <Icons>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>866,451</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>520,286</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>352,425</Location>
          </Icon>
        </Icons>
      </Map>
      <Map>
        <FileName>Test image 2.jpg</FileName>
        <Icons>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>250,175</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>270,175</Location>
          </Icon>
          <Icon>
            <FileName>icon idle.bmp</FileName>
            <Location>230,175</Location>
          </Icon>
        </Icons>
      </Map>
    </Maps>
  </Options>
</Setup>

Open in new window

0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Glancing at your code it appears that you're looking for the icon files in the maps directory. Based on the XML in your last post I assume this is what you're expecting, but we definitely want to eliminate this bug now before it becomes a problem...

     iconObj.File = string.Format(@"{0}\{1}", rootPath, iconNode["FileName"].InnerText); // <~ "rootPath" should be "rootPath2"

Can you please upload this updated version? That way I'll be able to include this in my review.
0
 
seahnaAuthor Commented:
Not a problem I have it uploaded again and the password is the same.

http://www.4shared.com/dir/18010998/929b7f2c/sharing.html
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
As I thought, it was some kind of pathing issue between when I originally gave you my demo code and what is now in the DefaultConfigs.xml file. No big deal.

Believe it or not the rest of your code (for the mapping part we've been dealing with) is sound.

Check your email in a moment for the changes document. All you need to do is replace the method specified in the document with the one I've pasted into the document, and you should be cooking with gas.
0
 
seahnaAuthor Commented:
Ok I have good news and some not so good news. I copied your code over and I got the application to run the only problem I is now is I could only get one image to populate in full view. They all showed in the thumbnails and I double clicked on them and the second window showed up and two of the images where blank and the third one actually show and the zooming function worked but I couldnt pan the image. And the icons didnt zoom in and out with the image. I am going to keep looking at it to see if I can figure out what is going wrong. Thanks you though for all of your help.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
Don't forget that you're populating the thumbnails list from a directory read, not the configuration file. Make sure the images you expect to see are in the cinfiguration file. Only two maps were listed in there, and only one actually existed in your Maps folder.

For the image manipulation are you sure the handlers are attached to the proper objects? You should check there first. Also, regarding the icons, I assume you'll want to apply the same transformation to each icon that you're applying to the parent object.
0
 
seahnaAuthor Commented:
As far as the zooming goes I want the icons to zoom the same as the image and stay in the location they were placed at.
0
 
seahnaAuthor Commented:
Oh and I figured out why it didn't display the other image the name of it in the XML was slightly off.
0
 
Kelvin McDanielSr. Developer/ConsultantCommented:
:) Good job!

1. As of right now the icons have nothing acting on them... you need to also increase their size when you zoom. It's pretty easy to iterate over pictureBox1.Controls, look for any that are PictureBox, and zoom them when you zoome pictureBox1.

2. As I recall the pan wasn't implemented yet... and I don't see any code in anything you've provided that actually "pans". The definition I understand is to shift along a 2-D plane... left, right, up, down, or diagonal. You'll probably want this to occur on one of the Drag() events for the Map pictureBox control. Other than suggestions I'm not going to be much help there.

I'm at a point where I probably won't be of much further help to you... as what you're trying to do now (to do it well, anyway) would require quite a bit of research and testing on my part.
0
 
seahnaAuthor Commented:
That is fine I tahkn you for your help and if I  could I would grant you more points you have been a big help to me with all that you have done. Thanks  bunch!
0
 
seahnaAuthor Commented:
This was of great help to me. the Expert I worked with actually deserves a lot more points then I could give him. He was of great help to me.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 34
  • 29
Tackle projects and never again get stuck behind a technical roadblock.
Join Now