This is a migrated thread and some comments may be shown as answers.

Gantt does not render correctly in WinForms WebBrowser control .

2 Answers 225 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Piotr
Top achievements
Rank 1
Piotr asked on 04 Sep 2014, 10:01 AM
Hi

i'm stuck during implementation own gantt view inside a WebBrowser Control for standard WinForms UI. I 've already added necessary Registry keys (Dword value) according to the guidelines through the provided class:

internal class WebToolKit : IProgramInitializer
    {
        private static UIntPtr HKEY_LOCAL_MACHINE = (UIntPtr)0x80000002;
        private static int KEY_READ = 0x20019;
        private static int KEY_WOW64_32KEY = 0x200;
        private static int KEY_WOW64_64KEY = 0x100;
        private static UInt32 IE_VERSION = 0x00002EDF;    /// DWORD value must be here
        /// it provides information about IE engine version
        /// for webbbrowser control container
       
        private static string registryKeyPath = "SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION";
        private static string valueNameX86 = "OwnApp32.exe";
        private static string valueNameX64 = "OwnApp.exe";

        [DllImport("advapi32.dll", EntryPoint = "RegOpenKeyExW", CharSet = CharSet.Unicode, SetLastError = true)]
        private static extern int RegOpenKeyEx
            (UIntPtr hKey, string lpSubKey, uint ulOptions, int samDesired, out UIntPtr phkResult);
        [DllImport("advapi32.dll", EntryPoint = "RegQueryValueExW", CharSet = CharSet.Unicode, SetLastError = true)]
        private static extern int RegQueryValueEx(UIntPtr hKey, string lpValueName, IntPtr lpReserved, out uint lpType, StringBuilder lpData, ref uint lpcbData);
        [DllImport("advapi32.dll", SetLastError = true)]
        private static extern int RegCloseKey(UIntPtr hKey);
        public void Initialize()
        {
            UIntPtr zero = UIntPtr.Zero;
            string str = null;
            uint lpcbData = 0x1000;
            StringBuilder lpData = new StringBuilder((int)lpcbData);

            try
            {
                uint num2;
                if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryKeyPath, 0, KEY_READ | KEY_WOW64_64KEY, out zero) == 0)
                {
                    if (RegQueryValueEx(zero, valueNameX86, IntPtr.Zero, out num2, lpData, ref lpcbData) == 0)
                        str = lpData.ToString();
                    if (RegQueryValueEx(zero, valueNameX64, IntPtr.Zero, out num2, lpData, ref lpcbData) == 0)
                        str = lpData.ToString();
                }
                if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryKeyPath, 0, KEY_READ | KEY_WOW64_32KEY, out zero) == 0
                    && RegQueryValueEx(zero, valueNameX86, IntPtr.Zero, out num2, lpData, ref lpcbData) == 0)
                    str = lpData.ToString();
                if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryKeyPath, 0, KEY_READ | KEY_WOW64_32KEY, out zero) == 0
                    && RegQueryValueEx(zero, valueNameX64, IntPtr.Zero, out num2, lpData, ref lpcbData) == 0)
                    str = lpData.ToString();
            }
            finally
            {
                if (zero != UIntPtr.Zero)
                    RegCloseKey(zero);
            }
            if (String.IsNullOrEmpty(str))
            {
                try
                {
                    RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(registryKeyPath, true);
                    registryKey.SetValue(valueNameX86, IE_VERSION, RegistryValueKind.DWord);
                    registryKey.SetValue(valueNameX64, IE_VERSION, RegistryValueKind.DWord);
                }
                catch (SecurityException)
                {
                    System.Windows.Forms.MessageBox.Show(string.Format(
                           "Run this application under control of Administrator rights permissions"                            
                ));
                }

            }
        }

And until this place it works fine. I also have been checked browser version using JavaScript (navigator.AppName) and result was correct. But i have a trouble with user interaction between WebBrowser control and invoked UI navigation elements (i.e JQuery and Web Service are ok). For instance, splitter not working at all, just like progress trackBar on a Gantt.Timeline. Below i attached most important pieces of my code embedded webborwser control:  


// 
            // webBrowser1
            // 
            this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.webBrowser1.IsWebBrowserContextMenuEnabled = true;
            webBrowser1.IsAccessible = true;            
            this.webBrowser1.Location = new System.Drawing.Point(0, 0);
            this.webBrowser1.AllowWebBrowserDrop = true;
            this.webBrowser1.AllowNavigation = true;
            this.webBrowser1.Margin = new System.Windows.Forms.Padding(18, 39, 18, 39);
            this.webBrowser1.MinimumSize = new System.Drawing.Size(120, 260);
            this.webBrowser1.Name = "webBrowser1";
            this.webBrowser1.Size = new System.Drawing.Size(1028, 727);
            this.webBrowser1.ScriptErrorsSuppressed = true;
            this.webBrowser1.TabIndex = 1;
            this.webBrowser1.WebBrowserShortcutsEnabled = true;
            this.webBrowser1.ObjectForScripting = this;


internal void InitContext(Context cx)
        {
      
            this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted); 
                this.webBrowser1.Navigate(String.Format("{0}/Home/Index", URL));
        }

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //Poprawka dla property ScriptErrorsSuppressed
            //Normalnie blokuje otwarcie wszelkich pop-up nie tylko tych które są błędami skryptów JS
            //http://stackoverflow.com/questions/2476360/disable-javascript-error-in-webbrowser-control
            ((WebBrowser)sender).Document.Window.Error +=
                                 new HtmlElementErrorEventHandler(Window_Error);
            TrySetSuppressScriptErrors(webBrowser1, true);           
        }

        private static void Window_Error(object sender,
    HtmlElementErrorEventArgs e)
        {
            // Ignore the error and suppress the error dialog box. 
            e.Handled = true;

        }

        private void trackBarZoomBar_ValueChanged(object sender, EventArgs e)
        {
            ((SHDocVw.WebBrowser)webBrowser1.ActiveXInstance).ExecWB(SHDocVw.OLECMDID.OLECMDID_OPTICAL_ZOOM,
    SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, trackBarZoomBar.Value, IntPtr.Zero);
            this.lbZoomLabel.Text = String.Format("{0} %", trackBarZoomBar.Value);
        }

        private static bool TrySetSuppressScriptErrors(WebBrowser webBrowser, bool value)
        {
            FieldInfo field = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
            if (field != null)
            {
                object axIWebBrowser2 = field.GetValue(webBrowser);
                if (axIWebBrowser2 != null)
                {
                    axIWebBrowser2.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, axIWebBrowser2, new object[] { value });
                    return true;
                }
            }

            return false;
        }


I have no idea what am i doing wrong. I'll be gratefull for any sugestions.

Best regards
Luke







2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 04 Sep 2014, 02:38 PM
Hello Piotr,

This sounds as a known issue caused by the WebBrowser control. In this mode IE exposes pointer events but never triggers them. This confuses Kendo UI as it detects pointer events and starts to listen to them instead of mouse events.

So far we haven't found a reliable way to detect this behavior.

The only workaround for now is to put this JavaScript code in the page that you will host in the web browser control (before including the Kendo UI JS files):

  <script>
      window.MSPointerEvent = null;
      window.PointerEvent = null;
  </script>

This will prevent Kendo UI from detecting pointer events.

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Piotr
Top achievements
Rank 1
answered on 04 Sep 2014, 03:38 PM
Thanks a lot. Your solution works great. :)
Tags
Gantt
Asked by
Piotr
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Piotr
Top achievements
Rank 1
Share this question
or