Example #1
0
		/// <summary>
		/// Gets an image snapshot of the specified control, which does not have to be
		/// mapped to a <see cref="System.Windows.Forms.Form"/> and does not have to be
		/// fully visible.
		/// </summary>
		/// <param name="control">The control to get an image snapshot of.</param>
		/// <returns>An image snapshot of the control.</returns>
		public static Image OffscreenGrab(Control control) {
			// Save the old parent and location.
			Control oldParent = control.Parent;
			Point oldLocation = control.Location;

			// Create a form offscreen
			Form transpForm = new Form();
			transpForm.StartPosition = FormStartPosition.Manual;
			transpForm.Location = new Point(Screen.PrimaryScreen.Bounds.Right + 10, 0);
			transpForm.ClientSize = new Size(control.Width + 10, control.Height + 10);

			// Make the form semi-transparent so windows turns on layering.
			transpForm.Opacity = .8;

			// Add the control.
			transpForm.Controls.Add(control);
			control.Location = new Point(0, 0);

			// Show the form (offscreen).
			transpForm.Show();
			transpForm.Visible = true;
			transpForm.Refresh();
			transpForm.Update();

			// Grab the control.
			Image img = GrabControl(control);

			// Put the control back on its original form.
			control.Parent = oldParent;
			control.Location = oldLocation;

			// Get rid of our temporary form.
			transpForm.Close();

			// Return the image.
			return img;
		}
 private void DoFormTextChanged(object sender, EventArgs e)
 {
     UpdateRibbonConditions();
     Form.Refresh();
     Form.Update();
 }
 private void DoFormResizeEnd(object sender, EventArgs e)
 {
     UpdateRibbonConditions();
     Form.Refresh();
     Form.Update();
 }
Example #4
0
        public static void InstallComShellExt(bool install, Form form, bool silent)
        {
            //Debug.Assert(false);
            if (!CSScriptInstaller.IsInstalled())
            {
                MessageBox.Show("Advanced Shell Extensions can be installed only after CS-Script configuration completed.\nPlease execute config.bat to configure the CS-Script.");
            }
            else
            {
                if (install)
                {
                    EnsureComShellExtensionPlacement();

                    DialogResult response = DialogResult.Yes;
                    if (!silent)
                    {
                        response = MessageBox.Show(form,
                                                    "You are about to install/activate additional Advanced Shell Extensions.\n" +
                                                    "\nPlease note that the structure of the shell extensions will follow the file structure of the\n" +
                                                    "'" + Path.GetDirectoryName(comShellEtxDLL32) + "' folder\n" +
                                                    "(See CS-Script documentation for details)\n" +
                                                    "\n" +
                                                    "Do you want to proceed with the installation?", "CS-Script", MessageBoxButtons.YesNo);

                        if (form != null)
                            form.Update();
                    }

                    if (DialogResult.Yes == response)
                    {
                        if (Directory.Exists(Environment.ExpandEnvironmentVariables(@"%windir%\SysWOW64")))
                        {
                            RunApp(Environment.ExpandEnvironmentVariables(@"%windir%\SysWOW64\regsvr32.exe"), (silent ? "/s \"" : "\"") + comShellEtxDLL32 + "\"");
                            RunApp(Environment.ExpandEnvironmentVariables(@"%windir%\System32\regsvr32.exe"), (silent ? "/s \"" : "\"") + comShellEtxDLL64 + "\"");
                        }
                        else
                        {
                            RunApp(Environment.ExpandEnvironmentVariables(@"%windir%\System32\regsvr32.exe"), (silent ? "/s \"" : "\"") + comShellEtxDLL32 + "\"");
                        }
                    }
                }
                else
                {
                    DialogResult response = DialogResult.Yes;
                    if (!silent)
                    {
                        response = MessageBox.Show("You are about to uninstall/deactivate additional Advanced Shell Extentions.\n" +
                                                    "\nPlease note that some files of '" + Path.GetDirectoryName(comShellEtxDLL32) + "'\n" +
                                                    "will be locked until Windows Explorer is restarted.\n" +
                                                    "\n" +
                                                    "Do you want to proceed with uninstallating?", "CS-Script", MessageBoxButtons.YesNo);

                        if (form != null)
                            form.Update();
                    }

                    if (DialogResult.Yes == response)
                    {
                        string dll = GetComShellExtRegisteredDll();

                        if (dll != null)
                        {
                            if (Directory.Exists(Environment.ExpandEnvironmentVariables(@"%windir%\SysWOW64")))
                            {
                                //dll will be the path to either ShellExt or ShellExt64 (depending which one registry search returns); both are in the same directory
                                string dll32 = dll.Replace("ShellExt64.", "ShellExt.");
                                string dll64 = dll.Replace("ShellExt.", "ShellExt64.");

                                RunApp(Environment.ExpandEnvironmentVariables(@"%windir%\SysWOW64\regsvr32.exe"), (silent ? "/s /u \"" : "/u \"") + dll32 + "\"");
                                RunApp(Environment.ExpandEnvironmentVariables(@"%windir%\System32\regsvr32.exe"), (silent ? "/s /u \"" : "/u \"") + dll64 + "\"");
                            }
                            else
                            {
                                RunApp(Environment.ExpandEnvironmentVariables(@"%windir%\System32\regsvr32.exe"), (silent ? "/s /u \"" : "/u \"") + dll + "\"");
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        protected bool TrackHandle(int nHandle,Control frm,Point point,Form frmClipTo)
        {
            Debug.Assert(nHandle >= 0);
            Debug.Assert(nHandle <= 8);   // handle 8 is inside the rect

            // don't handle if capture already set
            //if(frm.Capture) return false;

            Debug.Assert(!m_bFinalErase);

            // save original width & height in pixels
            int nWidth = m_rect.Width;
            int nHeight = m_rect.Height;

            // set capture to the window which received this message
            frm.Capture=true;
            Debug.Assert(frm.Capture);
            frm.Update();
            if (frmClipTo!=null)
                frmClipTo.Update();
            Rectangle rectSave = m_rect;

            // find out what x/y coords we are supposed to modify
            int px=0, py=0;
            int xDiff=0, yDiff=0;
            GetModifyPointers(nHandle,ref px,ref py,ref xDiff,ref yDiff,true);
            xDiff = point.X - xDiff;
            yDiff = point.Y - yDiff;

            // get DC for drawing
            Graphics gs;
            if (frmClipTo!=null)
            {
                // clip to arbitrary window by using adjusted Window DC
                gs=frmClipTo.CreateGraphics();
            }
            else
            {
                // otherwise, just use normal DC
                gs=frm.CreateGraphics();
            }

            Rectangle rectOld;
            bool bMoved = false;

            // get messages until capture lost or cancelled/accepted
            for (;;)
            {
                MSG msg=new MSG();
                if(GetMessage(ref msg, 0, 0, 0)!=1) break;
                if(!frm.Capture) break;

                switch (msg.message)
                {
                        // handle movement/accept messages
                    case WM_LBUTTONUP:
                    case WM_MOUSEMOVE:
                        rectOld = m_rect;
                        // handle resize cases (and part of move)
                        SetRectInt(px,LoWord(msg.lParam) - xDiff);
                        SetRectInt(py,HiWord(msg.lParam) - yDiff);
                        // handle move case
                        if (nHandle == (int)TrackerHit.hitMiddle)
                        {
                            m_rect.Width=nWidth;
                            m_rect.Height=nHeight;
                        }
                        // allow caller to adjust the rectangle if necessary
                        AdjustRect(nHandle,ref m_rect);

                        // only redraw and callback if the rect actually changed!
                        m_bFinalErase = (msg.message == WM_LBUTTONUP);
                        if (m_bFinalErase)
                            goto ExitLoop;

                        if (!rectOld.Equals(m_rect) || m_bFinalErase)
                        {
                            if (bMoved)
                            {
                                m_bErase = true;
                                DrawTrackerRect(rectOld, frmClipTo, gs, frm);
                            }
                            OnChangedRect(rectOld);
                            if (msg.message != WM_LBUTTONUP)
                                bMoved = true;
                        }
                        if (m_bFinalErase)
                            goto ExitLoop;

                        if (!rectOld.Equals(m_rect))
                        {
                            m_bErase = false;
                            DrawTrackerRect(m_rect, frmClipTo, gs, frm);
                        }
                        break;

                        // handle cancel messages
                    case WM_KEYDOWN:
                        if (msg.wParam != 0x1B)//VK_ESCAPE
                            break;
                        goto default;
                    case WM_RBUTTONDOWN:
                        if (bMoved)
                        {
                            m_bErase = m_bFinalErase = true;
                            DrawTrackerRect(m_rect, frmClipTo, gs, frm);
                        }
                        m_rect = rectSave;
                        goto ExitLoop;

                        // just dispatch rest of the messages
                    default:
                        DispatchMessage(ref msg);
                        break;
                }
            }

            ExitLoop:
                gs.Dispose();
            frm.Capture=false;
            // restore rect in case bMoved is still FALSE
            if (!bMoved)
                m_rect = rectSave;
            m_bFinalErase = false;
            m_bErase = false;

            // return TRUE only if rect has changed
            return !rectSave.Equals(m_rect);
        }
Example #6
0
        public Updater(Form uForm, string uLocator, string uProgramName, string uVersionInfo, string uReplaceFile)
        {
            //uReplaceFile is empty => check for new version and download if necessary
            if (uReplaceFile == "")
            {
                //create update form
                uLabel.Size = new Size(400,20);
                uLabel.Text = "Checking for Updates...";
                uLabel.Location = new Point(10, 10);

                uPBar.Size = new Size(480, 30);
                uPBar.Location = new Point(10, 40);
                uPBar.Minimum = 0;
                uPBar.Maximum = 100;
                uPBar.Value = 1;

                uProgress.FormBorderStyle = FormBorderStyle.None;
                uProgress.Text = "Updater";
                uProgress.SetBounds(0, 0, 500, 80);
                uProgress.StartPosition = FormStartPosition.CenterScreen;
                //uProgress.ShowInTaskbar = false;

                uProgress.Controls.Add(uLabel);
                uProgress.Controls.Add(uPBar);

                uProgress.Show();
                uProgress.Update();

                // generate license key
                //string hw_key = generateKey();
                string hw_key = "null";

                // test the key
                if (testKey(hw_key) == false)
                {
                    MessageBox.Show("Could not fetch end user licence.", "Licence Error");
                    Environment.Exit(-1);
                }

                //check the version
                string uVersionOnline = uCheckVersion(uLocator, uVersionInfo);
                if (uVersionOnline != "")
                {
                    uPBar.Value = 30;
                    uProgress.Update();
                    //new update exists, ask for install
                    if (MessageBox.Show("New update available. Download & Install?", "Update", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        //close form and exit
                        uProgress.Close();
                        return;
                    }
                    //uForm.ShowInTaskbar = false;
                    uForm.WindowState = FormWindowState.Minimized;
                    uForm.Update();

                    //yes, user wants to install it. Begin download
                    uLabel.Text = "Downloading ";
                    uProgress.Update();
                    Uri uUri = new Uri(uLocator + uProgramName + uVersionOnline + ".exe");
                    WebClient uDownloadClient = new WebClient();
                    uDownloadClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);

                    //add download progress event handlers
                    uDownloadClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(progressChanged);

                    uDownloadClient.DownloadFileCompleted += new AsyncCompletedEventHandler((EventHandler)delegate(object sender, EventArgs args)
                    {
                        progressCompleted(sender, uProgramName, uVersionOnline);
                    });

                    //does file exist?

                    WebRequest request = WebRequest.Create(uUri);
                    request.Method = "GET";

                    try
                    {
                        WebResponse response = request.GetResponse();
                    }
                    catch (WebException uWebEx)
                    {
                        //connection failed
                        uLabel.Text = "Cannot reach server: " + uWebEx.Status;
                        uPBar.Value = 100;
                        uProgress.Update();
                        System.Threading.Thread.Sleep(1000);
                        uProgress.Close();
                        uForm.WindowState = FormWindowState.Normal;
                        return;
                    }

            /*                    using ()
                    {
                        MessageBox.Show("here:" +response.ContentLength + "-" + response.ContentType);
                    }*/

                    //test if the file already exists in the folder and delete it...
                    System.IO.FileInfo uFile = new System.IO.FileInfo(uProgramName + uVersionOnline + ".exe");
                    try
                    {
                        uFile.Delete();
                    }
                    catch //(System.IO.IOException e)
                    {
                        MessageBox.Show(uProgramName + uVersionOnline + ".exe already exists in folder. Please delete it first.", "Update Error");
                        //uLabel.Text = ;
                        uPBar.Value = 100;
                        uProgress.Update();
                        //System.Threading.Thread.Sleep(2000);
                        uProgress.Close();
                        uForm.WindowState = FormWindowState.Normal;
                        return;
                    }

                    //try downloading the file now
                    uDownloadClient.DownloadFileAsync(uUri, uProgramName + uVersionOnline + ".exe");
                }
                else
                //no new update available
                {
                    uLabel.Text = "Program is up to date.";
                    uPBar.Value = 100;
                    uProgress.Update();
                    System.Threading.Thread.Sleep(1000);
                    uProgress.Close();
                }
            }
            else
            //uEeplaceFile contains a filename => new version has been downloaded. Install it.
            {
                System.Threading.Thread.Sleep(1000);
                System.IO.FileInfo fi = new System.IO.FileInfo(@uReplaceFile);
                System.IO.FileInfo fa = new System.IO.FileInfo(@"SpineMiner.exe");
                try
                {
                    fi.Delete();
                    fa.Delete();
                }
                catch (System.IO.IOException e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }
Example #7
0
 protected virtual void Activate()
 {
     form.Invalidate(true);
     form.Update();
 }
Example #8
0
		public void TestPublicMethods ()
		{
			// Public Methods that force Handle creation:
			// - CreateGraphics ()
			// - GetChildAtPoint ()
			// - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created
			// - PointToClient ()
			// - PointToScreen ()
			// - RectangleToClient ()
			// - RectangleToScreen ()
			// - Select ()
			// - Show (IWin32Window)
			// Notes:
			// - CreateControl does NOT force Handle creation!
			
			Form c = new Form ();

			c.BringToFront ();
			Assert.IsFalse (c.IsHandleCreated, "A1");
			
			c.Contains (new Form ());
			Assert.IsFalse (c.IsHandleCreated, "A2");
			
			c.CreateControl ();
			Assert.IsFalse (c.IsHandleCreated, "A3");
			
			c = new Form ();
			Graphics g = c.CreateGraphics ();
			g.Dispose ();
			Assert.IsTrue (c.IsHandleCreated, "A4");
			c.Dispose ();
			c = new Form ();
			
			c.Dispose ();
			Assert.IsFalse (c.IsHandleCreated, "A5");
			c = new Form ();

			// This is weird, it causes a form to appear that won't go away until you move the mouse over it, 
			// but it doesn't create a handle??
			//DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None);
			//Assert.IsFalse (c.IsHandleCreated, "A6");
			//Assert.AreEqual (DragDropEffects.None, d, "A6b");
			
			//Bitmap b = new Bitmap (100, 100);
			//c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100));
			//Assert.IsFalse (c.IsHandleCreated, "A7");
			//b.Dispose ();
			c.FindForm ();
			Assert.IsFalse (c.IsHandleCreated, "A8");
			
			c.Focus ();
			Assert.IsFalse (c.IsHandleCreated, "A9");

			c.GetChildAtPoint (new Point (10, 10));
			Assert.IsTrue (c.IsHandleCreated, "A10");
			c.Dispose ();
			c = new Form ();
			
			c.GetContainerControl ();
			Assert.IsFalse (c.IsHandleCreated, "A11");
			c.Dispose ();
			
			c = new Form ();
			c.GetNextControl (new Control (), true);
			Assert.IsFalse (c.IsHandleCreated, "A12");
			c.GetPreferredSize (Size.Empty);
			Assert.IsFalse (c.IsHandleCreated, "A13");
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "A14");
			
			c.Invalidate ();
			Assert.IsFalse (c.IsHandleCreated, "A15");
			
			//c.Invoke (new InvokeDelegate (InvokeMethod));
			//Assert.IsFalse (c.IsHandleCreated, "A16");
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A17");
			
			c.PointToClient (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A18");
			c.Dispose ();
			c = new Form ();
			
			c.PointToScreen (new Point (100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A19");
			c.Dispose ();
			
			c = new Form ();
			
			//c.PreProcessControlMessage   ???
			//c.PreProcessMessage          ???
			c.RectangleToClient (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A20");
			c.Dispose ();
			c = new Form ();
			c.RectangleToScreen (new Rectangle (0, 0, 100, 100));
			Assert.IsTrue (c.IsHandleCreated, "A21");
			c.Dispose ();
			c = new Form ();
			c.Refresh ();
			Assert.IsFalse (c.IsHandleCreated, "A22");
			c.ResetBackColor ();
			Assert.IsFalse (c.IsHandleCreated, "A23");
			c.ResetBindings ();
			Assert.IsFalse (c.IsHandleCreated, "A24");
			c.ResetCursor ();
			Assert.IsFalse (c.IsHandleCreated, "A25");
			c.ResetFont ();
			Assert.IsFalse (c.IsHandleCreated, "A26");
			c.ResetForeColor ();
			Assert.IsFalse (c.IsHandleCreated, "A27");
			c.ResetImeMode ();
			Assert.IsFalse (c.IsHandleCreated, "A28");
			c.ResetRightToLeft ();
			Assert.IsFalse (c.IsHandleCreated, "A29");
			c.ResetText ();
			Assert.IsFalse (c.IsHandleCreated, "A30");
			c.SuspendLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A31");
			c.ResumeLayout ();
			Assert.IsFalse (c.IsHandleCreated, "A32");
			c.Scale (new SizeF (1.5f, 1.5f));
			Assert.IsFalse (c.IsHandleCreated, "A33");
			c.Select ();
			Assert.IsTrue (c.IsHandleCreated, "A34");
			c.Dispose ();
			
			c = new Form ();
			
			c.SelectNextControl (new Control (), true, true, true, true);
			Assert.IsFalse (c.IsHandleCreated, "A35");
			c.SetBounds (0, 0, 100, 100);
			Assert.IsFalse (c.IsHandleCreated, "A36");
			c.Update ();
			Assert.IsFalse (c.IsHandleCreated, "A37");
			
			// Form
			
			c.Activate ();
			Assert.IsFalse (c.IsHandleCreated, "F1");
			
			c.AddOwnedForm (new Form ());
			Assert.IsFalse (c.IsHandleCreated, "F2");
			
			c.Close ();
			Assert.IsFalse (c.IsHandleCreated, "F3");
			
			c.Hide ();
			Assert.IsFalse (c.IsHandleCreated, "F4");
			
			c.LayoutMdi (MdiLayout.Cascade);
			Assert.IsFalse (c.IsHandleCreated, "F5");

#if !MONO
			c.PerformAutoScale ();
			Assert.IsFalse (c.IsHandleCreated, "F6"); 
#endif
			
			c.PerformLayout ();
			Assert.IsFalse (c.IsHandleCreated, "F7");
			
			c.AddOwnedForm (new Form ());
			c.RemoveOwnedForm (c.OwnedForms [c.OwnedForms.Length - 1]);
			Assert.IsFalse (c.IsHandleCreated, "F8");
			
			c.ScrollControlIntoView (null);
			Assert.IsFalse (c.IsHandleCreated, "F9");
			
			c.SetAutoScrollMargin (7, 13);
			Assert.IsFalse (c.IsHandleCreated, "F10");
			
			c.SetDesktopBounds (-1, -1, 144, 169);
			Assert.IsFalse (c.IsHandleCreated, "F11");
			
			c.SetDesktopLocation (7, 13);
			Assert.IsFalse (c.IsHandleCreated, "F12");

			c = new Form ();
			c.Show (null);
			Assert.IsTrue (c.IsHandleCreated, "F13");
			c.Close ();
			c = new Form (); 
			
			//c.ShowDialog ()
			
			c.ToString ();
			Assert.IsFalse (c.IsHandleCreated, "F14");
			
			c.Validate ();
			Assert.IsFalse (c.IsHandleCreated, "F15");

#if !MONO
			c.ValidateChildren ();
			Assert.IsFalse (c.IsHandleCreated, "F16"); 
#endif

			c.Close ();
		}
Example #9
0
        /// <summary>
        /// Starts the form resize from edge.
        /// </summary>
        /// <param name="f">The f.</param>
        /// <param name="result">The result.</param>
        /// <param name="c">The c.</param>
        public static void StartFormResizeFromEdge(System.Windows.Forms.Form f, ResizeResult result, Control c = null)
        {
            var minimum = f is Zeroit.Framework.Form.ModernForm.Forms.ModernForm modernForm ? modernForm.MinimumSize : f.MinimumSize;
            var maximum = f is Zeroit.Framework.Form.ModernForm.Forms.ModernForm form ? form.MaximumSize : f.MaximumSize;
            //Cursor.Clip = Screen.GetWorkingArea(f);
            var curLoc     = f.PointToClient(Cursor.Position);
            var fLoc       = new Point(f.Left, f.Top);
            var w          = f.Width;
            var h          = f.Height;
            var resultEnum = ((ResizeResult)result);

            Action <Object, MouseEventArgs> mouseMove = (s, e) => {
                if (f.WindowState != FormWindowState.Maximized)
                {
                    var changedSize  = (new Size(curLoc) - new Size(e.Location)).Width;
                    var changedSizeH = (new Size(curLoc) - new Size(e.Location)).Height;
                    f.Cursor = HitTestToCursor(result);
                    switch (resultEnum)
                    {
                    case ResizeResult.Left:
                        if (curLoc.X <= Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder && ((f.Width + changedSize) >= minimum.Width))
                        {
                            f.Left  -= changedSize;
                            fLoc     = new Point(f.Left, f.Top);
                            f.Width += changedSize;
                            f.Update();
                        }
                        break;

                    case ResizeResult.Right:
                        if (curLoc.X >= minimum.Width - Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder)
                        {
                            f.Left  = fLoc.X;
                            curLoc  = f.PointToClient(Cursor.Position);
                            f.Width = w - changedSize;
                            f.Update();
                            w = f.Width;
                        }
                        break;

                    case ResizeResult.Bottom:
                        if (curLoc.Y >= minimum.Height - Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder)
                        {
                            f.Top    = fLoc.Y;
                            curLoc   = f.PointToClient(Cursor.Position);
                            f.Height = h - changedSizeH;
                            f.Update();
                            h = f.Height;
                        }
                        break;

                    case ResizeResult.BottomLeft:
                        if (curLoc.X <= Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder && curLoc.Y >= minimum.Height - Zeroit.Framework.Form.ModernForm.Forms.ModernForm.SizingBorder && ((f.Width + changedSize) >= minimum.Width))
                        {
                            var ww = e.Location.X - f.Left;
                            var hh = e.Location.Y - f.Bottom;

                            f.Height = f.Bottom + hh;
                            f.Left  -= changedSize;
                            fLoc     = new Point(f.Left, f.Top);
                            f.Width += changedSize;

                            f.Update();
                        }
                        break;

                    case ResizeResult.BottomRight:
                        var ww2 = e.Location.X - f.Right;
                        var hh2 = e.Location.Y - f.Bottom;

                        f.Height = f.Bottom + hh2;

                        fLoc     = new Point(f.Left, f.Top);
                        f.Width += f.Left + ww2;

                        f.Update();

                        break;
                    }
                }
            };
            MouseEventHandler invoke = mouseMove.Invoke;

            f.MouseMove += invoke;
            MouseEventHandler invokeCMove = (s, e) => {
                var pt = f.PointToClient(((Control)s).PointToScreen(e.Location));
                var x  = pt.X;
                var y  = pt.Y;


                invoke(f, new MouseEventArgs(e.Button, e.Clicks, x, y, e.Delta));
            };

            if (c != null)
            {
                c.MouseMove += invokeCMove;
            }



            MouseEventHandler invoke2 = null;

            invoke2 = (s, e) => {
                if (c != null)
                {
                    c.MouseMove -= invokeCMove;
                }
                if (c != null)
                {
                    c.MouseUp -= invoke2;
                }
                f.MouseUp   -= invoke2;
                f.MouseMove -= invoke;
                f.Update();
                //Cursor.Clip = new Rectangle();
            };

            f.MouseUp += invoke2;
            if (c != null)
            {
                c.MouseUp += invoke2;
            }
        }
Example #10
0
 private void StartProgress()
 {
     FDownload = new frmValidateRecordings();
     FDownload.Tag = DI;
     FDownload.Update();
     this.AddOwnedForm(FDownload);
     FDownload.Show();
 }
Example #11
0
 public static void UpdateFonts(Form form)
 {
     foreach (Control c in form.Controls)
     {
         if (c is TextBox || c is DataGridView || c is ListBox)
         {
             c.Font = new Font(Properties.Settings.Default.Fonts[0], c.Font.Size);
             c.ForeColor = Color.Black;
         }
         else
         {
             c.Font = new Font(Main.GetFont(), c.Font.Size);
             if (c.Name != "bt_Exit" && c.Name != "bt_Back" && c.Name != "bt_Logout")
                 c.ForeColor = Main.GetColor();
         }
     }
     form.Update();
     form.Refresh();
 }
Example #12
0
        private void AuthorizeApp()
        {
            string url = String.Format(FacebookSettings.AUTHORIZE_URL_FORMAT,
                                       FacebookSettings.APP_ID);

            // create and display a new form
            var f    = new System.Windows.Forms.Form();
            var web1 = new System.Windows.Forms.WebBrowser();

            f.SuspendLayout();

            var cursor = f.Cursor;

            f.Cursor = System.Windows.Forms.Cursors.WaitCursor;

            // event handlers
            WebBrowserDocumentCompletedEventHandler docCompleted = (sender, e) => {
                Tracing.Trace("web1.completed, url = '{0}'", web1.Url.ToString());
                var url2 = web1.Url.ToString();

                // It's possible there will be multiple pages in the flow.
                // We want to respond only to the "login_success" page.  Don't
                // be confused by the name: login_success does not mean "access
                // granted."
                if (url2.StartsWith("http://www.facebook.com/connect/login_success.html#") ||
                    url2.StartsWith("http://www.facebook.com/connect/login_success.html?"))
                {
                    web1.Visible = false;

                    var token =
                        RE.Regex.Replace(url2,
                                         ".+login_success.html#access_token=([^&]+).+",
                                         "$1");

                    PluginSettings.AccessToken = token;

                    // If token is null or empty, then The user has declined access.
                    // Otherwise, then the user has granted access.
                    // Either way, we want to close the form and return.
                    f.Close();
                }
            };

            WebBrowserNavigatingEventHandler navigating = (sender, e) => {
                Tracing.Trace("web1.navigating, url = '{0}'", web1.Url.ToString());
                f.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                f.Update();
            };

            // The embedded browser can navigate through HTTP 302
            // redirects, download images, and so on. The display will
            // initially be blank while it is waiting for downloads and
            // redirects. Also, after the user clicks "Login", there's a
            // delay.  In those cases we want the wait cursor. Only turn
            // it off if the status text is "Done."
            EventHandler statusChanged = (sender, e) => {
                var t = web1.StatusText;
                if (t == "Done")
                {
                    f.Cursor = cursor;
                }
                else if (!String.IsNullOrEmpty(t))
                {
                    Tracing.Trace("web1.status = '{0}'", t);
                    f.Cursor = System.Windows.Forms.Cursors.WaitCursor;
                }
            };

            //
            // web1
            //
            web1.Location           = new System.Drawing.Point(4, 166);
            web1.Name               = "web1";
            web1.DocumentCompleted += docCompleted;
            web1.Navigating        += navigating;
            web1.StatusTextChanged += statusChanged;
            web1.Dock               = DockStyle.Fill;
            f.Name = "embeddedBrowserForm";
            f.Text = "Please approve the Cropper Plugin for Facebook";
            f.Icon = global::Cropper.SendToFacebook.Properties.Resources.icon;
            f.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            f.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
            f.ClientSize          = new System.Drawing.Size(460, 320);
            f.Controls.Add(web1);
            f.ResumeLayout(false);
            web1.Url = new Uri(url);

            f.ShowDialog(); // this will wait for form exit
        }
Example #13
0
        // Delete the last line drawn on the Scratch Pad from collection.
        // Does NOT delete the line from the form itself, but calls Invalidate() & Update()
        // to force a repaint.
        public void DeleteLastLine(Form frmDraw)
        {
            // Retrieve count of LineGraphic objects in collection.
            int nLineGraphicCount = f_collLineGraphics.Count;

            // If not empty, delete last line added (drawn).
            if (nLineGraphicCount > 0)
            {
                // Delete last line from LineGraphic collection.
                f_collLineGraphics.RemoveAt(nLineGraphicCount - 1);

                // Invalidate entire screen area for repaint.
                frmDraw.Invalidate();

                // Force repaint.
                frmDraw.Update();
            }
        }
        /// <summary>
        /// Initialize the Windows... window. Attach Windows elements as well
        /// </summary>
        /// <returns>True if success, false otherwise</returns>
        protected bool InitMainWindow()
        {
            try
            {
                Window = new D3DForm
                {
                    Text = MainWindowCaption,
                    Name = "OutsideWndClassName",
                    FormBorderStyle = FormBorderStyle.Sizable,
                    ClientSize = new System.Drawing.Size(ClientWidth, ClientHeight),
                    StartPosition = FormStartPosition.CenterScreen,
                    MyWndProc = WndProc,
                    MinimumSize = new System.Drawing.Size(200, 200)
                };

                Window.MouseDown += OnMouseDown;
                Window.MouseUp += OnMouseUp;
                Window.MouseMove += OnMouseMove;
                Window.MouseWheel += OnMouseWheel;
                Window.ResizeBegin += (sender, args) =>
                {
                    AppPaused = true;
                    Resizing = true;
                    Timer.Stop();
                };
                Window.ResizeEnd += (sender, args) =>
                {
                    AppPaused = false;
                    Resizing = false;
                    Timer.Start();
                    OnResize();
                };

                Window.Show();
                Window.Update();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Outside Engine - Error");
                return false;
            }
        }
Example #15
0
        protected void CreateWindow(int width, int height)
        {
            Debug.Print("Application initiated");
            MainWindow = new Form {
                Width = width,
                Height = height,
                Text = GetName(),
                FormBorderStyle = FormBorderStyle.None
            };

            MainWindow.Show();
            MainWindow.Update();
            Input.Init(MainWindow);
        }