Pasted the code below
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.IO;
using System.Xml;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DoubleBuffered = true;
}
public ArrayList goZones = null;
public int a, b, c, d, k, n1, n2, n3, panelpostion;
public int zoomminwidth, zoommaxwidth, zoomminheight, zoommaxheight;
bool f, g2 = false, g3 = false, panelflag = true, initialimage = true;
private PosSizableRect nodeSelected = PosSizableRect.None;
Bitmap mybitmap;
Screen svc;
Point w;
string file = "";
Size sz1, sz;
Graphics g;
Image image, image1;
Rectangle rect, rect1, rect2;
public static List<Rectangle> rectangles = new List<Rectangle>();
public static List<string> lab = new List<string>();
private enum PosSizableRect
{
UpMiddle,
LeftMiddle,
LeftBottom,
LeftUp,
RightUp,
RightMiddle,
RightBottom,
BottomMiddle,
None
};
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFD.FileName = "";
OpenFD.Title = "open image";
OpenFD.InitialDirectory = "C";
OpenFD.Filter = "JPEG|*.jpg|Bmp|*.bmp|All Files|*.*.*";
if (OpenFD.ShowDialog() == DialogResult.OK)
{
file = OpenFD.FileName;
image1= image = Image.FromFile(file);
sz1.Width = 800;
sz1.Height = 650;
svc = Screen.PrimaryScreen;
image= resizeimage(image, sz1);
sz1 = image.Size;
panelflag = true;
zoominToolStripMenuItem1.Checked = false;
zoomOutToolStripMenuItem1.Checked = false;
deleteToolStripMenuItem.Checked = false;
label1.Text = "";
rectangles.Clear();
lab.Clear();
f = true;
n3 = n2 = 0;
mybitmap = null;
label1.Visible = false;
zoomborder(panel1.Width);
}
}
private Image resizeimage(Image my, Size sz1)
{
double ratio = 0d;
double myThumbWidth = 0d;
double myThumbHeight = 0d;
Bitmap bp;
if ((my.Width / Convert.ToDouble(sz1.Width)) > (my.Height /
Convert.ToDouble(sz1.Height)))
ratio = Convert.ToDouble(my.Width) / Convert.ToDouble(sz1.Width);
else
ratio = Convert.ToDouble(my.Height -10) / Convert.ToDouble(sz1.Height);
myThumbHeight = Math.Ceiling(my.Height / ratio);
myThumbWidth = Math.Ceiling(my.Width / ratio);
Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
sz.Width = svc.Bounds.Width;
sz.Height = svc.Bounds.Height;
rect2 = rect = new Rectangle(0, 0, thumbSize.Width, sz.Height-120);
panelpostion= Convert.ToInt16((sz.Width -10) /3.5);
k = rect.Width + panelpostion; n1 = rect.Height;
bp = new Bitmap(sz.Width-10, rect.Height);
bp.SetResolution(300, 300);
g = Graphics.FromImage(bp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(my, rect, 0, 0, my.Width, my.Height, GraphicsUnit.Pixel);
if (f == false)
{
panel1.Size=sz=sz1 = bp.Size ;
XmlDocument oDOM = new XmlDocument();
string str2 = Path.GetFileNameWithoutExtension(file) + ".xml";
oDOM = null;
if(!(File.Exists(str2)))
{
string str1 = Path.GetFileNameWithoutExtension(file);
StreamWriter Recta = new StreamWriter(Path.GetDirectoryName(str1) + str1 + ".xml");
Recta.WriteLine("<xml>");
Recta.WriteLine("<screen>");
Recta.WriteLine("<X>" + rect2.X.ToString() + "</X>");
Recta.WriteLine("<Y>" + rect2.Y.ToString() + "</Y>");
Recta.WriteLine("<Width>" + rect2.Width.ToString() + "</Width>");
Recta.WriteLine("<height>" + rect2.Height.ToString() + "</height>");
Recta.WriteLine("</screen>");
Recta.WriteLine("</xml>");
Recta.Close();
}
}
rect = new Rectangle(0, 0, 0, 0);
return (bp);
}
private void zoominToolStripMenuItem1_Click(object sender, EventArgs e)
{
zoominfunction();
}
private void zoomOutToolStripMenuItem1_Click(object sender, EventArgs e)
{
zoomoutfunction();
}
private void zoominfunction()
{
if (file == "")
MessageBox.Show("Open a file");
else
{
zoominToolStripMenuItem1.Checked = true;
zoomOutToolStripMenuItem1.Checked = false;
shortcut();
}
}
private void zoomoutfunction()
{
if (file == "")
MessageBox.Show("Open a file");
else
{
zoominToolStripMenuItem1.Checked = false;
zoomOutToolStripMenuItem1.Checked = true;
shortcut();
}
}
private void shortcut()
{
if (zoominToolStripMenuItem1.Checked == true)
ZoomIn();
else if (zoomOutToolStripMenuItem1.Checked == true)
ZoomOut();
}
public void ZoomIn()
{
double ratio = 0d;
double ratio1 = 0d;
if (sz1.Width >= Convert.ToInt16(sz.Width*3.8))
MessageBox.Show("Max ZoomIn");
else
{
sz1.Width += 50;
sz1.Height += 50;
ratio = Convert.ToDouble(sz1.Width) / Convert.ToDouble(panel1.Width);
ratio1 = Convert.ToDouble(sz1.Height) / Convert.ToDouble(panel1.Height);
panel1.Size = sz1;
panelpostion = panelpostion - 5;
for (c = 0; c <= (rectangles.Count - 1); c++)
{
if (rectangles[c].Y>=0 && rectangles[c].Y<=20)
rect1.Y = rectangles[c].Y;
else if (rectangles[c].Y >=20 && rectangles[c].Y <= 100)
rect1.Y = rectangles[c].Y+2;
rect1.X = rectangles[c].X-5;
rect1.Width = Convert.ToInt16(Convert.ToDouble(rectangles[c].Width) * ratio);
rect1.Height = Convert.ToInt16((Convert.ToDouble(rectangles[c].Height) * ratio));
rectangles.RemoveAt(c);
rectangles.Insert(c, rect1);
}
}
panel1.Invalidate();
}
public void ZoomOut()
{
if (sz.Height == sz1.Height)
MessageBox.Show("Max ZoomIn");
else
{
sz1.Width -= 50;
sz1.Height -= 50;
panel1.Size = sz1;
panelpostion = panelpostion + 5;
}
panel1.Invalidate();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (file == "")
return;
if (mybitmap == null)
{
return;
}
using (g = Graphics.FromImage(mybitmap))
{
e.Graphics.DrawImage(image, new Rectangle(panelpostion, 0, panel1.Width, panel1.Height));
using (Pen pen = new Pen(Color.Green, 3))
{
paintworks();
if (f == true)
{
f = false;
pen.Color = Color.Red;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
c = 0;
foreach (Rectangle r in rectangles)
{
e.Graphics.DrawRectangle(pen, r);
e.Graphics.DrawString(lab[c].ToString(), new Font(lab[c].ToString(), 8F), new SolidBrush(label1.ForeColor), r);
c++;
}
pen.Color = Color.Green;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(pen, rect);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
foreach (PosSizableRect pos in Enum.GetValues(typeof(PosSizableRect)))
{
e.Graphics.DrawRectangle(pen, GetRect(pos));
}
}
else
{
pen.Color = Color.Red;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.DrawRectangle(pen, rect);
c = 0;
foreach (Rectangle r in rectangles)
{
e.Graphics.DrawRectangle(pen, r);
e.Graphics.DrawString(lab[c].ToString(), new Font(lab[c].ToString(), 8F), new SolidBrush(label1.ForeColor), r);
c++;
}
}
}
}
return;
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (file == "")
return;
zoomborder(panel1.Width);
contextMenuStrip1.Visible = false;
if (rectangles.Count != 0)
{
f = false;
elocation(w);
d = c;
if (f == true)
{
rect = new Rectangle(rectangles[d].X, rectangles[d].Y, rectangles[d].Width, rectangles[d].Height);
f = false;
g3 = true;
g2 = true;
}
else
{
g2 = false;
}
}
else
g2 = false;
if (mybitmap == null)
{
mybitmap = new Bitmap(panel1.Width, panel1.Height);
mybitmap.SetResolution(300, 300);
}
if (g2 == true)
{
nodeSelected = PosSizableRect.None;
nodeSelected = GetNodeSelectable(e.Location);
a = e.X;
b = e.Y;
}
else
{
rect = new Rectangle(e.X, e.Y, 0, 0);
g3 = false;
}
panel1.Invalidate();
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (file == "")
return;
panel1.Cursor = GetCursor(GetNodeSelectable(w = e.Location));
if (mybitmap == null)
{
loadxml();
}
if (e.Button == MouseButtons.Left)
{
if (g2 == false)
{
c = -1;
f = false;
elocation(w);
if (f == true)
{
if (g3 == false)
f = false;
}
if (f == true)
{
rect = new Rectangle(e.X, e.Y, rectangles[c].Width, rectangles[c].Height);
rectangles.RemoveAt(c);
rectangles.Insert(c, rect);
f = false;
}
else
{
if (rect.X + rect.Width >= zoommaxwidth || rect.Y + rect.Height >= zoommaxheight || e.X >= zoommaxwidth + 50 || e.Y >= zoommaxheight + 50)
{
borderrectangle(w);
}
else
{
f = false;
cond();
if (f == true)
{
MessageBox.Show("Cannot draw Rectangle over another Rectangle", "Warning");
f = false;
rect = new Rectangle(0, 0, 0, 0);
}
else
{
if (!(rect.Left == 0 || rect.Top == 0))
rect = new Rectangle(rect.Left, rect.Top, e.X - rect.Left, e.Y - rect.Top);
panelflag = true;
}
}
}
}
else
{
if (g3 == false)
{
f = false;
cond();
if (f == false)
{
g2 = false;
f = false;
return;
}
else
f = false;
}
coordinatechanges(w);
a = e.X;
b = e.Y;
}
}
if (panelflag == true)
{
panel1.Invalidate();
panelflag = false;
}
}
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
if (file == "")
return;
picclickcontrol(w);
panelflag = true;
}
private void panel1_MouseLeave(object sender, EventArgs e)
{
if (file == "")
return;
if (rect.X != 0 || rect.Y != 0)
{
cond();
if (f == false)
borderrectangle(w);
else
f = false;
}
}
private void paintworks()
{
if (MouseButtons != MouseButtons.Left)
g3 = false;
if (g3 == false)
{
f = false;
foreach (Rectangle r in rectangles)
{
if ((w.X >= r.X && w.X <= (r.X + r.Width)) && (w.Y >= r.Y && w.Y <= r.Y + r.Height))
{
f = true;
rect = new Rectangle(r.X, r.Y, r.Width, r.Height);
break;
}
}
}
else
f = true;
}
private Rectangle GetRect(PosSizableRect p)
{
if (rect.Width <= 0 || rect.Height <= 0)
return new Rectangle();
switch (p)
{
case PosSizableRect.LeftUp:
return rect1 = new Rectangle(rect.X - 5 / 2, rect.Y - 5 / 2, 5, 5);
case PosSizableRect.LeftMiddle:
return rect1 = new Rectangle(rect.X - 5 / 2, rect.Y + rect.Height / 2 - 5, 5, 5);
case PosSizableRect.LeftBottom:
return rect1 = new Rectangle((rect.X) - 5 / 2, (rect.Y + rect.Height) - 5 / 2, 5, 5);
case PosSizableRect.BottomMiddle:
return rect1 = new Rectangle(rect.X + rect.Width / 2 - 5, rect.Y + rect.Height - 5 / 2, 5, 5);
case PosSizableRect.RightUp:
return rect1 = new Rectangle((rect.X + rect.Width) - 5 / 2, rect.Y - 5 / 2, 5, 5);
case PosSizableRect.RightBottom:
return rect1 = new Rectangle((rect.X + rect.Width) - 5 / 2, (rect.Y + rect.Height) - 5 / 2, 5, 5);
case PosSizableRect.RightMiddle:
return rect1 = new Rectangle(rect.X + rect.Width - 5 / 2, rect.Y + rect.Height / 2 - 5, 5, 5);
case PosSizableRect.UpMiddle:
return rect1 = new Rectangle(rect.X + rect.Width / 2 - 5, rect.Y - 5 / 2, 5, 5);
default:
return new Rectangle();
}
}
private PosSizableRect GetNodeSelectable(Point p)
{
foreach (PosSizableRect r in Enum.GetValues(typeof(PosSizableRect)))
{
if (GetRect(r).Contains(p))
{
return r;
}
}
return PosSizableRect.None;
}
private Cursor GetCursor(PosSizableRect p)
{
switch (p)
{
case PosSizableRect.LeftUp:
return Cursors.SizeNWSE;
case PosSizableRect.LeftMiddle:
return Cursors.SizeWE;
case PosSizableRect.LeftBottom:
return Cursors.SizeNESW;
case PosSizableRect.BottomMiddle:
return Cursors.SizeNS;
case PosSizableRect.RightUp:
return Cursors.SizeNESW;
case PosSizableRect.RightBottom:
return Cursors.SizeNWSE;
case PosSizableRect.RightMiddle:
return Cursors.SizeWE;
case PosSizableRect.UpMiddle:
return Cursors.SizeNS;
default:
f = false;
if ((w.X < zoomminwidth || w.X > zoommaxwidth))
return Cursors.Arrow;
else
{
elocation(w);
if (f == true)
{
f = false;
return Cursors.SizeAll;
}
else
return Cursors.Cross;
}
}
}
public void comman()
{
if (!(mybitmap == null))
{
if (!(rectangles.Count == 0))
{
using (Pen pen = new Pen(Color.Red, 2))
{
c = 0;
foreach (Rectangle r in rectangles)
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawString(lab[c].ToString(), new Font(lab[c].ToString(), 2.75F), new SolidBrush(label1.ForeColor), r);
g.DrawRectangle(pen, r);
c++;
}
}
}
}
}
private void loadxml()
{
XmlDocument oDOM = new XmlDocument();
XmlNode oscreenwidth;
XmlNode oscreenheight;
XmlNode ox;
string str1 = Path.GetFileNameWithoutExtension(file) + ".xml";
if (File.Exists(str1))
{
oDOM.Load(str1);
if (File.Exists(str1))
{
XmlNodeList oscreenrevolution = oDOM.DocumentElement.SelectNodes(".//screen");
foreach (XmlNode oscreen in oscreenrevolution)
{
oscreenwidth = oscreen.SelectSingleNode("//Width");
a = Convert.ToInt16(oscreenwidth.InnerText);
oscreenheight = oscreen.SelectSingleNode("//height");
b = Convert.ToInt16(oscreenheight.InnerText);
ox = oscreen.SelectSingleNode("//X");
c = Convert.ToInt16(ox.InnerText);
}
oscreenrevolution = null;
ox = null;
oscreenwidth = null;
oscreenheight = null;
oDOM = null;
switch (svc.Bounds.Width.ToString())
{
case "800":
{
if (c == 290)
d = -64;
else if (c == 326)
d = -100;
else if (c == 363)
d = -137;
else if (c == 409)
d = -183;
else
d = 0;
diffscreenresolution(b, d);
break;
}
case "1024":
{
if (c == 226)
d = 64;
else if (c == 326)
d = -36;
else if (c == 363)
d = -73;
else if (c == 409)
d = -120;
else
d = 0;
diffscreenresolution(b, d);
break;
}
case "1152":
{
if (c == 226)
d = 100;
else if (c == 290)
d = 36;
else if (c == 363)
d = -37;
else if (c == 409)
d = -83;
else
d = 0;
diffscreenresolution(b, d);
break;
}
case "1280":
{
if (c == 226)
d = 137;
else if (c == 290)
d = 73;
else if (c == 326)
d = 37;
else if (c == 409)
d = -47;
else
d = 0;
diffscreenresolution(b, d);
break;
}
case "1440":
{
if (c == 226)
d = 183;
else if (c == 290)
d = 120;
else if (c == 326)
d = 83;
else if (c == 363)
d = 47;
else
d = 0;
diffscreenresolution(b, d);
break;
}
default:
{
d = 0;
break;
}
}
mybitmap = new Bitmap(panel1.Width, panel1.Height);
mybitmap.SetResolution(300, 300);
label1.Text = "";
rect = new Rectangle(0, 0, 0, 0);
}
}
}
private void diffscreenresolution(int b1, int z)
{
XmlDocument oDOM = new XmlDocument();
XmlNodeList oRectangle;
string str1 = Path.GetFileNameWithoutExtension(file) + ".xml";
oDOM.Load(str1);
oRectangle = oDOM.DocumentElement.SelectNodes(".//Rectangle");
if (oRectangle != null)
{
foreach (XmlNode oRect in oRectangle)
{
XmlNode oXAxis = oRect.SelectSingleNode(".//X");
XmlNode oYAxis = oRect.SelectSingleNode(".//Y");
XmlNode oWAxis = oRect.SelectSingleNode(".//Width");
XmlNode oHAxis = oRect.SelectSingleNode(".//height");
XmlNode label = oRect.SelectSingleNode(".//label");
rect.X = Convert.ToInt16(oXAxis.InnerText);
rect.Y = Convert.ToInt16(oYAxis.InnerText);
rect.Width = Convert.ToInt16(oWAxis.InnerText);
rect.Height = Convert.ToInt16((oHAxis.InnerText));
label1.Text = Convert.ToString(label.InnerText);
rect.X = Convert.ToInt16(Convert.ToDouble(rect.X)) + z;
rect.Y = Convert.ToInt16((Convert.ToDouble(rect.Y) / Convert.ToDouble(b)) * (Convert.ToDouble((rect2.Height))));
rect.Height = Convert.ToInt16(Convert.ToDouble(rect.Height) * (Convert.ToDouble(rect2.Height) / Convert.ToDouble(b)));
lab.Add(label.InnerText);
rectangles.Add(rect);
oXAxis = null;
oYAxis = null;
oWAxis = null;
oHAxis = null;
label = null;
}
oRectangle = null;
oDOM = null;
}
}
private void elocation(Point n)
{
c = -1;
foreach (Rectangle r in rectangles)
{
if ((n.X >= r.X && n.X <= (r.X + r.Width)) && (n.Y >= r.Y && n.Y <= r.Y + r.Height))
{
f = true;
c++;
break;
}
c++;
}
}
private void borderrectangle(Point n)
{
if (rect.X + rect.Width >= zoommaxwidth && rect.Y + rect.Height >= zoommaxheight || n.X >= zoommaxwidth + 50 || n.Y + rect.Height >= zoommaxheight + 50)
{
if (rect.X + rect.Width >= zoommaxwidth)
rect.X = zoommaxwidth - rect.Width;
if (rect.Y + rect.Height >= zoommaxheight)
rect.Y = zoommaxheight - rect.Height;
cond();
borderrect();
}
else if (rect.X + rect.Width >= zoommaxwidth)
{
rect.X = zoommaxwidth - rect.Width;
rect = new Rectangle(rect.Left, rect.Top, rect.Width, n.Y - rect.Top);
if (MouseButtons == MouseButtons.None)
{
cond();
borderrect();
}
}
else if (rect.Y + rect.Height >= zoommaxheight)
{
rect.Y = zoommaxheight - rect.Height;
rect = new Rectangle(rect.Left, rect.Top, n.X - rect.Left, rect.Height);
if (MouseButtons == MouseButtons.None)
{
cond();
borderrect();
}
}
}
private void coordinatechanges(Point n)
{
switch (nodeSelected)
{
case PosSizableRect.LeftUp:
if (n.Y <= zoomminheight || n.X <= zoomminwidth)
{
if (rect.Y <= zoomminheight)
{
rect.Y = zoomminheight;
}
else if (rect.X <= zoomminwidth)
rect.X = zoomminwidth;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.X += n.X - a;
rect.Y += n.Y - b;
rect.Width -= n.X - a;
rect.Height -= n.Y - b;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.LeftMiddle:
if (n.X <= zoomminwidth)
{
rect.X = zoomminwidth;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.X += n.X - a;
rect.Width -= n.X - a;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.LeftBottom:
if (n.X <= zoomminwidth || n.Y >= zoommaxheight)
{
if (rect.X <= zoomminwidth)
rect.X = zoomminwidth;
else if (rect.Y + rect.Height >= zoommaxheight)
rect.Y = zoommaxheight - rect.Height;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.X += n.X - a;
rect.Height += n.Y - b;
rect.Width -= n.X - a;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.BottomMiddle:
if (n.Y >= zoommaxheight)
{
if (rect.Y + rect.Height >= zoommaxheight)
rect.Y = zoommaxheight - rect.Height;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.Height += n.Y - b;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.RightUp:
if (n.X >= zoommaxwidth || n.Y <= zoomminwidth)
{
if (rect.X + rect.Width > zoommaxwidth)
rect.X = zoommaxwidth - rect.Width;
else if (n.Y <= zoomminwidth)
rect.Y = zoomminwidth;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.Y += n.Y - b;
rect.Width += n.X - a;
rect.Height -= n.Y - b;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.RightBottom:
if (n.X >= zoommaxwidth || n.Y >= zoommaxheight)
{
if (rect.X + rect.Width >= zoommaxwidth)
rect.X = zoommaxwidth - rect.Width;
else if (rect.Y + rect.Height >= zoommaxheight)
rect.Y = zoommaxheight - rect.Height;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.Width += n.X - a;
rect.Height += n.Y - b;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.RightMiddle:
if (n.X >= zoommaxwidth)
{
if (rect.X + rect.Width >= zoommaxwidth)
rect.Width = zoommaxwidth - rect.X;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.Width += n.X - a;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
case PosSizableRect.UpMiddle:
if (n.Y <= zoomminheight)
{
rect.Y = zoomminheight;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rect.Y += n.Y - b;
rect.Height -= n.Y - b;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
default:
rect.X = rect.X + n.X - a;
rect.Y = rect.Y + n.Y - b;
if (rect.X + rect.Width >= zoommaxwidth || rect.Y + rect.Height >= zoommaxheight || rect.X <= zoomminwidth || rect.Y < zoomminheight)
{
if (rect.X <= zoomminwidth)
rect.X = zoomminwidth;
if (rect.Y < zoomminheight)
rect.Y = zoomminheight;
if (rect.X + rect.Width >= zoommaxwidth)
rect.X = zoommaxwidth - rect.Width;
if (rect.Y + rect.Height >= zoommaxheight)
rect.Y = zoommaxheight - rect.Height;
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
else
{
rectangles.RemoveAt(d);
rectangles.Insert(d, rect);
}
break;
}
panelflag = true;
}
private void borderrect()
{
if (f == true)
{
f = false;
rectangles.RemoveAt(c);
rectangles.Insert(c, rect);
lab.RemoveAt(c);
lab.Insert(c, "");
}
else
{
if (!(rect.Width == 0 || rect.Height == 0))
{
rectangles.Add(rect);
lab.Add("");
if ((rect.Height != 0 && rect.Width != 0))
{
contextMenuStrip1.Show(w.X, w.Y);
}
}
}
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
w.X = rect.X; w.Y = rect.Y;
elocation(w);
if (f == true)
{
rectangles.RemoveAt(c);
lab.RemoveAt(c);
f = false;
rect = new Rectangle(0, 0, 0, 0);
}
if (rectangles.Count == 0)
{
rect.Width = 0; rect.Height = 0;
}
deleteToolStripMenuItem.Checked = false;
g2 = false;
g3 = false;
label1.Text = "";
}
private void picclickcontrol(Point n)
{
if (g2 == false)
{
if ((rect.Height != 0 && rect.Width != 0))
{
}
}
if (rectangles.Count == 0)
{
rect = new Rectangle(rect.Left, rect.Top, n.X - rect.Left, n.Y - rect.Top);
if (rect.Width <= 0 || rect.Height <= 0)
{
contextMenuStrip1.Visible = false;
MessageBox.Show("Reverse croping not allowed");
}
else
{
rectangles.Add(rect);
contextMenuStrip1.Show(w.X, w.Y);
panel1.Invalidate();
if (rectangles.Count != 0 && rectangles.Count != lab.Count)
{
if (label1.Text == "")
{
label1.Text = "";
lab.Add(label1.Text);
}
}
}
}
else
{
f = false;
cond();
if (f == false)
{
g2 = false;
if (rect.Height != 0 && rect.Width != 0)
{
if (rect.Width <= 0 || rect.Height <= 0 || rect.Y < 0 || rect.X < 0)
{
cond();
if (f == true)
{
rect = new Rectangle(rectangles[c].X, rectangles[c].Y, rectangles[c].Width, rectangles[c].Height);
f = false;
}
else
rect = new Rectangle(0, 0, 0, 0);
contextMenuStrip1.Visible = false;
MessageBox.Show("Reverse croping not allowed");
}
else
{
rectangles.Add(rect);
if (panel1.Width == sz.Width)
contextMenuStrip1.Show(w);
else if (panel1.Width <= (sz.Width * 8))
{
a = panel1.Width;
for (c = 0; a > sz.Width; c++, a -= 50) ;
contextMenuStrip1.Show((w.X) - (25 * c), w.Y - (25 * c));
}
else
{
a = panel1.Width;
for (c = 0; a > sz.Width; c++, a -= 50) ;
contextMenuStrip1.Show((rect.X + rect.Width) - (25 * c), rect.Y - (40 * c));
}
panel1.Invalidate();
if (rectangles.Count != 0 && rectangles.Count != lab.Count)
{
if (label1.Text == "")
{
label1.Text = "";
lab.Add(label1.Text);
}
}
}
}
else
contextMenuStrip1.Visible = false;
}
else
{
f = false;
}
}
}
private void resetfunction()
{
if (file == "")
MessageBox.Show("Open a file");
else
{
zoominToolStripMenuItem1.Checked = false;
zoomOutToolStripMenuItem1.Checked = false;
deleteToolStripMenuItem.Checked = false;
zoominToolStripMenuItem1.Enabled = true;
zoomOutToolStripMenuItem1.Enabled = true;
if (f == true)
f = false;
else
{
f = false;
double ratio = 0d;
sz1.Width = panel1.Width;
for (; sz1.Width > sz.Width; )
{
sz1.Width -= 50;
ratio = Convert.ToDouble(panel1.Width) / Convert.ToDouble(sz1.Width);
for (c = 0; c <= (rectangles.Count - 1); c++)
{
switch (svc.Bounds.Width.ToString())
{
case "1280":
{
if (svc.Bounds.Height == 768)
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 1)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2);
else if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 11)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 17)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 5);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + 1.1);
else if (sz1.Width < (sz.Width + (50 * 20)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 23)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
}
else if (svc.Bounds.Height == 1024)
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width == (sz.Width + (50 * 15)) || sz1.Width == (sz.Width + (50 * 20)) || sz1.Width == (sz.Width + (50 * 25)))
{
rect1.Width = Convert.ToInt16((rectangles[c].Width / ratio)) + 2;
}
else
{
rect1.Width = Convert.ToInt16((rectangles[c].Width / ratio));
}
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2);
else if (sz1.Width < (sz.Width + (50 * 6)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 23)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 25)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 5);
if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 10)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 12)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 17)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
}
break;
}
case "1152":
{
if (sz1.Width == (sz.Width + (50 * 10)) || sz1.Width == (sz.Width + (50 * 20)) || sz1.Width == (sz.Width + (50 * 30)))
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio))) + 1;
else
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 7)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 9)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 14)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 24)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 29)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else if (sz1.Width < (sz.Width + (50 * 33)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 8);
if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
case "1024":
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 2)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 11)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 29)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 5);
else if (sz1.Width < (sz.Width + (50 * 34)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 10)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 12)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
case "1440":
{
if (svc.Bounds.Height == 1050)
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 6)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 13)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 23)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 27)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else if (sz1.Width < (sz.Width + (50 * 33)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 8);
if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - 1.1);
else if (sz1.Width < (sz.Width + (50 * 10)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 12)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - 1.1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
}
else
{
if (sz1.Width == (sz.Width + (50 * 10)) || sz1.Width == (sz.Width + (50 * 20)) || sz1.Width == (sz.Width + (50 * 30)))
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio))) + 1;
else
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 7)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 9)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 14)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 24)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 29)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else if (sz1.Width < (sz.Width + (50 * 33)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 8);
if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
}
break;
}
case "800":
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 11)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 28)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2);
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - .1);
else if (sz1.Width < (sz.Width + (50 * 13)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - 1.1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
default:
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2);
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
rect1.Height = Convert.ToInt16(rectangles[c].Height / ratio);
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
}
rectangles.RemoveAt(c);
rectangles.Insert(c, rect1);
}
panel1.Width -= 50;
panel1.Height -= 50;
}
}
zoomborder(panel1.Width);
for (c = 0; c <= rectangles.Count - 1; c++)
{
rect1 = (Rectangle)(rectangles[c]);
if (rect1.X + rect1.Width > zoommaxwidth)
{
rect1.Width = zoommaxwidth - rect1.X;
rectangles.RemoveAt(c);
rectangles.Insert(c, rect1);
}
}
sz1.Width = 800;
sz1.Height = 650;
image = resizeimage(image1, sz1);
n3 = n2 = 0;
}
}
private void zoomborder(int width)
{
if (width > sz.Width)
{
for (c = 0; width > sz.Width; c++, width -= 50) ;
zoomminwidth = panelpostion - 5;
zoommaxwidth = k+(Convert.ToInt16(15.5*c));
zoommaxheight = n1+(50*c) ;
zoomminheight = 0;
}
else
{
zoomminwidth = Convert.ToInt16((sz.Width) / 3.5);
zoommaxwidth = k;
zoommaxheight = n1;
zoomminheight = 0;
}
}
private void chapterToolStripMenuItem_Click(object sender, EventArgs e)
{
label1.Text = "Chapter";
f = false;
cond();
if (f == true)
{
f = false;
if (lab.Count == rectangles.Count)
{
lab.RemoveAt(c);
lab.Insert(c, label1.Text);
}
else
lab.Add(label1.Text);
label1.Text = "";
}
}
private void summaryToolStripMenuItem_Click(object sender, EventArgs e)
{
label1.Text = "Summary";
deleteToolStripMenuItem.Enabled = false;
f = false;
cond();
if (f == true)
{
f = false;
if (lab.Count == rectangles.Count)
{
lab.RemoveAt(c);
lab.Insert(c, label1.Text);
}
else
lab.Add(label1.Text);
label1.Text = "";
}
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
if (!(rect.Height != 0 && rect.Width != 0))
contextMenuStrip1.Enabled = false;
else
{
contextMenuStrip1.Enabled = true;
f = false;
cond();
if (f == true)
{
f = false;
contextMenuStrip1.Items[0].Enabled = true;
}
else
contextMenuStrip1.Items[0].Enabled = false;
}
}
private void cond()
{
c = -1;
foreach (Rectangle r in rectangles)
{
if ((rect.X >= r.X && rect.X <= (r.X + r.Width)) && (rect.Y >= r.Y && rect.Y <= r.Y + r.Height))
{
rect = new Rectangle(r.X, r.Y, r.Width, r.Height);
c++;
f = true;
break;
}
c++;
}
}
private void kToolStripMenuItem_Click(object sender, EventArgs e)
{
if (file == "")
{
MessageBox.Show("Open a file");
return;
}
List<Rectangle> rectangles1 = new List<Rectangle>();
double ratio = 0d;
b = panel1.Width;
a = panel1.Width;
rectangles1 = rectangles;
sz1.Width = panel1.Width;
for (; sz1.Width > sz.Width; )
{
sz1.Width -= 50;
ratio = Convert.ToDouble(panel1.Width) / Convert.ToDouble(sz1.Width);
for (c = 0; c <= (rectangles.Count - 1); c++)
{
switch (svc.Bounds.Width.ToString())
{
case "1280":
{
if (svc.Bounds.Height == 768)
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 1)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2);
else if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 11)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 17)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 5);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + 1.1);
else if (sz1.Width < (sz.Width + (50 * 20)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 23)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
}
else if (svc.Bounds.Height == 1024)
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width == (sz.Width + (50 * 15)) || sz1.Width == (sz.Width + (50 * 20)) || sz1.Width == (sz.Width + (50 * 25)))
{
rect1.Width = Convert.ToInt16((rectangles[c].Width / ratio)) + 2;
}
else
{
rect1.Width = Convert.ToInt16((rectangles[c].Width / ratio));
}
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2);
else if (sz1.Width < (sz.Width + (50 * 6)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 23)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 25)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 5);
if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 10)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 12)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 17)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
}
break;
}
case "1152":
{
if (sz1.Width == (sz.Width + (50 * 10)) || sz1.Width == (sz.Width + (50 * 20)) || sz1.Width == (sz.Width + (50 * 30)))
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio))) + 1;
else
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 7)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 9)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 14)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 24)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 29)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else if (sz1.Width < (sz.Width + (50 * 33)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 8);
if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
case "1024":
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 2)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 11)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 29)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 5);
else if (sz1.Width < (sz.Width + (50 * 34)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 10)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 12)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
case "1440":
{
if (svc.Bounds.Height == 1050)
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 6)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 13)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 23)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 27)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else if (sz1.Width < (sz.Width + (50 * 33)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 8);
if (sz1.Width < (sz.Width + (50 * 4)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - 1.1);
else if (sz1.Width < (sz.Width + (50 * 10)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 12)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - 1.1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
}
else
{
if (sz1.Width == (sz.Width + (50 * 10)) || sz1.Width == (sz.Width + (50 * 20)) || sz1.Width == (sz.Width + (50 * 30)))
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio))) + 1;
else
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 7)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 9)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 14)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 24)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 29)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else if (sz1.Width < (sz.Width + (50 * 33)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 7);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 8);
if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
}
break;
}
case "800":
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Y = Convert.ToInt16((rectangles[c].Y) / ratio) - (n2 - 1);
else if (sz1.Width < (sz.Width + (50 * 5)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 2);
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 3);
else if (sz1.Width < (sz.Width + (50 * 11)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 4);
else if (sz1.Width < (sz.Width + (50 * 28)))
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2 - 6);
else
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2);
if (sz1.Width < (sz.Width + (50 * 3)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 8)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - .1);
else if (sz1.Width < (sz.Width + (50 * 13)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) + .1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else if (sz1.Width < (sz.Width + (50 * 15)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio) - 1.1);
else if (sz1.Width < (sz.Width + (50 * 18)))
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
else
rect1.Height = Convert.ToInt16((rectangles[c].Height / ratio));
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
default:
{
rect1.X = Convert.ToInt16(Convert.ToInt16((rectangles[c].X / ratio)));
rect1.Y = Convert.ToInt16((rectangles[c].Y / ratio)) - (n2);
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
rect1.Height = Convert.ToInt16(rectangles[c].Height / ratio);
rect1.Width = Convert.ToInt16(rectangles[c].Width / ratio);
break;
}
}
rectangles.RemoveAt(c);
rectangles.Insert(c, rect1);
}
panel1.Width -= 50;
panel1.Height -= 50;
PropertyInfo pInfo = panel1.GetType().GetProperty("ImageRectangle",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
rect1 = (Rectangle)pInfo.GetValue(panel1, null);
n2 = n3 - rect1.Y;
n3 = rect1.Y;
}
panel1.Location = new Point(0, 48);
for (c = 0; c <= rectangles.Count - 1; c++)
{
rect1 = (Rectangle)(rectangles[c]);
if (rect1.X + rect1.Width > zoommaxwidth)
{
rect1.Width = zoommaxwidth - rect1.X;
rectangles.RemoveAt(c);
rectangles.Insert(c, rect1);
}
}
string str1 = Path.GetFileNameWithoutExtension(file);
StreamWriter Recta = new StreamWriter(Path.GetDirectoryName(str1) + str1 + ".xml");
Recta.WriteLine("<xml>");
Recta.WriteLine("<screen>");
Recta.WriteLine("<X>" + rect2.X.ToString() + "</X>");
Recta.WriteLine("<Y>" + rect2.Y.ToString() + "</Y>");
Recta.WriteLine("<Width>" + rect2.Width.ToString() + "</Width>");
Recta.WriteLine("<height>" + rect2.Height.ToString() + "</height>");
Recta.WriteLine("</screen>");
c = 0;
foreach (Rectangle r in rectangles)
{
Recta.WriteLine("<Rectangle>");
Recta.WriteLine("<X>" + r.X.ToString() + "</X>");
Recta.WriteLine("<Y>" + r.Y.ToString() + "</Y>");
Recta.WriteLine("<Width>" + r.Width.ToString() + "</Width>");
Recta.WriteLine("<height>" + r.Height.ToString() + "</height>");
Recta.WriteLine("<label>" + lab[c].ToString() + "</label>");
Recta.WriteLine("</Rectangle>");
c++;
}
Recta.WriteLine("</xml>");
Recta.Close();
}
private void fToolStripMenuItem1_Click(object sender, EventArgs e)
{
zoominfunction();
}
private void eToolStripMenuItem_Click(object sender, EventArgs e)
{
zoomoutfunction();
}
private void resetToolStripMenuItem_Click(object sender, EventArgs e)
{
resetfunction();
}
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
label1.Text = e.ClickedItem.ToString();
f = false;
cond();
if (label1.Text != "Delete")
{
if (f == true)
{
f = false;
if (lab.Count == rectangles.Count)
{
lab.RemoveAt(c);
lab.Insert(c, label1.Text);
}
else
lab.Add(label1.Text);
label1.Text = "";
}
}
}
}
}
|