/// <summary> /// Put the main form window in fullscreen mode. /// </summary> private void GoFullScreen() { this.mainForm.FormBorderStyle = FormBorderStyle.None; if (this.mainForm.allScreens) { var width = 0; if (this.mainForm.allScreens) { width += Screen.AllScreens.Sum(screen => screen.Bounds.Width); } this.mainForm.Width = width; this.mainForm.Location = new Point(0, 0); } else { var screenBounds = Screen.FromControl(this.mainForm.tcTerminals).Bounds; this.mainForm.Width = screenBounds.Width; this.mainForm.Location = screenBounds.Location; } this.mainForm.Height = Screen.FromControl(this.mainForm.tcTerminals).Bounds.Height; this.mainForm.WindowState = FormWindowState.Normal; this.mainForm.menuStrip.Visible = false; this.mainForm.BringToFront(); }
private void DoDraw() { EventsHelper.Fire(_drawing, this, EventArgs.Empty); CodeClock clock = new CodeClock(); clock.Start(); if (this.Surface != null) { System.Drawing.Graphics graphics = this.CreateGraphics(); this.Surface.WindowID = this.Handle; this.Surface.ContextID = graphics.GetHdc(); this.Surface.ClientRectangle = this.ClientRectangle; this.Surface.ClipRectangle = this.ClientRectangle; DrawArgs args = new DrawArgs(this.Surface, new WinFormsScreenProxy(Screen.FromControl(this)), DrawMode.Render) { Dpi = Dpi }; _isDrawing = true; try { _tile.Draw(args); _lastRenderExceptionMessage = null; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "An error has occured while rendering the contents of a tile."); _lastRenderExceptionMessage = ex is RenderingException ? ((RenderingException)ex).UserMessage : ex.Message; // we cannot simply pass the existing Graphics because we haven't released its hDC yet // if we do, we'll get a "Object is currently in use elsewhere" exception DrawErrorMessage(_lastRenderExceptionMessage, Surface.ContextID, ClientRectangle); } finally { graphics.ReleaseHdc(this.Surface.ContextID); graphics.Dispose(); _isDrawing = false; } } //Cause the tile to paint/refresh. Invalidate(); Update(); clock.Stop(); string str = String.Format("TileControl.Draw: {0}, {1}\n", clock.ToString(), this.Size.ToString()); Trace.Write(str); }
public void Show(Control control, Rectangle area) { if (control == null) { throw new ArgumentNullException("control"); } SetOwnerItem(control); resizableTop = resizableRight = false; Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (location.X + Size.Width > (screen.Left + screen.Width)) { resizableRight = true; location.X = (screen.Left + screen.Width) - Size.Width; } if (location.Y + Size.Height > (screen.Top + screen.Height)) { resizableTop = true; location.Y -= Size.Height + area.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
public static Rectangle GetWorkingArea(Control ctl) { return(Screen.FromControl(ctl).WorkingArea); }
public static Rectangle GetBounds(Control ctl) { return(Screen.FromControl(ctl).Bounds); }
protected override void OnPaint(PaintEventArgs e) { //Assume anything Vista or later has the same issues. if (IsVistaOrLater()) { //Windows Vista is opportunistic when it comes to wait conditions (e.g. locks, Mutexes, etc) //in that it will actually process WM_PAINT messages on the current thread, even though //it is supposed to be blocking in a WaitSleepJoin state. This behaviour can actually //break rendering for a couple of reasons: // 1. We do custom double-buffering, and it's possible that we could process a paint message // for an image that hasn't actually been rendered to the back buffer yet. // 2. The renderer itself accesses the pixel data of the ImageSops, which is a synchronized operation. // In the case where 2 threads try to load the pixel data of an image simultaneously, the renderer can end up // blocking execution on the main UI thread in the middle of a rendering operation. If we // allow another tile to paint in this situation, it actually causes some GDI errors because // the previous rendering operation has not yet completed. if (_isDrawing || _painting) { e.Graphics.Clear(Color.Black); //Queue this tile up for deferred painting and return. if (!_tilesToRepaint.Contains(this)) { _tilesToRepaint.Add(this); } return; } //We're about to paint this tile, so remove it from the queue. _tilesToRepaint.Remove(this); } if (_tile.PresentationImage == null) { DisposeSurface(); } if (this.Surface == null) { // Make sure tile gets blacked out if there's // no presentation image in it e.Graphics.Clear(Color.Black); } else { this.Surface.WindowID = this.Handle; this.Surface.ContextID = e.Graphics.GetHdc(); this.Surface.ClientRectangle = this.ClientRectangle; this.Surface.ClipRectangle = e.ClipRectangle; DrawArgs args = new DrawArgs(this.Surface, new WinFormsScreenProxy(Screen.FromControl(this)), DrawMode.Refresh); _painting = true; try { _tile.Draw(args); // if an exception was encountered the last time we rendered the buffer, refresh the error text now if (!string.IsNullOrEmpty(_lastRenderExceptionMessage)) { // we cannot simply pass the Graphics because we haven't released its hDC yet // if we do, we'll get a "Object is currently in use elsewhere" exception DrawErrorMessage(_lastRenderExceptionMessage, Surface.ContextID, ClientRectangle); } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "An error has occured while refreshing the contents of a tile."); var exceptionMessage = ex is RenderingException ? ((RenderingException)ex).UserMessage : ex.Message; // we cannot simply pass the existing Graphics because we haven't released its hDC yet // if we do, we'll get a "Object is currently in use elsewhere" exception DrawErrorMessage(exceptionMessage, Surface.ContextID, ClientRectangle); } finally { e.Graphics.ReleaseHdc(this.Surface.ContextID); _painting = false; } } // Now that we've finished painting this tile, we can process the deferred paint jobs. // The code below is self-fulfilling, in that we remove one tile from the queue and // invalidate it, causing it to paint. When it's done painting, it will remove and // invalidate the next one, and so on. if (IsVistaOrLater() && _tilesToRepaint.Count > 0) { TileControl tileToRepaint = _tilesToRepaint[0]; _tilesToRepaint.RemoveAt(0); tileToRepaint.Invalidate(); tileToRepaint.Update(); } //base.OnPaint(e); }
public void Show(Control control, Rectangle rect, bool center) { if (control == null) { throw new ArgumentNullException("control"); } SetOwnerItem(control); if (_canResize && !_changeRegion) { Padding = new Padding(3); } else if (!_changeRegion) { Padding = new Padding(1); } else { Padding = Padding.Empty; } int width = Padding.Horizontal; int height = Padding.Vertical; base.Size = new Size(_popupControl.Width + width, _popupControl.Height + height); _resizableTop = false; _resizableLeft = false; Point location = control.PointToScreen(new Point(rect.Left, rect.Bottom)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (center) { if (location.X + (rect.Width + Size.Width) / 2 > screen.Right) { location.X = screen.Right - Size.Width; _resizableLeft = true; } else { location.X = location.X - (Size.Width - rect.Width) / 2; } } else { if (location.X + Size.Width > (screen.Left + screen.Width)) { _resizableLeft = true; location.X = (screen.Left + screen.Width) - Size.Width; } } if (location.Y + Size.Height > (screen.Top + screen.Height)) { _resizableTop = true; location.Y -= Size.Height + rect.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }