c# - WebBrowser ContextMenu run action of menu item -
itemprop = "text">
I have an application with a web browser control. I load a page by clicking on a button. Then I want to run an "Adobe PDF Convert" action from the contextual web browser, but ... when I try to reach the context menu:
foreach (MenuItem vMenuItem in WebBrowser.ContextMenu.MenuItems) {if (vMenuItem.Text.Contains ("Onvert") and VMenuItem.Text.Contains ("PDF")) {vMenuItem.PerformClick (); }} IDE
shows the "object reference not set for an example of an object" line in the line with foreach (in the menu vMenuItem WebBrowser ContextMenu.MenuItems) I have not created my own context menu, I want to show the default context menu. How do I use WebBrowser's context menu and how can I do that action?
I have a similar problem to you. I have made a reference to your problem in my post. If you are still interested in this problem, then it is doing something that imitates the clicks:
// code Example of how to use: Point Control Lock = this.PointToScreen (WebBrover 1. Location); ControlLoc.X = controlLoc.X + Webbrover 1. Document. GetAlementBiID ("SBVDCPPG"). Offsetrectengel Left + 65; ControlLoc.Y = Control Lock. Y + Webbrover 1 Document. Get Element BIID ("sbvdcapimg"). OffsetRectangle.Top + 50; Cursor Structure = control; MouseSimulator.ClickRightMouseButton (); ControlLoc.X = Control Lock.x + (Webbrozer 1. Document. Get Element BIID ("SBVDCPMG") Offsetrectengel .Let + 95); ControlLoc.Y = Control Lock. Y + (Webbrozer 1. Document Get Element BIID ("SBVDCPMG") Offsetrectengel. +45 +;); Cursor Structure = control MouseSimulator.ClickLeftMouseButton (); Public class mouse simulators {[DllImport ("user32.dll", Setlist error = true)) Fixed Exert UIT Send Input (UITNInput, Ref input, PINTPs, int CBSEs); [Structure Layout (LayoutCind.Security)] Strip INPUT {Public SendInputEventType type; Public MouseBehardwareInputAnonymous; } [Layout layout (LayoutCind.Explit)] Structured MouseBehardware Input Union [[Field Offset (0)] Public Mouse Input Data Mile; [Field Offset (0)] Public KeybuddyPute; [Field Offset (0)] Public Hardware Hi; } [Structure Layout (LayoutCind.Security)] String KEYBDINPUT {public use wVk; Public user wScan; Public UIT dwFlags; Time of public time; Public IntPtr dwExtraInfo; } [Layout Layout (LayoutCind.Security)] Structure HardwareWorld {Public Ent UMS; Public Small wParamL; Public minor wParamH; } Configuration MouseInputData {PUBLIC IND DX; Public int dy; Public UIT MoodyData; Public MouseEventFlags dwFlags; Time of public time; Public IntPtr dwExtraInfo; } [Flags] enum MouseEventFlags: uint {MOUSEEVENTF_MOVE = 0x0001, MOUSEEVENTF_LEFTDOWN = 0x0002, MOUSEEVENTF_LEFTUP = 0x0004, MOUSEEVENTF_RIGHTDOWN = 0x0008, MOUSEEVENTF_RIGHTUP = 0x0010, MOUSEEVENTF_MIDDLEDOWN = 0x0020, MOUSEEVENTF_MIDDLEUP = 0x0040, MOUSEEVENTF_XDOWN = 0x0080, MOUSEEVENTF_XUP = 0x0100, MOUSEEVENTF_WHEEL = 0x0800, MOUSEEVENTF_VIRTUALDESK = 0x4000, MOUSEEVENTF_ABSOLUTE = 0x8000} enum SendInputEventType: int {InputMouse, InputKeyboard, InputHardware} Public Static Zero ClickRightMouseButton () {INPUT mouseDownInput = new INPUT (); MouseDown input.product = SendInputEventType.InputMouse; MouseDownInput.phx.mai Dvflag = muwevtflag.mucevnt_iirittandaa; SendInput (1, Ref mousedowninput, Marshall Size (new input ())); INPUT mouseUpInput = new INPUT (); MouseUpInput.type = SendInputEventType.InputMouse; MouseUpInput.mkhi.mi.dwFlags = MouseAventFlag.MusEVENTIIRTTP; SendInput (1, ref mouseup input, martial size. (New input ()); } Public static zero ClickLeftMouseButton () {INPUT mouseDownInput = new INPUT (); MouseDown input.product = SendInputEventType.InputMouse; MouseDownInputMatch.me DualFlags = MouseAventFlag.MusEVENTLIFTdown; SendInput (1, Ref mousedowninput, Marshall Size (new input ())); INPUT mouseUpInput = new INPUT (); MouseUpInput.type = SendInputEventType.InputMouse; MouseUpInput.mkhi.mi.dwFlags = MouseAventFlag.mixEvent_LEFTUP; SendInput (1, ref mouseup input, martial size. (New input ()); }
Comments
Post a Comment