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); /// /// 通过点住控件移动窗体 /// /// 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); } } }