Click here to Skip to main content
15,887,385 members
Home / Discussions / C#
   

C#

 
AnswerRe: Remove all characters in a string up to and including a specified pattern Pin
PIEBALDconsult2-Feb-10 5:31
mvePIEBALDconsult2-Feb-10 5:31 
AnswerRe: Remove all characters in a string up to and including a specified pattern Pin
sanforjackass2-Feb-10 5:33
sanforjackass2-Feb-10 5:33 
GeneralRe: Remove all characters in a string up to and including a specified pattern Pin
OriginalGriff2-Feb-10 5:42
mveOriginalGriff2-Feb-10 5:42 
AnswerRe: Remove all characters in a string up to and including a specified pattern Pin
OkkiePepernoot2-Feb-10 6:01
OkkiePepernoot2-Feb-10 6:01 
GeneralRe: Remove all characters in a string up to and including a specified pattern Pin
MarkB1232-Feb-10 8:28
MarkB1232-Feb-10 8:28 
AnswerRe: Remove all characters in a string up to and including a specified pattern Pin
Ramkithepower3-Feb-10 1:38
Ramkithepower3-Feb-10 1:38 
GeneralRe: Remove all characters in a string up to and including a specified pattern Pin
MarkB1233-Feb-10 11:37
MarkB1233-Feb-10 11:37 
Questionzooming/panning Pin
sarai002-Feb-10 5:24
sarai002-Feb-10 5:24 
I'm creating a security application that is using WinForms it reads in am image from an XML and displays that image in a Thumbnail format. Then when the image is double click it is populated in a second window with icon image representing specific security devices. In the second window I need to be able to zoom and pan the image along with the icon displayed over top the image.. Right now when I go to zoom the main image is the only thing that zooms but it doesn't not pan. I need to be able to make the icons zoom with the image and make the whole thing pan accordingly. Any help with this would be great. Keep in mind that the main map image I can zoom and pan my problem is when I move the mouse off the scroll bar the image doesn't stay where I panned it to.

Additional Note: Not sure how much information you will need to help so I attached the code from both Forms in the zip file along with the XML code below that stores the information about the images and the icons. Please let me know what other information you might need to assist me.

Form 1
---------------------------------------------------------------
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.View
{
public partial class Maps : Form
{
public Maps()
{
InitializeComponent();
}

//form global variables
ImageList thumbs = new ImageList();
Size ThumbSize = new Size(64, 64);
PictureBox pictureBox1 = new PictureBox();

#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";

pictureBox1.Size = thumbs.ImageSize;
pictureBox1.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(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = Image.FromFile(fi.FullName);
pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
thumbs.Images.Add(bmp);
ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileName(fi.Name), thumbs.Images.Count - 1);
lvi.Tag = fi.Name;
listView1.Items.Add(lvi);
}
foreach (System.IO.FileInfo fi in di.GetFiles("*.gif"))
{
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = Image.FromFile(fi.FullName);
pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
thumbs.Images.Add(bmp);
ListViewItem lvi = new ListViewItem(System.IO.Path.GetFileName(fi.Name), thumbs.Images.Count - 1);
lvi.Tag = fi.Name;
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);
Dialogs1.Display.Map1 frm = new Dialogs1.Display.Map1((string)lvi.Tag);

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

#endregion

}
}
-------------------------------------------------------------
Form 2
-------------------------------------------------------------
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(string targetFileName)
{
InitializeComponent();

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

if (!string.IsNullOrEmpty(targetFileName))
{
ShowFile(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
}
}
-----------------------------------------------------------------------
XML
-----------------------------------------------------------------------
<Setup><br />
  <Options><br />
    <Maps><br />
      <MapDirectory>C:\Projects\AV4.1\Images</MapDirectory><br />
      <IconDirectory>C:\Projects\AV4.1\Images\Icons</IconDirectory><br />
      <Map><br />
        <FileName>Test image 1.jpg</FileName><br />
        <Icons><br />
          <Icon><br />
            <FileName>icon idle.bmp</FileName><br />
            <Location>250,175</Location><br />
          </Icon><br />
          <Icon><br />
            <FileName>icon idle.bmp</FileName><br />
            <Location>270,175</Location><br />
          </Icon><br />
          <Icon><br />
            <FileName>icon idle.bmp</FileName><br />
            <Location>230,175</Location><br />
          </Icon><br />
        </Icons><br />
      </Map><br />
      <Map><br />
        <FileName>Test image 2.jpg</FileName><br />
        <Icons><br />
          <Icon><br />
            <FileName>icon idle.bmp</FileName><br />
            <Location>250,175</Location><br />
          </Icon><br />
          <Icon><br />
            <FileName>icon idle.bmp</FileName><br />
            <Location>270,175</Location><br />
          </Icon><br />
          <Icon><br />
            <FileName>icon idle.bmp</FileName><br />
            <Location>230,175</Location><br />
          </Icon><br />
        </Icons><br />
      </Map><br />
    </Maps><br />
  </Options><br />
</Setup>

QuestionC# Create Excelfile Pin
Mschauder2-Feb-10 3:26
Mschauder2-Feb-10 3:26 
AnswerRe: C# Create Excelfile Pin
The Man from U.N.C.L.E.2-Feb-10 3:40
The Man from U.N.C.L.E.2-Feb-10 3:40 
QuestionGmail Samples Pin
Anil Kumar.Arvapalli2-Feb-10 3:17
Anil Kumar.Arvapalli2-Feb-10 3:17 
AnswerRe: Gmail Samples Pin
WoutL2-Feb-10 3:23
WoutL2-Feb-10 3:23 
AnswerRe: Gmail Samples Pin
Abhinav S2-Feb-10 3:44
Abhinav S2-Feb-10 3:44 
QuestionTrouble with drawing on winfrom in new thread Pin
Frozzeg2-Feb-10 2:45
Frozzeg2-Feb-10 2:45 
AnswerRe: Trouble with drawing on winfrom in new thread Pin
Luc Pattyn2-Feb-10 3:29
sitebuilderLuc Pattyn2-Feb-10 3:29 
AnswerRe: Trouble with drawing on winfrom in new thread Pin
The Man from U.N.C.L.E.2-Feb-10 3:52
The Man from U.N.C.L.E.2-Feb-10 3:52 
GeneralRe: Trouble with drawing on winfrom in new thread Pin
Frozzeg2-Feb-10 8:00
Frozzeg2-Feb-10 8:00 
GeneralRe: Trouble with drawing on winfrom in new thread Pin
Dave Kreskowiak2-Feb-10 8:53
mveDave Kreskowiak2-Feb-10 8:53 
QuestionComboBox index Databind Pin
Kaikus2-Feb-10 2:22
Kaikus2-Feb-10 2:22 
AnswerRe: ComboBox index Databind Pin
The Man from U.N.C.L.E.2-Feb-10 4:01
The Man from U.N.C.L.E.2-Feb-10 4:01 
Question.NET applications? Pin
ppayal2-Feb-10 0:12
ppayal2-Feb-10 0:12 
AnswerRe: .NET applications? Pin
OriginalGriff2-Feb-10 0:19
mveOriginalGriff2-Feb-10 0:19 
AnswerRe: .NET applications? Pin
Keith Barrow2-Feb-10 0:19
professionalKeith Barrow2-Feb-10 0:19 
GeneralRe: .NET applications? Pin
OriginalGriff2-Feb-10 0:32
mveOriginalGriff2-Feb-10 0:32 
GeneralRe: .NET applications? Pin
Daniel Grunwald2-Feb-10 1:37
Daniel Grunwald2-Feb-10 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.