FrmSlideChart.cs
5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using GeneralLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace SunVoteARSPPT
{
public partial class FrmSlideChart : Form
{
public FrmSlideChart()
{
InitializeComponent();
this.FormClosed += FrmSlideChart_FormClosed;
}
private void FrmSlideChart_FormClosed(object sender, FormClosedEventArgs e)
{
if (Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.SlideShowWindow != null)
{
RECT r = new RECT();
if (GetWindowRect((IntPtr)Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.SlideShowWindow.HWND, ref r))
{
int x = r.Left;
int y = r.Top;
int w = r.Right - r.Left;
int h = r.Bottom - r.Top;
string pos = (this.Left - x) + "," + (this.Top - y) + "," + this.Width + "," + this.Height;
GlobalInfo.sysConfig.WriteSysConfig("System", "SlideChartPos", pos);
}
}
}
private void FrmSlideChart_Load(object sender, EventArgs e)
{
this.TopMost = true;//杨斌 2016-10-19
}
public void ShowCenter()
{
this.Show();
if (Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.SlideShowWindow != null)
{
RECT r = new RECT();
if (GetWindowRect((IntPtr)Globals.SunVoteARSAddIn.PPTEdit.PPT.ActivePresentation.SlideShowWindow.HWND, ref r))
{
int x = r.Left;
int y = r.Top;
int w = r.Right - r.Left;
int h = r.Bottom - r.Top;
int xm = w - 30;
int ym = h - 30;
try
{
var iniSet = INIControl.GetInstances(GlobalInfo.SYSTEM_CONFIG_PATH);
string pos = iniSet.ReadString("System", "SlideChartPos", "");
var ary = pos.Split(',');
if ((ary != null) && (ary.Length >= 4))
{
int xx = ConvertOper.Convert(ary[0]).ToInt;
int yy = ConvertOper.Convert(ary[1]).ToInt;
int ww = ConvertOper.Convert(ary[2]).ToInt;
int hh = ConvertOper.Convert(ary[3]).ToInt;
if (xx < 0) xx = 0;
if (yy < 0) yy = 0;
if (xx > xm) xx = xm;
if (yy > ym) yy = ym;
if (ww < 30) ww = 30;
if (hh < 30) hh = 30;
this.Location = new Point(x + xx, y + yy);
this.Size = new Size(ww, hh);
}
else
{
//默认右下角。杨斌 2019-06-27
this.Location = new Point(x + (w - this.Width), y + (h - this.Height));
//this.Location = new Point(x + (w - this.Width) / 2, y + (h - this.Height) / 2);//居中
}
}
catch
{
//默认右下角。杨斌 2019-06-27
this.Location = new Point(x + (w - this.Width), y + (h - this.Height));
//this.Location = new Point(x + (w - this.Width) / 2, y + (h - this.Height) / 2);//居中
}
}
}
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; //最左坐标
public int Top; //最上坐标
public int Right; //最右坐标
public int Bottom; //最下坐标
}
[DllImport("user32")]
private static extern bool ReleaseCapture();
[DllImport("user32")]
private static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
/// <summary>
/// 通过点住控件移动窗体
/// </summary>
/// <param name="ctl"></param>
private void MoveForm(Control ctl)
{
const int WM_NCLBUTTONDOWN = 0xA1;
const int HTCAPTION = 0x2;
//const int WM_SYSCOMMAND = 0x112;
//const int SC_MOVE = 0xF010;
ReleaseCapture();
SendMessage(ctl.Handle.ToInt32(), WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
private void Chart_MouseDown(object sender, MouseEventArgs e)
{
MoveForm(this);
}
}
}