예제 #1
0
		/// <summary>
		/// Draws an rectangle with colors on the top/left and bottom/right with the given <paramref name="width"/>
		/// </summary>
		/// <param name="topLeftColor">Color for top/left edges</param>
		/// <param name="bottomRightColor">Color for bottom/right edges</param>
		/// <param name="rectangle">Outside of inset rectangle to draw</param>
		/// <param name="width">Width of the rectangle, in pixels</param>
		public void DrawInsetRectangle (Color topLeftColor, Color bottomRightColor, Rectangle rectangle, int width = 1)
		{
			for (int i = 0; i < width; i++) {
				DrawLine (topLeftColor, rectangle.TopLeft, rectangle.InnerTopRight);
				DrawLine (topLeftColor, rectangle.TopLeft, rectangle.InnerBottomLeft);
				DrawLine (bottomRightColor, rectangle.InnerBottomLeft, rectangle.InnerBottomRight);
				DrawLine (bottomRightColor, rectangle.InnerTopRight, rectangle.InnerBottomRight);
				rectangle.Inflate (-1, -1);
			}
		}
예제 #2
0
		PrintDocument GetPrintDocument()
		{
			var document = new PrintDocument();
			document.PrintSettings = settings;
			var font = Fonts.Serif(16);
			var printTime = DateTime.Now;
			document.PrintPage += (sender, e) =>
			{
				Size pageSize = Size.Round(e.PageSize);

				// draw a border around the printable area
				var rect = new Rectangle(pageSize);
				rect.Inflate(-1, -1);
				e.Graphics.DrawRectangle(Pens.Silver, rect);

				// draw title
				e.Graphics.DrawText(font, Colors.Black, new Point(50, 20), document.Name);

				// draw page number
				var text = string.Format("page {0} of {1}", e.CurrentPage + 1, document.PageCount);
				var textSize = Size.Round(e.Graphics.MeasureString(font, text));
				e.Graphics.DrawText(font, Colors.Black, new Point(pageSize.Width - textSize.Width - 50, 20), text);

				// draw date
				text = string.Format("Printed on {0:f}", printTime);
				textSize = Size.Round(e.Graphics.MeasureString(font, text));
				e.Graphics.DrawText(font, Colors.Black, new Point(pageSize.Width - textSize.Width - 50, pageSize.Height - textSize.Height - 20), text);

				// draw some rectangles
				switch (e.CurrentPage)
				{
					case 0:
						e.Graphics.DrawRectangle(Pens.Blue, new Rectangle(50, 50, 100, 100));
						e.Graphics.DrawRectangle(Pens.Green, new Rectangle(new Point(pageSize) - new Size(150, 150), new Size(100, 100)));
						break;
					case 1:
						e.Graphics.DrawRectangle(Pens.Blue, new Rectangle(pageSize.Width - 150, 50, 100, 100));
						e.Graphics.DrawRectangle(Pens.Green, new Rectangle(50, pageSize.Height - 150, 100, 100));
						break;
				}
			};
			document.Name = "Name Of Document";
			document.PageCount = 2;
			return document;
		}
예제 #3
0
 void HandleDocumentLoaded(object sender, WebViewLoadedEventArgs e)
 {
     var newIsLocal = string.IsNullOrEmpty(e.Uri.AbsolutePath) || e.Uri.IsLoopback;
     if (isLocal != newIsLocal)
     {
         isLocal = newIsLocal;
         var newSize = isLocal ? defaultSize : expandedSize;
         var location = this.Location;
         var rect = new Rectangle(location, this.ClientSize);
         rect.Inflate((newSize.Width - rect.Width) / 2, (newSize.Height - rect.Height) / 2);
         if (Generator.IsMac)
             rect.Y = location.Y;
         this.Location = rect.Location;
         this.ClientSize = rect.Size;
     }
 }