public static void Run(TneForm form) { MainForm = form; WatchMsg(); }
void OnShowContextMenu(IWebBrowser webbrowser, JsQueryEventArgs args) { var menuInfo = JsonConvert.DeserializeObject <ShowContextMenuForTneFormInfo>(args.Request); var wbinfo = GetBrowserInfo(webbrowser); var tneForm = wbinfo.GetNativeObject(menuInfo.TneFormId, false) as TneForm; var menuForm = new TneForm(menuInfo.Url); menuForm.SizeAble = false; menuForm.ShowInTaskBar = false; menuForm.StartPosition = StartPosition.Manual; menuForm.TopMost = true; menuForm.KillFocus += (sender, eventArgs) => { menuForm.Close(); }; menuForm.Parent = tneForm; var x = tneForm.X + menuInfo.X; var y = tneForm.Y + menuInfo.Y; if (menuInfo.X == -1 && menuInfo.Y == -1) { var point = new NativeMethods.POINT(); NativeMethods.GetCursorPos(ref point); x = point.x; y = point.y; } RECT rect = new RECT(); var rectPtr = Marshal.AllocHGlobal(Marshal.SizeOf <RECT>()); Marshal.StructureToPtr(rect, rectPtr, true); NativeMethods.SystemParametersInfoW(NativeMethods.SPI_GETWORKAREA, 0, rectPtr, 0); rect = Marshal.PtrToStructure <RECT>(rectPtr); Marshal.FreeHGlobal(rectPtr); int cx = rect.right - rect.left; int cy = rect.bottom - rect.top; if (x + menuInfo.Width > cx) { x = x - menuInfo.Width; if (x < 0) { x = 0; } } if (y + menuInfo.Height > cy) { y = y - menuInfo.Height; if (y < 0) { y = 0; } } menuForm.X = x; menuForm.Y = y; menuForm.Width = menuInfo.Width; menuForm.Height = menuInfo.Height; menuForm.TopMost = true; menuForm.Show(); webbrowser.ResponseJsQuery(webbrowser.WebView, args.QueryId, args.CustomMsg, "OK"); }