Skip to content
This repository was archived by the owner on Mar 4, 2018. It is now read-only.

Commit d150511

Browse files
authored
Merge pull request #27 from WorksOfBarry/dspf
Start of Display File edit support
2 parents d4030b2 + 3b31476 commit d150511

File tree

10 files changed

+2179
-0
lines changed

10 files changed

+2179
-0
lines changed

Forms/DragLabel.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using IBMiCmd.LanguageTools;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Drawing;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows.Forms;
9+
10+
namespace IBMiCmd.Forms
11+
{
12+
class DragLabel : Label
13+
{
14+
public DragLabel()
15+
{
16+
MouseDown += labelWorker_MouseDown;
17+
MouseMove += labelWorker_MouseMove;
18+
MouseUp += labelWorker_MouseUp;
19+
}
20+
21+
bool clicked = false;
22+
int iOldX;
23+
int iOldY;
24+
int iClickX;
25+
int iClickY;
26+
27+
void labelWorker_MouseDown(object sender, MouseEventArgs e)
28+
{
29+
Label labelWorker = (Label)sender;
30+
if (e.Button == MouseButtons.Left)
31+
{
32+
Point p = ConvertFromChildToForm(e.X, e.Y, labelWorker);
33+
iOldX = p.X;
34+
iOldY = p.Y;
35+
iClickX = e.X;
36+
iClickY = e.Y;
37+
clicked = true;
38+
}
39+
}
40+
41+
void labelWorker_MouseMove(object sender, MouseEventArgs e)
42+
{
43+
Label labelWorker = (Label)sender;
44+
if (clicked)
45+
{
46+
Point p = new Point(); // New Coordinate
47+
p.X = e.X + labelWorker.Left;
48+
p.Y = e.Y + labelWorker.Top;
49+
labelWorker.Left = p.X - iClickX;
50+
labelWorker.Top = p.Y - iClickY;
51+
}
52+
}
53+
54+
void labelWorker_MouseUp(object sender, MouseEventArgs e)
55+
{
56+
Label labelWorker = (Label)sender;
57+
Point p = new Point(); // New Coordinate
58+
p.X = e.X + labelWorker.Left;
59+
p.Y = e.Y + labelWorker.Top;
60+
61+
FieldInfo fieldInfo = (FieldInfo)labelWorker.Tag;
62+
fieldInfo.Position = PointToDSPF(PointToDSPFView(new Point(p.X - iClickX, p.Y - iClickY)), fieldInfo.Length);
63+
labelWorker.Location = dspfEdit.DSPFtoUILoc(fieldInfo.Position);
64+
65+
clicked = false;
66+
}
67+
68+
private Point ConvertFromChildToForm(int x, int y, Control control)
69+
{
70+
Point p = new Point(x, y);
71+
control.Location = p;
72+
return p;
73+
}
74+
75+
private static Point PointToDSPFView(Point Location)
76+
{
77+
int x = (((int)Location.X) / 9) * 9;
78+
int y = (((int)Location.Y) / 19) * 19;
79+
80+
return new Point(x, y);
81+
}
82+
83+
private static Point PointToDSPF(Point Location, int fieldLen)
84+
{
85+
int x = (((int)Location.X) / 9)+1;
86+
int y = (((int)Location.Y) / 19)+1;
87+
88+
if (x < 1) x = 1;
89+
if ((x + fieldLen) > dspfEdit.WindowSize.Width) x = dspfEdit.WindowSize.Width - fieldLen;
90+
if (y < 1) y = 1;
91+
if (y > dspfEdit.WindowSize.Height) y = dspfEdit.WindowSize.Height;
92+
93+
return new Point(x, y);
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)