【问题标题】:Open chrome (hidden tab) in C# panel在 C# 面板中打开 chrome(隐藏选项卡)
【发布时间】:2018-06-29 21:21:02
【问题描述】:

Error IMAGE Click

大家好,我正在开发一个项目,我需要在c#面板中运行谷歌浏览器应用程序,但是与图片中的代码不符。

 [DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
        private void Form1_Load(object sender, EventArgs e)
        {

        }



        private void button1_Click_1(object sender, EventArgs e)
        {
            Process p = Process.Start(@"D:\\chrome.lnk");
            p.WaitForInputIdle();
            SetParent(p.MainWindowHandle, panel1.Handle); //Exception thrown here

        }

异常的文本。

System.InvalidOperationException was unhandled
  HResult=-2146233079
  Message=İşlemden çıkıldığından istenen bilgiler kullanılamıyor.
  Source=System
  StackTrace:
       konum: System.Diagnostics.Process.EnsureState(State state)
       konum: System.Diagnostics.Process.get_MainWindowHandle()
       konum: AnyMinWin.Form1.button1_Click(Object sender, EventArgs e) c:\users\anyone\documents\visual studio 2010\Projects\AnyMinWin\AnyMinWin\Form1.cs içinde: satır 36
       konum: System.Windows.Forms.Control.OnClick(EventArgs e)
       konum: System.Windows.Forms.Button.OnClick(EventArgs e)
       konum: System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       konum: System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       konum: System.Windows.Forms.Control.WndProc(Message& m)
       konum: System.Windows.Forms.ButtonBase.WndProc(Message& m)
       konum: System.Windows.Forms.Button.WndProc(Message& m)
       konum: System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       konum: System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       konum: System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       konum: System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       konum: System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       konum: System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       konum: System.Windows.Forms.Application.Run(Form mainForm)
       konum: AnyMinWin.Program.Main() c:\users\anyone\documents\visual studio 2010\Projects\AnyMinWin\AnyMinWin\Program.cs içinde: satır 18
       konum: System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       konum: System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       konum: Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       konum: System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       konum: System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       konum: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       konum: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       konum: System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

【问题讨论】:

  • 错误的英文翻译为“由于进程退出,无法使用请求的信息。” (你仍然需要把你的代码放在问题中)
  • 抱歉,我已经更正了

标签: c# .net google-chrome


【解决方案1】:

只需使用 WebBrowser 并将其设置为:

WebBrowser wb = new WebBrowser();
wb.Navigate("link to you web");
web.Visible = false;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多