diff --git a/snippets/csharp/System.Drawing/Bitmap/.ctor/Program.cs b/snippets/csharp/System.Drawing/Bitmap/.ctor/Program.cs new file mode 100644 index 00000000000..29f0804ec65 --- /dev/null +++ b/snippets/csharp/System.Drawing/Bitmap/.ctor/Program.cs @@ -0,0 +1,12 @@ +using System; + +internal static class Program +{ + [STAThread] + private static void Main() + { + //BitmapConstructorForm1.Run(); + //BitmapConstructorForm11.Run(); + BitmapConstructorForm12.Run(); + } +} diff --git a/snippets/csharp/System.Drawing/Bitmap/.ctor/Project.csproj b/snippets/csharp/System.Drawing/Bitmap/.ctor/Project.csproj new file mode 100644 index 00000000000..4a6d98d26b7 --- /dev/null +++ b/snippets/csharp/System.Drawing/Bitmap/.ctor/Project.csproj @@ -0,0 +1,9 @@ + + + + Exe + net10.0-windows + true + + + diff --git a/snippets/csharp/System.Drawing/Bitmap/.ctor/form1.cs b/snippets/csharp/System.Drawing/Bitmap/.ctor/form1.cs index fd66d0f1f26..1381e15556b 100644 --- a/snippets/csharp/System.Drawing/Bitmap/.ctor/form1.cs +++ b/snippets/csharp/System.Drawing/Bitmap/.ctor/form1.cs @@ -2,92 +2,85 @@ using System.Drawing; using System.Windows.Forms; -public class Form1: - System.Windows.Forms.Form +public class BitmapConstructorForm1 : Form { - #region " Windows Form Designer generated code " - - public Form1() : base() - { - - //This call is required by the Windows Form Designer. + public BitmapConstructorForm1() : base() + { + // This call is required by the Windows Form Designer. InitializeComponent(); - this.Button1.Click += new EventHandler(Button1_Click); - this.Button2.Click += new EventHandler(Button2_Click); - InitializeBitmap(); + Button1.Click += new EventHandler(Button1_Click); + Button2.Click += new EventHandler(Button2_Click); + + string filePath = "path//to//your//image.bmp"; + InitializeBitmap(filePath); InitializeStreamBitmap(); - //Add any initialization after the InitializeComponent() call + // Add any initialization after the InitializeComponent() call. } - //Form overrides dispose to clean up the component list. + // Form overrides Dispose to clean up the component list. protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } - //Required by the Windows Form Designer - private System.ComponentModel.IContainer components; + // Required by the Windows Form Designer. + private System.ComponentModel.IContainer components = null; - //NOTE: The following procedure is required by the Windows Form Designer - //It can be modified using the Windows Form Designer. - //Do not modify it using the code editor. - internal System.Windows.Forms.Button Button1; - internal System.Windows.Forms.PictureBox PictureBox1; - internal System.Windows.Forms.Button Button2; + // NOTE: The following procedure is required by the Windows Form Designer. + // It can be modified using the Windows Form Designer. + // Do not modify it using the code editor. + internal Button Button1; + internal PictureBox PictureBox1; + internal Button Button2; [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.Button1 = new System.Windows.Forms.Button(); - this.PictureBox1 = new System.Windows.Forms.PictureBox(); - this.Button2 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + Button1 = new Button(); + PictureBox1 = new PictureBox(); + Button2 = new Button(); + SuspendLayout(); // // Button1 // - this.Button1.Location = new System.Drawing.Point(24, 192); - this.Button1.Name = "Button1"; - this.Button1.Size = new System.Drawing.Size(96, 23); - this.Button1.TabIndex = 2; - this.Button1.Text = "Rotate and Flip"; + Button1.Location = new Point(24, 192); + Button1.Name = "Button1"; + Button1.Size = new Size(96, 23); + Button1.TabIndex = 2; + Button1.Text = "Rotate and Flip"; // // PictureBox1 // - this.PictureBox1.Location = new System.Drawing.Point(48, 40); - this.PictureBox1.Name = "PictureBox1"; - this.PictureBox1.Size = new System.Drawing.Size(168, 72); - this.PictureBox1.TabIndex = 3; - this.PictureBox1.TabStop = false; + PictureBox1.Location = new Point(48, 40); + PictureBox1.Name = "PictureBox1"; + PictureBox1.Size = new Size(168, 72); + PictureBox1.TabIndex = 3; + PictureBox1.TabStop = false; // // Button2 // - this.Button2.Location = new System.Drawing.Point(152, 192); - this.Button2.Name = "Button2"; - this.Button2.TabIndex = 4; - this.Button2.Text = "Button2"; + Button2.Location = new Point(152, 192); + Button2.Name = "Button2"; + Button2.TabIndex = 4; + Button2.Text = "Button2"; // // Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Button2); - this.Controls.Add(this.PictureBox1); - this.Controls.Add(this.Button1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new Size(292, 266); + Controls.Add(Button2); + Controls.Add(PictureBox1); + Controls.Add(Button1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } - #endregion - // // The following code example demonstrates constructing how to construct // a new Bitmap from a file. @@ -116,24 +109,22 @@ private void InitializeComponent() // Bitmap bitmap1; - private void InitializeBitmap() + private void InitializeBitmap(string filePath) { try { - bitmap1 = (Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\" + - @"All Users\Documents\My Music\music.bmp"); + bitmap1 = (Bitmap)Bitmap.FromFile(filePath); PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize; PictureBox1.Image = bitmap1; } - catch(System.IO.FileNotFoundException) + catch (System.IO.FileNotFoundException) { - MessageBox.Show("There was an error." + - "Check the path to the bitmap."); + MessageBox.Show("There was an error. Check the path to the bitmap."); } } // - private void Button1_Click(System.Object sender, System.EventArgs e) + private void Button1_Click(object sender, EventArgs e) { if (bitmap1 != null) @@ -153,11 +144,10 @@ private void Button1_Click(System.Object sender, System.EventArgs e) // a form that contains a button named Button2. Paste the code into the // form and associate this method with the button's Click event. // - private void Button2_Click(System.Object sender, System.EventArgs e) + private void Button2_Click(object sender, EventArgs e) { - Bitmap bitmap1 = Bitmap.FromHicon(SystemIcons.Hand.Handle); - Graphics formGraphics = this.CreateGraphics(); + Graphics formGraphics = CreateGraphics(); GraphicsUnit units = GraphicsUnit.Point; RectangleF bmpRectangleF = bitmap1.GetBounds(ref units); @@ -179,70 +169,76 @@ private void InitializeStreamBitmap() { try { - System.Net.WebRequest request = - System.Net.WebRequest.Create( - "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif"); - System.Net.WebResponse response = request.GetResponse(); - System.IO.Stream responseStream = - response.GetResponseStream(); - Bitmap bitmap2 = new Bitmap(responseStream); + using System.Net.Http.HttpClient client = new(); + using System.Net.Http.HttpResponseMessage response = + client.GetAsync("http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif") + .GetAwaiter() + .GetResult(); + response.EnsureSuccessStatusCode(); + using System.IO.Stream responseStream = + response.Content.ReadAsStreamAsync() + .GetAwaiter() + .GetResult(); + Bitmap bitmap2 = new(responseStream); PictureBox1.Image = bitmap2; } - catch(System.Net.WebException) + catch (System.Net.Http.HttpRequestException) { - MessageBox.Show("There was an error opening the image file." - + "Check the URL"); + MessageBox.Show("There was an error opening the image file. Check the URL"); } } // - // The following code example demonstrates how to use the Image.PixelFormat, + + // The following code example demonstrates how to use the Image.PixelFormat, // Image.Height, Image.Width, and BitmapData.Scan0 properties; the Bitmap.LockBits // and Bitmap.UnlockBits methods; and the ImageLockMode enumeration. // This example is designed to be used with Windows // Forms. To run this example, paste it into a form and handle the form's Paint event by // calling the LockUnlockBitsExample method, passing e as PaintEventArgs. // This example assumes the existence of an 24bpp image file named fakePhoto.jpg at c:\. + // - private void LockUnlockBitsExample(PaintEventArgs e) - { + private static void LockUnlockBitsExample(PaintEventArgs e) + { + // Create a new bitmap. + Bitmap bmp = new("c:\\fakePhoto.jpg"); - // Create a new bitmap. - Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg"); + // Lock the bitmap's bits. + Rectangle rect = new(0, 0, bmp.Width, bmp.Height); + System.Drawing.Imaging.BitmapData bmpData = + bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, + bmp.PixelFormat); - // Lock the bitmap's bits. - Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); - System.Drawing.Imaging.BitmapData bmpData = - bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, - bmp.PixelFormat); + // Get the address of the first line. + IntPtr ptr = bmpData.Scan0; - // Get the address of the first line. - IntPtr ptr = bmpData.Scan0; + // Declare an array to hold the bytes of the bitmap. + int bytes = Math.Abs(bmpData.Stride) * bmp.Height; + byte[] rgbValues = new byte[bytes]; - // Declare an array to hold the bytes of the bitmap. - int bytes = Math.Abs(bmpData.Stride) * bmp.Height; - byte[] rgbValues = new byte[bytes]; + // Copy the RGB values into the array. + System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); - // Copy the RGB values into the array. - System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); + // Set every third value to 255. A 24bpp bitmap will look red. + for (int counter = 2; counter < rgbValues.Length; counter += 3) + { + rgbValues[counter] = 255; + } - // Set every third value to 255. A 24bpp bitmap will look red. - for (int counter = 2; counter < rgbValues.Length; counter += 3) - rgbValues[counter] = 255; + // Copy the RGB values back to the bitmap + System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); - // Copy the RGB values back to the bitmap - System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes); + // Unlock the bits. + bmp.UnlockBits(bmpData); - // Unlock the bits. - bmp.UnlockBits(bmpData); + // Draw the modified image. + e.Graphics.DrawImage(bmp, 0, 150); + } - // Draw the modified image. - e.Graphics.DrawImage(bmp, 0, 150); - } - // - public static void Main() + public static void Run() { - Application.Run(new Form1()); + Application.Run(new BitmapConstructorForm1()); } } diff --git a/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.cs b/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.cs index bad98ae4d75..c7420722da0 100644 --- a/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.cs +++ b/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.cs @@ -2,66 +2,67 @@ using System.Drawing; using System.Windows.Forms; -public class Form1: - System.Windows.Forms.Form +public class BitmapConstructorForm11 : Form { - #region " Windows Form Designer generated code " - - public Form1() : base() - { + public BitmapConstructorForm11() : base() + { - //This call is required by the Windows Form Designer. + // This call is required by the Windows Form Designer. InitializeComponent(); - //Add any initialization after the InitializeComponent() call + // Add any initialization after the InitializeComponent() call. } - //Form overrides dispose to clean up the component list. + // Form overrides Dispose to clean up the component list. protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } - //Required by the Windows Form Designer - private System.ComponentModel.IContainer components; + // Required by the Windows Form Designer. + private System.ComponentModel.IContainer components = null; - //NOTE: The following procedure is required by the Windows Form Designer - //It can be modified using the Windows Form Designer. - //Do not modify it using the code editor. + // NOTE: The following procedure is required by the Windows Form Designer. + // It can be modified using the Windows Form Designer. + // Do not modify it using the code editor. [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { // // Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Name = "Form1"; - this.Text = "Form1"; - this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); + ClientSize = new Size(292, 266); + Name = "Form1"; + Text = "Form1"; + Paint += new PaintEventHandler(Form1_Paint); } - #endregion - // - private void ConstructFromResourceSaveAsGif(PaintEventArgs e) + private static void ConstructFromResourceSaveAsGif(PaintEventArgs e) { - // Construct a bitmap from the button image resource. - Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp"); + string resourceName = "Button.bmp"; + Bitmap bmp1; + try + { + bmp1 = new(typeof(Button), resourceName); + } + catch (ArgumentException ex) + { + MessageBox.Show($"The resource '{resourceName}' was not found. {ex.Message}"); + return; + } // Save the image as a GIF. bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif); // Construct a new image from the GIF file. - Bitmap bmp2 = new Bitmap("c:\\button.gif"); + Bitmap bmp2 = new("c:\\button.gif"); // Draw the two images. e.Graphics.DrawImage(bmp1, new Point(10, 10)); @@ -73,9 +74,9 @@ private void ConstructFromResourceSaveAsGif(PaintEventArgs e) } // - public static void Main() + public static void Run() { - Application.Run(new Form1()); + Application.Run(new BitmapConstructorForm11()); } private void Form1_Paint(object sender, PaintEventArgs e) diff --git a/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.resx b/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.resx new file mode 100644 index 00000000000..1af7de150c9 --- /dev/null +++ b/snippets/csharp/System.Drawing/Bitmap/.ctor/form11.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/snippets/csharp/System.Drawing/Bitmap/.ctor/form12.cs b/snippets/csharp/System.Drawing/Bitmap/.ctor/form12.cs index 53eb463d0c9..849dc2e2365 100644 --- a/snippets/csharp/System.Drawing/Bitmap/.ctor/form12.cs +++ b/snippets/csharp/System.Drawing/Bitmap/.ctor/form12.cs @@ -1,81 +1,71 @@ -using System.Drawing; -using System; +using System; +using System.Drawing; +using System.Drawing.Imaging; using System.Windows.Forms; -using System.Drawing.Drawing2D; - -public class Form1: - System.Windows.Forms.Form +public class BitmapConstructorForm12 : Form { - #region " Windows Form Designer generated code " - - public Form1() : base() - { - - //This call is required by the Windows Form Designer. + public BitmapConstructorForm12() : base() + { + // This call is required by the Windows Form Designer. InitializeComponent(); PopulateListBoxWithFonts(); PopulateListBoxWithGraphicsResolution(); - this.Paint += new PaintEventHandler(Form1_Paint); - this.Button1.Click += new EventHandler(Button1_Click); - - //Add any initialization after the InitializeComponent() call + Paint += new PaintEventHandler(Form1_Paint); + Button1.Click += new EventHandler(Button1_Click); + + // Add any initialization after the InitializeComponent() call. } - //Form overrides dispose to clean up the component list. + // Form overrides Dispose to clean up the component list. protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } - //Required by the Windows Form Designer - private System.ComponentModel.IContainer components; + // Required by the Windows Form Designer. + private System.ComponentModel.IContainer components = null; - //NOTE: The following procedure is required by the Windows Form Designer - //It can be modified using the Windows Form Designer. - //Do not modify it using the code editor. - internal System.Windows.Forms.ListBox listBox1; - internal System.Windows.Forms.Button Button1; + // NOTE: The following procedure is required by the Windows Form Designer. + // It can be modified using the Windows Form Designer. + // Do not modify it using the code editor. + internal ListBox listBox1; + internal Button Button1; [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.listBox1 = new System.Windows.Forms.ListBox(); - this.Button1 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + listBox1 = new ListBox(); + Button1 = new Button(); + SuspendLayout(); // //listBox1 // - this.listBox1.Location = new System.Drawing.Point(88, 112); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(120, 95); - this.listBox1.TabIndex = 0; + listBox1.Location = new Point(88, 112); + listBox1.Name = "listBox1"; + listBox1.Size = new Size(120, 95); + listBox1.TabIndex = 0; // //Button1 // - this.Button1.Location = new System.Drawing.Point(120, 24); - this.Button1.Name = "Button1"; - this.Button1.TabIndex = 1; - this.Button1.Text = "Button1"; + Button1.Location = new Point(120, 24); + Button1.Name = "Button1"; + Button1.TabIndex = 1; + Button1.Text = "Button1"; // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Button1); - this.Controls.Add(this.listBox1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new Size(292, 266); + Controls.Add(Button1); + Controls.Add(listBox1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } - #endregion - // The following code example shows all the font families in the // Families property of the FontFamily class. This example is // designed to be used with a Windows Form. To run this example, @@ -86,7 +76,7 @@ private void PopulateListBoxWithFonts() { listBox1.Width = 200; listBox1.Location = new Point(40, 120); - foreach ( FontFamily oneFontFamily in FontFamily.Families ) + foreach (FontFamily oneFontFamily in FontFamily.Families) { listBox1.Items.Add(oneFontFamily.Name); } @@ -101,11 +91,11 @@ private void PopulateListBoxWithFonts() private void PopulateListBoxWithGraphicsResolution() { Graphics boxGraphics = listBox1.CreateGraphics(); - Graphics formGraphics = this.CreateGraphics(); + Graphics formGraphics = CreateGraphics(); - listBox1.Items.Add("ListBox horizontal resolution: " + listBox1.Items.Add("ListBox horizontal resolution: " + boxGraphics.DpiX); - listBox1.Items.Add("ListBox vertical resolution: " + listBox1.Items.Add("ListBox vertical resolution: " + boxGraphics.DpiY); boxGraphics.Dispose(); @@ -126,16 +116,17 @@ private void ShowHotKey(PaintEventArgs e) string text = "&Click Here"; // Declare a new StringFormat. - StringFormat format = new StringFormat(); - - // Set the HotkeyPrefix property. - format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; + StringFormat format = new StringFormat + { + // Set the HotkeyPrefix property. + HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show + }; // Draw the string. - Brush theBrush = + Brush theBrush = SystemBrushes.FromSystemColor(SystemColors.Highlight); - e.Graphics.DrawString(text, this.Font, theBrush, 30, 40, format); + e.Graphics.DrawString(text, Font, theBrush, 30, 40, format); } // @@ -155,29 +146,27 @@ private void ShowHotKey(PaintEventArgs e) // private void AddShadow(PaintEventArgs e) { - // Create two SizeF objects. SizeF shadowSize = listBox1.Size; - SizeF addSize = new SizeF(10.5F, 20.8F); + SizeF addSize = new(10.5F, 20.8F); // Add them together and save the result in shadowSize. - shadowSize = shadowSize + addSize; + shadowSize += addSize; // Get the location of the ListBox and convert it to a PointF. PointF shadowLocation = listBox1.Location; // Add two points to get a new location. - shadowLocation = shadowLocation + new Size(5, 5); + shadowLocation += new Size(5, 5); // Create a rectangleF. - RectangleF rectFToFill = - new RectangleF(shadowLocation, shadowSize); + RectangleF rectFToFill = new(shadowLocation, shadowSize); // Create a custom brush using a semi-transparent color, and // then fill in the rectangle. Color customColor = Color.FromArgb(50, Color.Gray); SolidBrush shadowBrush = new SolidBrush(customColor); - e.Graphics.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill}); + e.Graphics.FillRectangles(shadowBrush, [rectFToFill]); // Dispose of the brush. shadowBrush.Dispose(); @@ -190,26 +179,24 @@ private void AddShadow(PaintEventArgs e) // Create a form and paste the following code into it. Call the // DrawVerticalStringFromBottomUp method in the form's Paint // event-handling method, passing e as PaintEventArgs. + // public void DrawVerticalStringFromBottomUp(PaintEventArgs e) { - // Create the string to draw on the form. string text = "Can you read this?"; // Create a GraphicsPath. - System.Drawing.Drawing2D.GraphicsPath path = - new System.Drawing.Drawing2D.GraphicsPath(); + System.Drawing.Drawing2D.GraphicsPath path = new(); // Add the string to the path; declare the font, font style, size, and // vertical format for the string. - path.AddString(text, this.Font.FontFamily, 1, 15, - new PointF(0.0F, 0.0F), + path.AddString(text, Font.FontFamily, 1, 15, + new PointF(0.0F, 0.0F), new StringFormat(StringFormatFlags.DirectionVertical)); // Declare a matrix that will be used to rotate the text. - System.Drawing.Drawing2D.Matrix rotateMatrix = - new System.Drawing.Drawing2D.Matrix(); + System.Drawing.Drawing2D.Matrix rotateMatrix = new(); // Set the rotation angle and starting point for the text. rotateMatrix.RotateAt(180.0F, new PointF(10.0F, 100.0F)); @@ -218,7 +205,7 @@ public void DrawVerticalStringFromBottomUp(PaintEventArgs e) path.Transform(rotateMatrix); // Set the SmoothingMode to high quality for best readability. - e.Graphics.SmoothingMode = + e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // Fill in the path to draw the string. @@ -234,13 +221,14 @@ public void DrawVerticalStringFromBottomUp(PaintEventArgs e) // designed to be used with Windows Forms. Create a form and paste // the following code into it. Call the DisplayKnownColors method in the // form's Paint event-handling method, passing e as PaintEventArgs. + // private void DisplayKnownColors(PaintEventArgs e) { - this.Size = new Size(650, 550); - + Size = new Size(650, 550); + // Get all the values from the KnownColor enumeration. - System.Array colorsArray = Enum.GetValues(typeof(KnownColor)); + Array colorsArray = Enum.GetValues(); KnownColor[] allColors = new KnownColor[colorsArray.Length]; Array.Copy(colorsArray, allColors, colorsArray.Length); @@ -250,9 +238,8 @@ private void DisplayKnownColors(PaintEventArgs e) float y = 0; float x = 10.0F; - for(int i = 0; i < allColors.Length; i++) + for (int i = 0; i < allColors.Length; i++) { - // If x is a multiple of 30, start a new column. if (i > 0 && i % 30 == 0) { @@ -267,10 +254,9 @@ private void DisplayKnownColors(PaintEventArgs e) // Create a custom brush from the color and use it to draw // the brush's name. - SolidBrush aBrush = - new SolidBrush(Color.FromName(allColors[i].ToString())); - e.Graphics.DrawString(allColors[i].ToString(), - this.Font, aBrush, x, y); + SolidBrush aBrush = new(Color.FromName(allColors[i].ToString())); + e.Graphics.DrawString(allColors[i].ToString(), + Font, aBrush, x, y); // Dispose of the custom brush. aBrush.Dispose(); @@ -283,13 +269,13 @@ private void DisplayKnownColors(PaintEventArgs e) // Create a form and paste the following code into it. Call the // FillEmptyRegion method in the form's Paint event-handling method, // passing e as PaintEventArgs. + // - private void FillEmptyRegion(PaintEventArgs e) + private static void FillEmptyRegion(PaintEventArgs e) { - // Create a region from a rectangle. - Rectangle originalRectangle = new Rectangle(40, 40, 40, 50); - Region smallRegion = new Region(originalRectangle); + Rectangle originalRectangle = new(40, 40, 40, 50); + Region smallRegion = new(originalRectangle); // Call MakeEmpty. smallRegion.MakeEmpty(); @@ -306,12 +292,13 @@ private void FillEmptyRegion(PaintEventArgs e) // Create a form and paste the following code into it. Call the // FillInfiniteRegion method in the form's Paint event-handling method, // passing e as PaintEventArgs. + // - private void FillInfiniteRegion(PaintEventArgs e) + private static void FillInfiniteRegion(PaintEventArgs e) { // Create a region from a rectangle. - Rectangle originalRectangle = new Rectangle(40, 40, 40, 50); - Region smallRegion = new Region(originalRectangle); + Rectangle originalRectangle = new(40, 40, 40, 50); + Region smallRegion = new(originalRectangle); // Call MakeInfinite. smallRegion.MakeInfinite(); @@ -328,11 +315,12 @@ private void FillInfiniteRegion(PaintEventArgs e) // Create a form and paste the following code into it. Call the // IconToBitmap method in the form's Paint event-handling method, // passing e as PaintEventArgs. + // - private void IconToBitmap(PaintEventArgs e) + private static void IconToBitmap(PaintEventArgs e) { // Construct an Icon. - Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40); + Icon icon1 = new(SystemIcons.Exclamation, 40, 40); // Call ToBitmap to convert it. Bitmap bmp = icon1.ToBitmap(); @@ -347,23 +335,21 @@ private void IconToBitmap(PaintEventArgs e) // with Windows Forms. Create a form and paste the following code // into it. Call the TranslateAndTransform method in the form's // Paint event-handling method, passing e as PaintEventArgs. + // private void TranslateAndTransform(PaintEventArgs e) { - // Create a GraphicsPath. - System.Drawing.Drawing2D.GraphicsPath myPath = - new System.Drawing.Drawing2D.GraphicsPath(); + System.Drawing.Drawing2D.GraphicsPath myPath = new(); // Create a rectangle. - RectangleF layoutRectangle = - new RectangleF(20.0F, 20.0F, 40.0F, 50.0F); + RectangleF layoutRectangle = new(20.0F, 20.0F, 40.0F, 50.0F); // Add the rectangle to the path. myPath.AddRectangle(layoutRectangle); // Add a string to the path. - myPath.AddString("Path", this.Font.FontFamily, 2, 10.0F, + myPath.AddString("Path", Font.FontFamily, 2, 10.0F, layoutRectangle, new StringFormat(StringFormatFlags.NoWrap)); // Draw the path. @@ -376,9 +362,9 @@ private void TranslateAndTransform(PaintEventArgs e) // [STAThread] - public static void Main() + public static void Run() { - Application.Run(new Form1()); + Application.Run(new BitmapConstructorForm12()); } private void Form1_Paint(object sender, PaintEventArgs e) @@ -399,32 +385,33 @@ private void Form1_Paint(object sender, PaintEventArgs e) // used with Windows Forms. Create a form containing a button named // Button1 and paste the following code into it. Associate the // Button1_Click method with the button's Click event. + // - private void Button1_Click(System.Object sender, System.EventArgs e) + private void Button1_Click(object sender, EventArgs e) { if (Button1.Font.Style != FontStyle.Bold) - Button1.Font = new Font(FontFamily.GenericSansSerif, - 12.0F, FontStyle.Bold); + Button1.Font = new Font(FontFamily.GenericSansSerif, + 12.0F, FontStyle.Bold); } // -// The following code example demonstrates how to construct a Region + // The following code example demonstrates how to construct a Region // using the RegionData class. This example is designed to be used with Windows // Forms. To run this example paste it into a form and handle the form's Paint event // by calling the DemonstrateRegionData method, passing e as PaintEventArgs. + // private void DemonstrateRegionData(PaintEventArgs e) { - //Create a simple region. - Region region1 = new Region(new Rectangle(10, 10, 100, 100)); + Region region1 = new(new Rectangle(10, 10, 100, 100)); // Extract the region data. System.Drawing.Drawing2D.RegionData region1Data = region1.GetRegionData(); // Create a new region using the region data. - Region region2 = new Region(region1Data); + Region region2 = new(region1Data); // Dispose of the first region. region1.Dispose(); @@ -433,23 +420,23 @@ private void DemonstrateRegionData(PaintEventArgs e) e.Graphics.ExcludeClip(region2); // Fill in the client rectangle. - e.Graphics.FillRectangle(Brushes.Red, this.ClientRectangle); + e.Graphics.FillRectangle(Brushes.Red, ClientRectangle); region2.Dispose(); } // -// The following code example demonstrates how use the Data from + // The following code example demonstrates how use the Data from // one region to set the Data for another region. This example is designed // to be used with Windows Forms. To run this example paste // it into a form and handle the form's Paint event // by calling the DemonstrateRegionData2 method, passing e as PaintEventArgs. + // private void DemonstrateRegionData2(PaintEventArgs e) { - //Create a simple region. - Region region1 = new Region(new Rectangle(10, 10, 100, 100)); + Region region1 = new(new Rectangle(10, 10, 100, 100)); // Extract the region data. System.Drawing.Drawing2D.RegionData region1Data = region1.GetRegionData(); @@ -457,7 +444,7 @@ private void DemonstrateRegionData2(PaintEventArgs e) data1 = region1Data.Data; // Create a second region. - Region region2 = new Region(); + Region region2 = new(); // Get the region data for the second region. System.Drawing.Drawing2D.RegionData region2Data = region2.GetRegionData(); @@ -466,7 +453,7 @@ private void DemonstrateRegionData2(PaintEventArgs e) region2Data.Data = data1; // Construct a third region using the modified RegionData of the second region. - Region region3 = new Region(region2Data); + Region region3 = new(region2Data); // Dispose of the first and second regions. region1.Dispose(); @@ -476,30 +463,29 @@ private void DemonstrateRegionData2(PaintEventArgs e) e.Graphics.ExcludeClip(region3); // Fill in the client rectangle. - e.Graphics.FillRectangle(Brushes.Red, this.ClientRectangle); + e.Graphics.FillRectangle(Brushes.Red, ClientRectangle); region3.Dispose(); } // - // - private void BitmapConstructorEx(PaintEventArgs e) - { + // + private static void BitmapConstructorEx(PaintEventArgs e) + { + // Create a bitmap. + Bitmap bmp = new("c:\\fakePhoto.jpg"); - // Create a bitmap. - Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg"); - - // Retrieve the bitmap data from the bitmap. - System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), - ImageLockMode.ReadOnly, bmp.PixelFormat); + // Retrieve the bitmap data from the bitmap. + BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), + ImageLockMode.ReadOnly, bmp.PixelFormat); - //Create a new bitmap. - Bitmap newBitmap = new Bitmap(200, 200, bmpData.Stride, bmp.PixelFormat, bmpData.Scan0); + //Create a new bitmap. + Bitmap newBitmap = new(200, 200, bmpData.Stride, bmp.PixelFormat, bmpData.Scan0); - bmp.UnlockBits(bmpData); + bmp.UnlockBits(bmpData); - // Draw the new bitmap. - e.Graphics.DrawImage(newBitmap, 10, 10); - } - // + // Draw the new bitmap. + e.Graphics.DrawImage(newBitmap, 10, 10); + } + // } diff --git a/snippets/csharp/System.Drawing/Bitmap/Clone/form1.cs b/snippets/csharp/System.Drawing/Bitmap/Clone/form1.cs index 5904b841b1a..2520d3a6ea1 100644 --- a/snippets/csharp/System.Drawing/Bitmap/Clone/form1.cs +++ b/snippets/csharp/System.Drawing/Bitmap/Clone/form1.cs @@ -1,16 +1,16 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; using System.Runtime.InteropServices; +using System.Windows.Forms; namespace System.Drawing.ClassicBitmapExamplesCS { - /// - /// Summary description for Form1. - /// + /// + /// Summary description for Form1. + /// internal class Form1 : System.Windows.Forms.Form { @@ -38,10 +38,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -56,10 +53,10 @@ private void InitializeComponent() // // Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Name = "Form1"; - this.Text = "Form1"; - this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); + ClientSize = new System.Drawing.Size(292, 266); + Name = "Form1"; + Text = "Form1"; + Paint += new System.Windows.Forms.PaintEventHandler(Form1_Paint); } #endregion // @@ -163,7 +160,7 @@ private void GetHicon_Example(PaintEventArgs e) Icon newIcon = Icon.FromHandle(Hicon); // Set the form Icon attribute to the new icon. - this.Icon = newIcon; + Icon = newIcon; // You can now destroy the icon, since the form creates // its own copy of the icon accessible through the Form.Icon property. diff --git a/snippets/csharp/System.Drawing/Bitmap/Overview/form1.cs b/snippets/csharp/System.Drawing/Bitmap/Overview/form1.cs index 4847a80f989..446142f3d7b 100644 --- a/snippets/csharp/System.Drawing/Bitmap/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/Bitmap/Overview/form1.cs @@ -1,25 +1,25 @@ using System; using System.Drawing; -using System.Windows.Forms; using System.Drawing.Imaging; +using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.Button1.Click += new EventHandler(Button1_Click); - this.Button2.Click += new EventHandler(Button2_Click); - this.Button3.Click += new EventHandler(Button3_Click); - this.Button4.Click += new EventHandler(Button4_Click); - this.Button5.Click += new EventHandler(Button5_Click); - + Button1.Click += new EventHandler(Button1_Click); + Button2.Click += new EventHandler(Button2_Click); + Button3.Click += new EventHandler(Button3_Click); + Button4.Click += new EventHandler(Button4_Click); + Button5.Click += new EventHandler(Button5_Click); + //Add any initialization after the InitializeComponent() call } @@ -28,10 +28,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -52,79 +49,79 @@ protected override void Dispose(bool disposing) [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.PictureBox1 = new System.Windows.Forms.PictureBox(); - this.Button1 = new System.Windows.Forms.Button(); - this.Button2 = new System.Windows.Forms.Button(); - this.Button3 = new System.Windows.Forms.Button(); - this.Button4 = new System.Windows.Forms.Button(); - this.Label1 = new System.Windows.Forms.Label(); - this.Button5 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + PictureBox1 = new System.Windows.Forms.PictureBox(); + Button1 = new System.Windows.Forms.Button(); + Button2 = new System.Windows.Forms.Button(); + Button3 = new System.Windows.Forms.Button(); + Button4 = new System.Windows.Forms.Button(); + Label1 = new System.Windows.Forms.Label(); + Button5 = new System.Windows.Forms.Button(); + SuspendLayout(); // //PictureBox1 // - this.PictureBox1.Location = new System.Drawing.Point(24, 8); - this.PictureBox1.Name = "PictureBox1"; - this.PictureBox1.Size = new System.Drawing.Size(100, 88); - this.PictureBox1.TabIndex = 0; - this.PictureBox1.TabStop = false; + PictureBox1.Location = new System.Drawing.Point(24, 8); + PictureBox1.Name = "PictureBox1"; + PictureBox1.Size = new System.Drawing.Size(100, 88); + PictureBox1.TabIndex = 0; + PictureBox1.TabStop = false; // //Button1 // - this.Button1.Location = new System.Drawing.Point(192, 8); - this.Button1.Name = "Button1"; - this.Button1.TabIndex = 2; - this.Button1.Text = "Button1"; + Button1.Location = new System.Drawing.Point(192, 8); + Button1.Name = "Button1"; + Button1.TabIndex = 2; + Button1.Text = "Button1"; // //Button2 // - this.Button2.Location = new System.Drawing.Point(192, 40); - this.Button2.Name = "Button2"; - this.Button2.TabIndex = 3; - this.Button2.Text = "Button2"; + Button2.Location = new System.Drawing.Point(192, 40); + Button2.Name = "Button2"; + Button2.TabIndex = 3; + Button2.Text = "Button2"; // //Button3 // - this.Button3.Location = new System.Drawing.Point(192, 72); - this.Button3.Name = "Button3"; - this.Button3.TabIndex = 4; - this.Button3.Text = "Button3"; + Button3.Location = new System.Drawing.Point(192, 72); + Button3.Name = "Button3"; + Button3.TabIndex = 4; + Button3.Text = "Button3"; // //Button4 // - this.Button4.Location = new System.Drawing.Point(192, 104); - this.Button4.Name = "Button4"; - this.Button4.TabIndex = 5; - this.Button4.Text = "Button4"; + Button4.Location = new System.Drawing.Point(192, 104); + Button4.Name = "Button4"; + Button4.TabIndex = 5; + Button4.Text = "Button4"; // //Label1 // - this.Label1.Location = new System.Drawing.Point(24, 72); - this.Label1.Name = "Label1"; - this.Label1.Size = new System.Drawing.Size(152, 32); - this.Label1.TabIndex = 6; - this.Label1.Text = "Label1"; + Label1.Location = new System.Drawing.Point(24, 72); + Label1.Name = "Label1"; + Label1.Size = new System.Drawing.Size(152, 32); + Label1.TabIndex = 6; + Label1.Text = "Label1"; // //Button5 // - this.Button5.Location = new System.Drawing.Point(200, 136); - this.Button5.Name = "Button5"; - this.Button5.TabIndex = 7; - this.Button5.Text = "Button5"; + Button5.Location = new System.Drawing.Point(200, 136); + Button5.Name = "Button5"; + Button5.TabIndex = 7; + Button5.Text = "Button5"; // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Button5); - this.Controls.Add(this.Label1); - this.Controls.Add(this.Button4); - this.Controls.Add(this.Button3); - this.Controls.Add(this.Button2); - this.Controls.Add(this.Button1); - this.Controls.Add(this.PictureBox1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new System.Drawing.Size(292, 266); + Controls.Add(Button5); + Controls.Add(Label1); + Controls.Add(Button4); + Controls.Add(Button3); + Controls.Add(Button2); + Controls.Add(Button1); + Controls.Add(PictureBox1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion @@ -140,21 +137,21 @@ private void InitializeComponent() // Bitmap image1; - private void Button1_Click(System.Object sender, System.EventArgs e) + private void Button1_Click(object sender, System.EventArgs e) { try { // Retrieve the image. - image1 = new Bitmap(@"C:\Documents and Settings\All Users\" + image1 = new Bitmap(@"C:\Documents and Settings\All Users\" + @"Documents\My Music\music.bmp", true); int x, y; // Loop through the images pixels to reset color. - for(x=0; x - private void Button2_Click(System.Object sender, System.EventArgs e) + private void Button2_Click(object sender, System.EventArgs e) { try { - Bitmap image1 = (Bitmap) Image.FromFile(@"C:\Documents and Settings\" + + Bitmap image1 = (Bitmap)Image.FromFile(@"C:\Documents and Settings\" + @"All Users\Documents\My Music\music.bmp", true); - TextureBrush texture = new TextureBrush(image1); - texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile; - Graphics formGraphics = this.CreateGraphics(); - formGraphics.FillEllipse(texture, + TextureBrush texture = new TextureBrush(image1) + { + WrapMode = System.Drawing.Drawing2D.WrapMode.Tile + }; + Graphics formGraphics = CreateGraphics(); + formGraphics.FillEllipse(texture, new RectangleF(90.0F, 110.0F, 100, 100)); formGraphics.Dispose(); } - catch(System.IO.FileNotFoundException) + catch (System.IO.FileNotFoundException) { MessageBox.Show("There was an error opening the bitmap." + "Please check the path."); @@ -213,12 +212,14 @@ private void Button2_Click(System.Object sender, System.EventArgs e) // form and associate the Button3_Click method with the button's // Click event. // - private void Button3_Click(System.Object sender, System.EventArgs e) + private void Button3_Click(object sender, System.EventArgs e) { Graphics buttonGraphics = Button3.CreateGraphics(); - Pen myPen = new Pen(Color.ForestGreen, 4.0F); - myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; + Pen myPen = new Pen(Color.ForestGreen, 4.0F) + { + DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot + }; Rectangle theRectangle = Button3.ClientRectangle; theRectangle.Inflate(-2, -2); @@ -235,7 +236,7 @@ private void Button3_Click(System.Object sender, System.EventArgs e) // Paste the code into the form and associate // the Button4_Click method with the button's Click event. // - private void Button4_Click(System.Object sender, System.EventArgs e) + private void Button4_Click(object sender, System.EventArgs e) { Graphics buttonGraphics = Button4.CreateGraphics(); @@ -251,7 +252,7 @@ private void Button4_Click(System.Object sender, System.EventArgs e) // Paste the code to the form and associate // the Button5_Click method with button's Click event. // - private void Button5_Click(System.Object sender, System.EventArgs e) + private void Button5_Click(object sender, System.EventArgs e) { try { @@ -261,7 +262,7 @@ private void Button5_Click(System.Object sender, System.EventArgs e) Button5.Text = "Saved file."; } } - catch(Exception) + catch (Exception) { MessageBox.Show("There was a problem saving the file." + "Check the file permissions."); @@ -300,13 +301,13 @@ private void ExtractMetaData(PaintEventArgs e) // For each PropertyItem in the array, display the id, // type, and length. int count = 0; - foreach ( PropertyItem propItem in propItems ) + foreach (PropertyItem propItem in propItems) { - e.Graphics.DrawString("Property Item " + + e.Graphics.DrawString("Property Item " + count.ToString(), font1, blackBrush, X, Y); Y += font1.Height; - e.Graphics.DrawString(" ID: 0x" + + e.Graphics.DrawString(" ID: 0x" + propItem.Id.ToString("x"), font1, blackBrush, X, Y); Y += font1.Height; @@ -314,27 +315,27 @@ private void ExtractMetaData(PaintEventArgs e) propItem.Type.ToString(), font1, blackBrush, X, Y); Y += font1.Height; - e.Graphics.DrawString(" length: " + - propItem.Len.ToString() + + e.Graphics.DrawString(" length: " + + propItem.Len.ToString() + " bytes", font1, blackBrush, X, Y); Y += font1.Height; count += 1; } font1.Dispose(); } - catch(Exception) + catch (Exception) { - MessageBox.Show("There was an error." + + MessageBox.Show("There was an error." + "Make sure the path to the image file is valid."); } } // -// + // // The following code example demonstrates how to use the GetPropertyItem // and SetPropertyItem methods. This example is designed to be used with Windows // Forms. To run this example paste it into a form, and handle the form's Paint event // by calling the DemonstratePropertyItem method, passing e as PaintEventArgs. -// + // private void DemonstratePropertyItem(PaintEventArgs e) { diff --git a/snippets/csharp/System.Drawing/Bitmap/SetResolution/Form1.cs b/snippets/csharp/System.Drawing/Bitmap/SetResolution/Form1.cs index ba91926cb1d..fc92576f581 100644 --- a/snippets/csharp/System.Drawing/Bitmap/SetResolution/Form1.cs +++ b/snippets/csharp/System.Drawing/Bitmap/SetResolution/Form1.cs @@ -1,10 +1,10 @@ -using System.Windows.Forms; +using System; +using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; -using System.ComponentModel; using System.Drawing.Text; -using System; +using System.Windows.Forms; public class Form1 : System.Windows.Forms.Form @@ -26,15 +26,15 @@ public Form1() : base() [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - -// Form1 -// - this.ClientSize = new System.Drawing.Size(292, 266); - - this.Name = "Form1"; - this.Text = "Form1"; - this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); - this.ResumeLayout(false); + + // Form1 + // + ClientSize = new System.Drawing.Size(292, 266); + + Name = "Form1"; + Text = "Form1"; + Paint += new System.Windows.Forms.PaintEventHandler(Form1_Paint); + ResumeLayout(false); } #endregion @@ -64,9 +64,11 @@ protected void DrawCaps(PaintEventArgs e) // Create a pen and set end custom start and end // caps to the hook cap. - Pen customCapPen = new Pen(Color.Black, 5); - customCapPen.CustomStartCap = HookCap; - customCapPen.CustomEndCap = HookCap; + Pen customCapPen = new Pen(Color.Black, 5) + { + CustomStartCap = HookCap, + CustomEndCap = HookCap + }; // Create a second pen using the start and end caps from // the hook cap. @@ -78,8 +80,8 @@ protected void DrawCaps(PaintEventArgs e) capPen.EndCap = endCap; // Create a line to draw. - Point[] points = { new Point(100, 100), new Point(200, 50), - new Point(250, 300) }; + Point[] points = [ new Point(100, 100), new Point(200, 50), + new Point(250, 300) ]; // Draw the lines. e.Graphics.DrawLines(capPen, points); @@ -92,7 +94,7 @@ private void ExtractAssociatedIconEx() { Icon ico = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe"); - this.Icon = ico; + Icon = ico; } // @@ -153,16 +155,16 @@ private void ShowOutputChannels(PaintEventArgs e) bmp2.Dispose(); } // -// + // private void OpAdditionExample(PaintEventArgs e) { PointF point1 = new PointF(120.5F, 120F); SizeF size1 = new SizeF(120.5F, 30.5F); RectangleF rect1 = new RectangleF(point1, size1); if (new PointF(rect1.Right, rect1.Bottom) == point1 + size1) - e.Graphics.DrawString("They are equal", this.Font, Brushes.Black, rect1); + e.Graphics.DrawString("They are equal", Font, Brushes.Black, rect1); else - e.Graphics.DrawString("They are not equal", this.Font, Brushes.Red, rect1); + e.Graphics.DrawString("They are not equal", Font, Brushes.Red, rect1); } // @@ -174,9 +176,9 @@ private void AddExample(PaintEventArgs e) RectangleF rect1 = new RectangleF(point1, size1); PointF point2 = new PointF(rect1.Right, rect1.Bottom); if (point2 != PointF.Add(point1, size1)) - e.Graphics.DrawString("They are not equal", this.Font, Brushes.Red, rect1); + e.Graphics.DrawString("They are not equal", Font, Brushes.Red, rect1); else - e.Graphics.DrawString("They are equal", this.Font, Brushes.Black, rect1); + e.Graphics.DrawString("They are equal", Font, Brushes.Black, rect1); } // @@ -208,12 +210,12 @@ private void ShearColors(PaintEventArgs e) int width = image.Width; int height = image.Height; - float[][] colorMatrixElements = { - new float[] {1, 0, 0, 0, 0}, - new float[] {0, 1, 0, 0, 0}, - new float[] {0.5f, 0, 1, 0, 0}, - new float[] {0, 0, 0, 1, 0}, - new float[] {0, 0, 0, 0, 1}}; + float[][] colorMatrixElements = [ + [1, 0, 0, 0, 0], + [0, 1, 0, 0, 0], + [0.5f, 0, 1, 0, 0], + [0, 0, 0, 1, 0], + [0, 0, 0, 0, 1]]; ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); @@ -234,54 +236,54 @@ private void ShearColors(PaintEventArgs e) imageAttributes); // } - // - InstalledFontCollection ifc = new InstalledFontCollection(); - private void EnumerateInstalledFonts(PaintEventArgs e) + // + InstalledFontCollection ifc = new InstalledFontCollection(); + private void EnumerateInstalledFonts(PaintEventArgs e) + { + FontFamily[] families = ifc.Families; + float x = 0.0F; + float y = 0.0F; + for (int i = 0; i < ifc.Families.Length; i++) { - FontFamily[] families = ifc.Families; - float x = 0.0F; - float y = 0.0F; - for (int i = 0; i < ifc.Families.Length; i++) + if (ifc.Families[i].IsStyleAvailable(FontStyle.Regular)) { - if (ifc.Families[i].IsStyleAvailable(FontStyle.Regular)) + e.Graphics.DrawString(ifc.Families[i].Name, new Font(ifc.Families[i], 12), + Brushes.Black, x, y); + y += 20; + if (y % 700 == 0) { - e.Graphics.DrawString(ifc.Families[i].Name, new Font(ifc.Families[i], 12), - Brushes.Black, x, y); - y += 20; - if (y % 700 == 0) - { - x += 140; - y = 0; - } + x += 140; + y = 0; } } } - // + } + // + + // + private void ConstructFontWithString(PaintEventArgs e) + { + Font font1 = new Font("Arial", 20); + e.Graphics.DrawString("Arial Font", font1, Brushes.Red, new PointF(10, 10)); + } + // + public static Bitmap ResizeImage(System.Drawing.Image image) + { + // + Bitmap bitmap = new Bitmap(100, 100); + bitmap.SetResolution(96.0F, 96.0F); + // - // - private void ConstructFontWithString(PaintEventArgs e) + using (Graphics graphics = Graphics.FromImage(bitmap)) { - Font font1 = new Font("Arial", 20); - e.Graphics.DrawString("Arial Font", font1, Brushes.Red, new PointF(10, 10)); + graphics.DrawImage(image, + new Rectangle(0, 0, 100, 100), + new Rectangle(0, 0, image.Width, image.Height), + GraphicsUnit.Pixel); } - // - public static Bitmap ResizeImage(System.Drawing.Image image) - { - // - Bitmap bitmap = new Bitmap(100, 100); - bitmap.SetResolution(96.0F, 96.0F); - // - using (Graphics graphics = Graphics.FromImage(bitmap)) - { - graphics.DrawImage(image, - new Rectangle(0, 0, 100, 100), - new Rectangle(0, 0, image.Width, image.Height), - GraphicsUnit.Pixel); - } - - return bitmap; - } + return bitmap; + } // public bool ThumbnailCallback() { diff --git a/snippets/csharp/System.Drawing/Brushes/Overview/form1.cs b/snippets/csharp/System.Drawing/Brushes/Overview/form1.cs index 14974d8c6db..79d107a8987 100644 --- a/snippets/csharp/System.Drawing/Brushes/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/Brushes/Overview/form1.cs @@ -1,19 +1,19 @@ -using System.Drawing.Drawing2D; +using System; using System.Drawing; -using System; +using System.Drawing.Drawing2D; using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.Paint += new PaintEventHandler(Form1_Paint); + Paint += new PaintEventHandler(Form1_Paint); Button1.Click += new EventHandler(Button1_Click); DrawFirstRectangle(); @@ -25,10 +25,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -43,23 +40,23 @@ protected override void Dispose(bool disposing) [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.Button1 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + Button1 = new System.Windows.Forms.Button(); + SuspendLayout(); // //Button1 // - this.Button1.Location = new System.Drawing.Point(208, 16); - this.Button1.Name = "Button1"; - this.Button1.TabIndex = 0; - this.Button1.Text = "Button1"; + Button1.Location = new System.Drawing.Point(208, 16); + Button1.Name = "Button1"; + Button1.TabIndex = 0; + Button1.Text = "Button1"; // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Button1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new System.Drawing.Size(292, 266); + Controls.Add(Button1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion @@ -78,7 +75,7 @@ private void CreateARectangleFromLTRB(PaintEventArgs e) private void Form1_Paint(object sender, PaintEventArgs e) { - + //ConvertRectangleToRectangleF(e) //RoundingAndTruncatingRectangles(e); } @@ -120,7 +117,7 @@ private void InstanceRectangleIntersection(PaintEventArgs e) Rectangle rectangle1 = new Rectangle(50, 50, 200, 100); Rectangle rectangle2 = new Rectangle(70, 20, 100, 200); - + e.Graphics.DrawRectangle(Pens.Black, rectangle1); e.Graphics.DrawRectangle(Pens.Red, rectangle2); @@ -147,7 +144,7 @@ private void InstanceRectangleIntersection(PaintEventArgs e) private void DrawFirstRectangle() { - ControlPaint.DrawReversibleFrame(rectangle1, + ControlPaint.DrawReversibleFrame(rectangle1, SystemColors.Highlight, FrameStyle.Thick); } @@ -160,16 +157,16 @@ private void Button1_Click(object sender, EventArgs e) // Check to see if the rectangle is within the bounds of the screen. if (screenRectangle.Contains(rectangle1)) - // If so, erase the previous rectangle. + // If so, erase the previous rectangle. { - ControlPaint.DrawReversibleFrame(rectangle1, + ControlPaint.DrawReversibleFrame(rectangle1, SystemColors.Highlight, FrameStyle.Thick); // Call the Offset method to move the rectangle. rectangle1.Offset(20, 20); // Draw the new, offset rectangle. - ControlPaint.DrawReversibleFrame(rectangle1, + ControlPaint.DrawReversibleFrame(rectangle1, SystemColors.Highlight, FrameStyle.Thick); } } @@ -208,7 +205,7 @@ private void RoundingAndTruncatingRectangles(PaintEventArgs e) { // Construct a new RectangleF. - RectangleF myRectangleF = + RectangleF myRectangleF = new RectangleF(30.6F, 30.7F, 40.8F, 100.9F); // Call the Round method. diff --git a/snippets/csharp/System.Drawing/BufferedGraphics/Overview/bufferingtest.cs b/snippets/csharp/System.Drawing/BufferedGraphics/Overview/bufferingtest.cs index be686117941..184ff71f2ca 100644 --- a/snippets/csharp/System.Drawing/BufferedGraphics/Overview/bufferingtest.cs +++ b/snippets/csharp/System.Drawing/BufferedGraphics/Overview/bufferingtest.cs @@ -11,30 +11,32 @@ public class BufferingExample : Form private BufferedGraphicsContext context; private BufferedGraphics grafx; - private byte bufferingMode; - private string[] bufferingModeStrings = - { "Draw to Form without OptimizedDoubleBufferring control style", - "Draw to Form using OptimizedDoubleBuffering control style", - "Draw to HDC for form" }; + private byte bufferingMode; + private string[] bufferingModeStrings = + [ "Draw to Form without OptimizedDoubleBuffering control style", + "Draw to Form using OptimizedDoubleBuffering control style", + "Draw to HDC for form" ]; - private System.Windows.Forms.Timer timer1; - private byte count; + private System.Windows.Forms.Timer timer1; + private byte count; public BufferingExample() : base() { // Configure the Form for this example. - this.Text = "User double buffering"; - this.MouseDown += new MouseEventHandler(this.MouseDownHandler); - this.Resize += new EventHandler(this.OnResize); - this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true ); + Text = "User double buffering"; + MouseDown += new MouseEventHandler(MouseDownHandler); + Resize += new EventHandler(OnResize); + SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); // Configure a timer to draw graphics updates. - timer1 = new System.Windows.Forms.Timer(); - timer1.Interval = 200; - timer1.Tick += new EventHandler(this.OnTimer); + timer1 = new System.Windows.Forms.Timer + { + Interval = 200 + }; + timer1.Tick += new EventHandler(OnTimer); - bufferingMode = 2; - count = 0; + bufferingMode = 2; + count = 0; // Retrieves the BufferedGraphicsContext for the // current application domain. @@ -45,121 +47,118 @@ public BufferingExample() : base() // domain. Any allocation requests for a buffer larger // than this will create a temporary buffered graphics // context to host the graphics buffer. - context.MaximumBuffer = new Size(this.Width+1, this.Height+1); + context.MaximumBuffer = new Size(Width + 1, Height + 1); // Allocates a graphics buffer the size of this form // using the pixel format of the Graphics created by // the Form.CreateGraphics() method, which returns a // Graphics object that matches the pixel format of the form. - grafx = context.Allocate(this.CreateGraphics(), - new Rectangle( 0, 0, this.Width, this.Height )); + grafx = context.Allocate(CreateGraphics(), + new Rectangle(0, 0, Width, Height)); - // Draw the first frame to the buffer. - DrawToBuffer(grafx.Graphics); + // Draw the first frame to the buffer. + DrawToBuffer(grafx.Graphics); } - private void MouseDownHandler(object sender, MouseEventArgs e) + private void MouseDownHandler(object sender, MouseEventArgs e) { - if( e.Button == MouseButtons.Right ) - { - // Cycle the buffering mode. - if( ++bufferingMode > 2 ) - bufferingMode = 0; - - // If the previous buffering mode used - // the OptimizedDoubleBuffering ControlStyle, - // disable the control style. - if( bufferingMode == 1 ) - this.SetStyle( ControlStyles.OptimizedDoubleBuffer, true ); - - // If the current buffering mode uses - // the OptimizedDoubleBuffering ControlStyle, - // enabke the control style. - if( bufferingMode == 2 ) - this.SetStyle( ControlStyles.OptimizedDoubleBuffer, false ); - - // Cause the background to be cleared and redraw. - count = 6; - DrawToBuffer(grafx.Graphics); - this.Refresh(); - } - else - { + if (e.Button == MouseButtons.Right) + { + // Cycle the buffering mode. + if (++bufferingMode > 2) + bufferingMode = 0; + + // If the previous buffering mode used + // the OptimizedDoubleBuffering ControlStyle, + // disable the control style. + if (bufferingMode == 1) + SetStyle(ControlStyles.OptimizedDoubleBuffer, true); + + // If the current buffering mode uses + // the OptimizedDoubleBuffering ControlStyle, + // enabke the control style. + if (bufferingMode == 2) + SetStyle(ControlStyles.OptimizedDoubleBuffer, false); + + // Cause the background to be cleared and redraw. + count = 6; + DrawToBuffer(grafx.Graphics); + Refresh(); + } + else + { // Toggle whether the redraw timer is active. - if( timer1.Enabled ) - timer1.Stop(); - else - timer1.Start(); - } + if (timer1.Enabled) + timer1.Stop(); + else + timer1.Start(); + } } - private void OnTimer(object sender, EventArgs e) - { + private void OnTimer(object sender, EventArgs e) + { // Draw randomly positioned ellipses to the buffer. - DrawToBuffer(grafx.Graphics); + DrawToBuffer(grafx.Graphics); // If in bufferingMode 2, draw to the form's HDC. - if( bufferingMode == 2 ) - // Render the graphics buffer to the form's HDC. - grafx.Render(Graphics.FromHwnd(this.Handle)); + if (bufferingMode == 2) + // Render the graphics buffer to the form's HDC. + grafx.Render(Graphics.FromHwnd(Handle)); // If in bufferingMode 0 or 1, draw in the paint method. - else - this.Refresh(); - } + else + Refresh(); + } private void OnResize(object sender, EventArgs e) { - // Re-create the graphics buffer for a new window size. - context.MaximumBuffer = new Size(this.Width+1, this.Height+1); - if( grafx != null ) - { - grafx.Dispose(); - grafx = null; - } - grafx = context.Allocate(this.CreateGraphics(), - new Rectangle( 0, 0, this.Width, this.Height )); - - // Cause the background to be cleared and redraw. - count = 6; - DrawToBuffer(grafx.Graphics); - this.Refresh(); - } - - private void DrawToBuffer(Graphics g) - { + // Re-create the graphics buffer for a new window size. + context.MaximumBuffer = new Size(Width + 1, Height + 1); + grafx?.Dispose(); + grafx = null; + grafx = context.Allocate(CreateGraphics(), + new Rectangle(0, 0, Width, Height)); + + // Cause the background to be cleared and redraw. + count = 6; + DrawToBuffer(grafx.Graphics); + Refresh(); + } + + private void DrawToBuffer(Graphics g) + { // Clear the graphics buffer every five updates. - if( ++count > 5 ) + if (++count > 5) { count = 0; - grafx.Graphics.FillRectangle(Brushes.Black, 0, 0, this.Width, this.Height); + grafx.Graphics.FillRectangle(Brushes.Black, 0, 0, Width, Height); } // Draw randomly positioned and colored ellipses. - Random rnd = new Random(); - for( int i=0; i<20; i++ ) - { - int px = rnd.Next(20,this.Width-40); - int py = rnd.Next(20,this.Height-40); - g.DrawEllipse(new Pen(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0,255), rnd.Next(0,255)), 1), - px, py, px+rnd.Next(0, this.Width-px-20), py+rnd.Next(0, this.Height-py-20)); - } + Random rnd = new Random(); + for (int i = 0; i < 20; i++) + { + int px = rnd.Next(20, Width - 40); + int py = rnd.Next(20, Height - 40); + g.DrawEllipse(new Pen(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), 1), + px, py, px + rnd.Next(0, Width - px - 20), py + rnd.Next(0, Height - py - 20)); + } // Draw information strings. - g.DrawString("Buffering Mode: "+bufferingModeStrings[bufferingMode], new Font("Arial", 8), Brushes.White, 10, 10); + g.DrawString("Buffering Mode: " + bufferingModeStrings[bufferingMode], new Font("Arial", 8), Brushes.White, 10, 10); g.DrawString("Right-click to cycle buffering mode", new Font("Arial", 8), Brushes.White, 10, 22); g.DrawString("Left-click to toggle timed display refresh", new Font("Arial", 8), Brushes.White, 10, 34); - } + } - protected override void OnPaint(PaintEventArgs e) + protected override void OnPaint(PaintEventArgs e) { - grafx.Render(e.Graphics); - } + grafx.Render(e.Graphics); + } [STAThread] public static void Main(string[] args) { - Application.Run(new BufferingExample()); + Application.Run(new BufferingExample()); } } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System.Drawing/BufferedGraphics/Render/bufferingexamples.cs b/snippets/csharp/System.Drawing/BufferedGraphics/Render/bufferingexamples.cs index 0e29211ba4c..62f57142281 100644 --- a/snippets/csharp/System.Drawing/BufferedGraphics/Render/bufferingexamples.cs +++ b/snippets/csharp/System.Drawing/BufferedGraphics/Render/bufferingexamples.cs @@ -8,7 +8,7 @@ namespace BufferingExample public class BufferingExamples : Form { private BufferedGraphicsContext appDomainBufferedGraphicsContext; - private BufferedGraphics grafx; + private BufferedGraphics grafx; public BufferingExamples() : base() { @@ -34,36 +34,36 @@ public BufferingExamples() : base() // // Allocates a graphics buffer using the pixel format // of the specified Graphics object. - grafx = appDomainBufferedGraphicsContext.Allocate(this.CreateGraphics(), - new Rectangle( 0, 0, 400, 400 )); + grafx = appDomainBufferedGraphicsContext.Allocate(CreateGraphics(), + new Rectangle(0, 0, 400, 400)); // // // Allocates a graphics buffer using the pixel format // of the specified handle to a device context. - grafx = appDomainBufferedGraphicsContext.Allocate(this.Handle, - new Rectangle( 0, 0, 400, 400 )); + grafx = appDomainBufferedGraphicsContext.Allocate(Handle, + new Rectangle(0, 0, 400, 400)); // } // private void RenderToGraphics(Graphics g) { - grafx.Render( g ); + grafx.Render(g); } // // private void RenderToDeviceContextHandle(IntPtr hDC) { - grafx.Render( hDC ); + grafx.Render(hDC); } // [STAThread] public static void Main(string[] args) { - Application.Run(new BufferingExamples()); + Application.Run(new BufferingExamples()); } } } diff --git a/snippets/csharp/System.Drawing/CharacterRange/Equals/Form1.cs b/snippets/csharp/System.Drawing/CharacterRange/Equals/Form1.cs index 8854d8342f5..087181b10d2 100644 --- a/snippets/csharp/System.Drawing/CharacterRange/Equals/Form1.cs +++ b/snippets/csharp/System.Drawing/CharacterRange/Equals/Form1.cs @@ -11,9 +11,9 @@ public partial class Form1 : Form { public Form1() { - // InitializeComponent(); + // InitializeComponent(); CharacterRangeInequality(); - this.Paint += new PaintEventHandler(Form1_Paint); + Paint += new PaintEventHandler(Form1_Paint); } void Form1_Paint(object sender, PaintEventArgs e) @@ -42,9 +42,9 @@ private void CharacterRangeEquality1() string message = "Strings or strings; that is the question."; // Compare the ranges for equality. The should not be equal. - CharacterRange range1 = + CharacterRange range1 = new CharacterRange(message.IndexOf("Strings"), "Strings".Length); - CharacterRange range2 = + CharacterRange range2 = new CharacterRange(message.IndexOf("strings"), "strings".Length); if (range1 == range2) @@ -97,7 +97,7 @@ private void CharacterRangeInequality() // private void CopyPixels1(PaintEventArgs e) { - e.Graphics.CopyFromScreen(this.Location, + e.Graphics.CopyFromScreen(Location, new Point(40, 40), new Size(100, 100)); } // @@ -105,8 +105,8 @@ private void CopyPixels1(PaintEventArgs e) // private void CopyPixels2(PaintEventArgs e) { - e.Graphics.CopyFromScreen(this.Location, new Point(40, 40), - new Size(100, 100), CopyPixelOperation.MergePaint); + e.Graphics.CopyFromScreen(Location, new Point(40, 40), + new Size(100, 100), CopyPixelOperation.MergePaint); } // // @@ -119,7 +119,7 @@ private void CopyPixels3(PaintEventArgs e) // private void CopyPixels4(PaintEventArgs e) { - e.Graphics.CopyFromScreen(0, 0, 20, 20, new Size(160, 160), + e.Graphics.CopyFromScreen(0, 0, 20, 20, new Size(160, 160), CopyPixelOperation.SourceInvert); } // @@ -127,10 +127,10 @@ private void CopyPixels4(PaintEventArgs e) // private void DrawImageUnscaled(PaintEventArgs e) { - string filepath = @"C:\Documents and Settings\All Users\Documents\" + + string filepath = @"C:\Documents and Settings\All Users\Documents\" + @"My Pictures\Sample Pictures\Water Lilies.jpg"; Bitmap bitmap1 = new Bitmap(filepath); - e.Graphics.DrawImageUnscaledAndClipped(bitmap1, new Rectangle(10,10,250,250)); + e.Graphics.DrawImageUnscaledAndClipped(bitmap1, new Rectangle(10, 10, 250, 250)); } // @@ -138,7 +138,7 @@ private void DrawImageUnscaled(PaintEventArgs e) private void AddPoint(PaintEventArgs e) { Point point1 = new Point(10, 10); - Point point2 = Point.Add(point1, new Size(250,0)); + Point point2 = Point.Add(point1, new Size(250, 0)); e.Graphics.DrawLine(Pens.Red, point1, point2); } // @@ -157,8 +157,8 @@ private void OffsetPoint(PaintEventArgs e) private void AddSizes(PaintEventArgs e) { Size size1 = new Size(100, 100); - Size size2 = new Size(50,50); - e.Graphics.DrawRectangle(Pens.Black, new Rectangle(new Point(10,10), size1)); + Size size2 = new Size(50, 50); + e.Graphics.DrawRectangle(Pens.Black, new Rectangle(new Point(10, 10), size1)); size1 = Size.Add(size1, size2); e.Graphics.DrawRectangle(Pens.Red, new Rectangle(new Point(10, 10), size1)); } @@ -423,4 +423,4 @@ private void DrawWithWindowTextPen(PaintEventArgs e) } // } -} \ No newline at end of file +} diff --git a/snippets/csharp/System.Drawing/CharacterRange/Overview/form1.cs b/snippets/csharp/System.Drawing/CharacterRange/Overview/form1.cs index f6a7da89035..6d8ac2c38b6 100644 --- a/snippets/csharp/System.Drawing/CharacterRange/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/CharacterRange/Overview/form1.cs @@ -2,20 +2,20 @@ using System.Drawing; using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.Button1.Click += new EventHandler(Button1_Click); - this.Button2.Click += new EventHandler(Button2_Click); - this.Paint += new PaintEventHandler(Form1_Paint); + Button1.Click += new EventHandler(Button1_Click); + Button2.Click += new EventHandler(Button2_Click); + Paint += new PaintEventHandler(Form1_Paint); //Add any initialization after the InitializeComponent() call } @@ -25,10 +25,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -44,32 +41,32 @@ protected override void Dispose(bool disposing) [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.Button1 = new System.Windows.Forms.Button(); - this.Button2 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + Button1 = new System.Windows.Forms.Button(); + Button2 = new System.Windows.Forms.Button(); + SuspendLayout(); // //Button1 // - this.Button1.Location = new System.Drawing.Point(40, 208); - this.Button1.Name = "Button1"; - this.Button1.TabIndex = 0; - this.Button1.Text = "Button1"; + Button1.Location = new System.Drawing.Point(40, 208); + Button1.Name = "Button1"; + Button1.TabIndex = 0; + Button1.Text = "Button1"; // //Button2 // - this.Button2.Location = new System.Drawing.Point(152, 208); - this.Button2.Name = "Button2"; - this.Button2.TabIndex = 1; - this.Button2.Text = "Button2"; + Button2.Location = new System.Drawing.Point(152, 208); + Button2.Name = "Button2"; + Button2.TabIndex = 1; + Button2.Text = "Button2"; // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Button2); - this.Controls.Add(this.Button1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new System.Drawing.Size(292, 266); + Controls.Add(Button2); + Controls.Add(Button1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion @@ -92,9 +89,9 @@ private void HighlightACharacterRange(PaintEventArgs e) // Create a CharacterRange array with the searchWord // location and length. - CharacterRange[] ranges = - new CharacterRange[]{new CharacterRange - (message.IndexOf(searchWord), searchWord.Length)}; + CharacterRange[] ranges = + [new CharacterRange + (message.IndexOf(searchWord), searchWord.Length)]; // Construct a StringFormat object. StringFormat stringFormat1 = new StringFormat(); @@ -114,15 +111,15 @@ private void HighlightACharacterRange(PaintEventArgs e) // Get the Region to highlight by calling the // MeasureCharacterRanges method. - Region[] charRegion = e.Graphics.MeasureCharacterRanges(message, + Region[] charRegion = e.Graphics.MeasureCharacterRanges(message, largeFont, displayRectangleF, stringFormat1); // Draw the message string on the form. - e.Graphics.DrawString(message, largeFont, Brushes.Blue, + e.Graphics.DrawString(message, largeFont, Brushes.Blue, displayRectangleF); // Fill in the region using a semi-transparent color. - e.Graphics.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Fuchsia)), + e.Graphics.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Fuchsia)), charRegion[0]); largeFont.Dispose(); @@ -141,12 +138,12 @@ private void Form1_Paint(object sender, PaintEventArgs e) // your form and associate the Button1_Click method with the button's // Click event. // - private void Button1_Click(System.Object sender, System.EventArgs e) + private void Button1_Click(object sender, System.EventArgs e) { - if (this.BackColor == SystemColors.ControlDark) + if (BackColor == SystemColors.ControlDark) { - this.BackColor = SystemColors.Control; + BackColor = SystemColors.Control; } } // @@ -157,16 +154,16 @@ private void Button1_Click(System.Object sender, System.EventArgs e) // into your form and associate the Button2_Click method with the // button's Click event. // - private void Button2_Click(System.Object sender, System.EventArgs e) + private void Button2_Click(object sender, System.EventArgs e) { - if (this.BackColor != SystemColors.ControlDark) + if (BackColor != SystemColors.ControlDark) { - this.BackColor = SystemColors.ControlDark; + BackColor = SystemColors.ControlDark; } - if (!(this.Font.Bold)) + if (!(Font.Bold)) { - this.Font = new Font(this.Font, FontStyle.Bold); + Font = new Font(Font, FontStyle.Bold); } } // diff --git a/snippets/csharp/System.Drawing/Color/FromArgb/form1.cs b/snippets/csharp/System.Drawing/Color/FromArgb/form1.cs index d79692b38cf..a74c0b882dd 100644 --- a/snippets/csharp/System.Drawing/Color/FromArgb/form1.cs +++ b/snippets/csharp/System.Drawing/Color/FromArgb/form1.cs @@ -1,88 +1,85 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicColorExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.Color.FromArgb(System.Int32) // public void FromArgb4(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Transparent red, green, and blue brushes. SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(0x78FF0000)); SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(0x7800FF00)); SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(0x780000FF)); - + // Base and height of the triangle that is used to position the // circles. Each vertex of the triangle is at the center of one of the // 3 circles. The base is equal to the diameter of the circles. - float triBase = 100; - float triHeight = (float)Math.Sqrt(3*(triBase*triBase)/4); - + float triBase = 100; + float triHeight = (float)Math.Sqrt(3 * (triBase * triBase) / 4); + // coordinates of first circle's bounding rectangle. - float x1 = 40; - float y1 = 40; - + float x1 = 40; + float y1 = 40; + // Fill 3 over-lapping circles. Each circle is a different color. - g.FillEllipse(trnsRedBrush, x1, y1, 2*triHeight, 2*triHeight); - g.FillEllipse(trnsGreenBrush, x1 + triBase/2, y1 + triHeight, - 2*triHeight, 2*triHeight); - g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2*triHeight, 2*triHeight); + g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight); + g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, + 2 * triHeight, 2 * triHeight); + g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, 2 * triHeight); } // @@ -90,23 +87,23 @@ public void FromArgb4(PaintEventArgs e) // public void FromArgb3(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Opaque colors (alpha value defaults to 255 -- max value). Color red = Color.FromArgb(255, 0, 0); Color green = Color.FromArgb(0, 255, 0); Color blue = Color.FromArgb(0, 0, 255); - + // Solid brush initialized to red. - SolidBrush myBrush = new SolidBrush(red); + SolidBrush myBrush = new SolidBrush(red); int alpha; - + // x coordinate of first red rectangle - int x = 50; - + int x = 50; + // y coordinate of first red rectangle - int y = 50; - + int y = 50; + // Fill rectangles with red, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { @@ -116,11 +113,11 @@ public void FromArgb3(PaintEventArgs e) x += 50; } // x coordinate of first green rectangle - x = 50; - + x = 50; + // y coordinate of first green rectangle - y += 50; - + y += 50; + // Fill rectangles with green, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { @@ -129,10 +126,10 @@ public void FromArgb3(PaintEventArgs e) x += 50; } // x coordinate of first blue rectangle. - x = 50; - - // y coordinate of first blue rectangle - y += 100; + x = 50; + + // y coordinate of first blue rectangle + y += 100; // Fill rectangles with blue, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) @@ -148,23 +145,23 @@ public void FromArgb3(PaintEventArgs e) // public void FromArgb2(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Opaque colors (alpha value defaults to 255 -- max value). Color red = Color.FromArgb(255, 0, 0); Color green = Color.FromArgb(0, 255, 0); Color blue = Color.FromArgb(0, 0, 255); - + // Solid brush initialized to red. - SolidBrush myBrush = new SolidBrush(red); + SolidBrush myBrush = new SolidBrush(red); int alpha; // x coordinate of first red rectangle - int x = 50; - + int x = 50; + // y coordinate of first red rectangle - int y = 50; - + int y = 50; + // Fill rectangles with red, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { @@ -174,11 +171,11 @@ public void FromArgb2(PaintEventArgs e) x += 50; } // x coordinate of first green rectangle. - x = 50; - + x = 50; + // y coordinate of first green rectangle. - y += 50; - + y += 50; + // Fill rectangles with green, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { @@ -187,11 +184,11 @@ public void FromArgb2(PaintEventArgs e) x += 50; } // x coordinate of first blue rectangle. - x = 50; - + x = 50; + // y coordinate of first blue rectangle. - y += 100; - + y += 100; + // Fill rectangles with blue, varying the alpha value from 25 to 250. for (alpha = 25; alpha <= 250; alpha += 25) { @@ -206,28 +203,28 @@ public void FromArgb2(PaintEventArgs e) // public void FromArgb1(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Transparent red, green, and blue brushes. SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(120, 255, 0, 0)); SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(120, 0, 255, 0)); SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(120, 0, 0, 255)); - + // Base and height of the triangle that is used to position the // circles. Each vertex of the triangle is at the center of one of the // 3 circles. The base is equal to the diameter of the circles. - float triBase = 100; - float triHeight = (float)Math.Sqrt(3*(triBase*triBase)/4); - + float triBase = 100; + float triHeight = (float)Math.Sqrt(3 * (triBase * triBase) / 4); + // Coordinates of first circle's bounding rectangle. - float x1 = 40; - float y1 = 40; - + float x1 = 40; + float y1 = 40; + // Fill 3 over-lapping circles. Each circle is a different color. - g.FillEllipse(trnsRedBrush, x1, y1, 2*triHeight, 2*triHeight); - g.FillEllipse(trnsGreenBrush, x1 + triBase/2, y1 + triHeight, - 2*triHeight, 2*triHeight); - g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2*triHeight, 2*triHeight); + g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight); + g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, + 2 * triHeight, 2 * triHeight); + g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, 2 * triHeight); } // @@ -235,20 +232,20 @@ public void FromArgb1(PaintEventArgs e) // public void KnownColorBrightnessExample1(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Color structures. One is a variable used for temporary storage. The other // is a constant used for comparisons. - Color someColor = Color.FromArgb(0); - Color redShade = Color.FromArgb(255, 200, 0, 100); - + Color someColor = Color.FromArgb(0); + Color redShade = Color.FromArgb(255, 200, 0, 100); + // Array to store KnownColor values that match the brightness of the // redShade color. - KnownColor[] colorMatches = new KnownColor[15]; - + KnownColor[] colorMatches = new KnownColor[15]; + // Number of matches found. - int count = 0; - + int count = 0; + // Iterate through the KnownColor enums until 15 matches are found. for (KnownColor enumValue = 0; enumValue <= KnownColor.YellowGreen && count < 15; enumValue++) @@ -257,16 +254,16 @@ public void KnownColorBrightnessExample1(PaintEventArgs e) if (someColor.GetBrightness() == redShade.GetBrightness()) colorMatches[count++] = enumValue; } - + // Display the redShade color and its argb value. - SolidBrush myBrush1 = new SolidBrush(redShade); - Font myFont = new Font("Arial", 12); - int x = 20; - int y = 20; + SolidBrush myBrush1 = new SolidBrush(redShade); + Font myFont = new Font("Arial", 12); + int x = 20; + int y = 20; someColor = redShade; g.FillRectangle(myBrush1, x, y, 100, 30); g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y); - + // Iterate through the matches that were found and display each color that // Corresponds with the enum value in the array. also display the name of // The KnownColor. @@ -285,20 +282,20 @@ public void KnownColorBrightnessExample1(PaintEventArgs e) // public void KnownColorBrightnessExample2(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Color structures. One is a variable used for temporary storage. The other // is a constant used for comparisons. - Color someColor = Color.FromArgb(0); - Color redShade = Color.FromArgb(255, 200, 0, 100); - + Color someColor = Color.FromArgb(0); + Color redShade = Color.FromArgb(255, 200, 0, 100); + // Array to store KnownColor values that match the brightness of the // redShade color. - KnownColor[] colorMatches = new KnownColor[15]; - + KnownColor[] colorMatches = new KnownColor[15]; + // Number of matches found. - int count = 0; - + int count = 0; + // Iterate through the KnownColor enums until 15 matches are found. for (KnownColor enumValue = 0; enumValue <= KnownColor.YellowGreen && count < 15; enumValue++) @@ -307,16 +304,16 @@ public void KnownColorBrightnessExample2(PaintEventArgs e) if (someColor.GetBrightness() == redShade.GetBrightness()) colorMatches[count++] = enumValue; } - + // display the redShade color and its argb value. - SolidBrush myBrush1 = new SolidBrush(redShade); - Font myFont = new Font("Arial", 12); - int x = 20; - int y = 20; + SolidBrush myBrush1 = new SolidBrush(redShade); + Font myFont = new Font("Arial", 12); + int x = 20; + int y = 20; someColor = redShade; g.FillRectangle(myBrush1, x, y, 100, 30); g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y); - + // Iterate through the matches that were found and display each color that // corresponds with the enum value in the array. also display the name of // The KnownColor. @@ -335,20 +332,20 @@ public void KnownColorBrightnessExample2(PaintEventArgs e) // public void GetHueExample(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Color structures. One is a variable used for temporary storage. The other // is a constant used for comparisons. - Color someColor = Color.FromArgb(0); - Color redShade = Color.FromArgb(255, 200, 0, 100); - + Color someColor = Color.FromArgb(0); + Color redShade = Color.FromArgb(255, 200, 0, 100); + // Array to store KnownColor values that match the hue of the redShade // color. - KnownColor[] colorMatches = new KnownColor[15]; + KnownColor[] colorMatches = new KnownColor[15]; // Number of matches found. - int count = 0; - + int count = 0; + // Iterate through the KnownColor enums until 15 matches are found. for (KnownColor enumValue = 0; enumValue <= KnownColor.YellowGreen && count < 15; enumValue++) @@ -357,16 +354,16 @@ public void GetHueExample(PaintEventArgs e) if (someColor.GetHue() == redShade.GetHue()) colorMatches[count++] = enumValue; } - + // Display the redShade color and its argb value. - SolidBrush myBrush1 = new SolidBrush(redShade); - Font myFont = new Font("Arial", 12); - int x = 20; - int y = 20; + SolidBrush myBrush1 = new SolidBrush(redShade); + Font myFont = new Font("Arial", 12); + int x = 20; + int y = 20; someColor = redShade; g.FillRectangle(myBrush1, x, y, 100, 30); g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y); - + // Iterate through the matches that were found and display each color that // corresponds with the enum value in the array. also display the name of // the KnownColor. @@ -385,20 +382,20 @@ public void GetHueExample(PaintEventArgs e) // public void GetSatExample(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Color structures. One is a variable used for temporary storage. The other // is a constant used for comparisons. - Color someColor = Color.FromArgb(0); - Color redShade = Color.FromArgb(255, 200, 0, 100); - + Color someColor = Color.FromArgb(0); + Color redShade = Color.FromArgb(255, 200, 0, 100); + // Array to store KnownColor values that match the saturation of the // redShade color. - KnownColor[] colorMatches = new KnownColor[15]; - + KnownColor[] colorMatches = new KnownColor[15]; + // Number of matches found. - int count = 0; - + int count = 0; + // Iterate through the KnownColor enums until 15 matches are found. for (KnownColor enumValue = 0; enumValue <= KnownColor.YellowGreen && count < 15; enumValue++) @@ -407,16 +404,16 @@ public void GetSatExample(PaintEventArgs e) if (someColor.GetSaturation() == redShade.GetSaturation()) colorMatches[count++] = enumValue; } - + // Display the redShade color and its argb value. - SolidBrush myBrush1 = new SolidBrush(redShade); - Font myFont = new Font("Arial", 12); - int x = 20; - int y = 20; + SolidBrush myBrush1 = new SolidBrush(redShade); + Font myFont = new Font("Arial", 12); + int x = 20; + int y = 20; someColor = redShade; g.FillRectangle(myBrush1, x, y, 100, 30); g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y); - + // Iterate through the matches that were found and display each color that // corresponds with the enum value in the array. also display the name of // the KnownColor. @@ -435,17 +432,17 @@ public void GetSatExample(PaintEventArgs e) // public void ToArgbToStringExample1(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Color structure used for temporary storage. - Color someColor = Color.FromArgb(0); - + Color someColor = Color.FromArgb(0); + // Array to store KnownColor values that match the criteria. - KnownColor[] colorMatches = new KnownColor[167]; - + KnownColor[] colorMatches = new KnownColor[167]; + // Number of matches found. - int count = 0; - + int count = 0; + // Iterate through the KnownColor enums to find all corresponding colors // that have a nonzero green component and zero-value red component and // that are not system colors. @@ -456,22 +453,22 @@ public void ToArgbToStringExample1(PaintEventArgs e) if (someColor.G != 0 && someColor.R == 0 && !someColor.IsSystemColor) colorMatches[count++] = enumValue; } - SolidBrush myBrush1 = new SolidBrush(someColor); - Font myFont = new Font("Arial", 9); - int x = 40; - int y = 40; - + SolidBrush myBrush1 = new SolidBrush(someColor); + Font myFont = new Font("Arial", 9); + int x = 40; + int y = 40; + // Iterate through the matches that were found and display each color that // corresponds with the enum value in the array. also display the name of // the KnownColor and the ARGB components. for (int i = 0; i < count; i++) { - + // Display the color. someColor = Color.FromKnownColor(colorMatches[i]); myBrush1.Color = someColor; g.FillRectangle(myBrush1, x, y, 50, 30); - + // Display KnownColor name and the four component values. To display the // component values: Use the ToArgb method to get the 32-bit ARGB value // of someColor, which was created from a KnownColor. Then create a @@ -490,17 +487,17 @@ public void ToArgbToStringExample1(PaintEventArgs e) // public void ToArgbToStringExample2(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Color structure used for temporary storage. - Color someColor = Color.FromArgb(0); - + Color someColor = Color.FromArgb(0); + // Array to store KnownColor values that match the criteria. - KnownColor[] colorMatches = new KnownColor[167]; - + KnownColor[] colorMatches = new KnownColor[167]; + // Number of matches found. - int count = 0; - + int count = 0; + // Iterate through the KnownColor enums to find all corresponding colors // that have a nonzero green component and zero-value red component and // that are not system colors. @@ -511,11 +508,11 @@ public void ToArgbToStringExample2(PaintEventArgs e) if (someColor.G != 0 && someColor.R == 0 && !someColor.IsSystemColor) colorMatches[count++] = enumValue; } - SolidBrush myBrush1 = new SolidBrush(someColor); - Font myFont = new Font("Arial", 9); - int x = 40; - int y = 40; - + SolidBrush myBrush1 = new SolidBrush(someColor); + Font myFont = new Font("Arial", 9); + int x = 40; + int y = 40; + // Iterate through the matches that were found and display each color that // corresponds with the enum value in the array. also display the name of // the KnownColor and the ARGB components. @@ -525,7 +522,7 @@ public void ToArgbToStringExample2(PaintEventArgs e) someColor = Color.FromKnownColor(colorMatches[i]); myBrush1.Color = someColor; g.FillRectangle(myBrush1, x, y, 50, 30); - + // Display KnownColor name and the four component values. To display the // component values: Use the ToArgb method to get the 32-bit ARGB value // of someColor, which was created from a KnownColor. Then create a @@ -540,13 +537,13 @@ public void ToArgbToStringExample2(PaintEventArgs e) } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Color/Name/form1.cs b/snippets/csharp/System.Drawing/Color/Name/form1.cs index 0c82e1906a5..ed70680bf69 100644 --- a/snippets/csharp/System.Drawing/Color/Name/form1.cs +++ b/snippets/csharp/System.Drawing/Color/Name/form1.cs @@ -1,16 +1,16 @@ using System; -using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; +using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); @@ -26,10 +26,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -46,42 +43,42 @@ protected override void Dispose(bool disposing) [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.Button1 = new System.Windows.Forms.Button(); - this.PictureBox1 = new System.Windows.Forms.PictureBox(); - this.Button2 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + Button1 = new System.Windows.Forms.Button(); + PictureBox1 = new System.Windows.Forms.PictureBox(); + Button2 = new System.Windows.Forms.Button(); + SuspendLayout(); // //Button1 // - this.Button1.Location = new System.Drawing.Point(184, 40); - this.Button1.Name = "Button1"; - this.Button1.TabIndex = 0; - this.Button1.Text = "Button1"; + Button1.Location = new System.Drawing.Point(184, 40); + Button1.Name = "Button1"; + Button1.TabIndex = 0; + Button1.Text = "Button1"; // //PictureBox1 // - this.PictureBox1.Location = new System.Drawing.Point(112, 160); - this.PictureBox1.Name = "PictureBox1"; - this.PictureBox1.Size = new System.Drawing.Size(128, 88); - this.PictureBox1.TabIndex = 3; - this.PictureBox1.TabStop = false; + PictureBox1.Location = new System.Drawing.Point(112, 160); + PictureBox1.Name = "PictureBox1"; + PictureBox1.Size = new System.Drawing.Size(128, 88); + PictureBox1.TabIndex = 3; + PictureBox1.TabStop = false; // //Button2 // - this.Button2.Location = new System.Drawing.Point(184, 88); - this.Button2.Name = "Button2"; - this.Button2.TabIndex = 2; - this.Button2.Text = "Button2"; + Button2.Location = new System.Drawing.Point(184, 88); + Button2.Name = "Button2"; + Button2.TabIndex = 2; + Button2.Text = "Button2"; // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.PictureBox1); - this.Controls.Add(this.Button2); - this.Controls.Add(this.Button1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new System.Drawing.Size(292, 266); + Controls.Add(PictureBox1); + Controls.Add(Button2); + Controls.Add(Button1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion @@ -103,8 +100,8 @@ private void ShowLineAndAlignment(PaintEventArgs e) { // Construct a new Rectangle . - Rectangle displayRectangle = - new Rectangle (new Point(40, 40), new Size (80, 80)); + Rectangle displayRectangle = + new Rectangle(new Point(40, 40), new Size(80, 80)); // Construct 2 new StringFormat objects StringFormat format1 = new StringFormat(StringFormatFlags.NoClip); @@ -120,9 +117,9 @@ private void ShowLineAndAlignment(PaintEventArgs e) // Draw the bounding rectangle and a string for each // StringFormat object. e.Graphics.DrawRectangle(Pens.Black, displayRectangle); - e.Graphics.DrawString("Showing Format1", this.Font, + e.Graphics.DrawString("Showing Format1", Font, Brushes.Red, (RectangleF)displayRectangle, format1); - e.Graphics.DrawString("Showing Format2", this.Font, + e.Graphics.DrawString("Showing Format2", Font, Brushes.Red, (RectangleF)displayRectangle, format2); } // @@ -140,11 +137,11 @@ private void ShowStringTrimming(PaintEventArgs e) string quote = "Not everything that can be counted counts," + " and not everything that counts can be counted."; format1.Trimming = StringTrimming.EllipsisWord; - e.Graphics.DrawString(quote, this.Font, Brushes.Black, + e.Graphics.DrawString(quote, Font, Brushes.Black, new RectangleF(10.0F, 10.0F, 90.0F, 50.0F), format1); } // - + private void Form1_Paint(object sender, PaintEventArgs e) { @@ -172,7 +169,7 @@ private void UseTransparentProperty() { // Set the Image property of the PictureBox to an image retrieved // from the file system. - PictureBox1.Image = + PictureBox1.Image = Image.FromFile("C:\\Documents and Settings\\All Users\\" + "Documents\\My Pictures\\Sample Pictures\\sunset.jpg"); @@ -187,7 +184,7 @@ private void UseTransparentProperty() Button1.BackColor = Color.Transparent; Button2.BackColor = Color.Transparent; } - catch(System.IO.FileNotFoundException) + catch (System.IO.FileNotFoundException) { MessageBox.Show("There was an error." + "Make sure the image file path is valid."); @@ -202,14 +199,14 @@ private void UseTransparentProperty() // Paste the code into a form that contains a button named Button1 // and associate the Button1_Click method with the button's Click event. // - private void Button1_Click(System.Object sender, System.EventArgs e) + private void Button1_Click(object sender, System.EventArgs e) { // Construct a new Point with integers. Point Point1 = new Point(100, 100); // Create a Graphics object. - Graphics formGraphics = this.CreateGraphics(); + Graphics formGraphics = CreateGraphics(); // Construct another Point, this time using a Size. Point Point2 = new Point(new Size(100, 100)); @@ -218,10 +215,10 @@ private void Button1_Click(System.Object sender, System.EventArgs e) // and if so print out their x and y values. if (Point1 == Point2) { - formGraphics.DrawString(String.Format("Point1.X: " + + formGraphics.DrawString(string.Format("Point1.X: " + "{0},Point2.X: {1}, Point1.Y: {2}, Point2.Y {3}", - new object[]{Point1.X, Point2.X, Point1.Y, Point2.Y}), - this.Font, Brushes.Black, new PointF(10, 70)); + new object[] { Point1.X, Point2.X, Point1.Y, Point2.Y }), + Font, Brushes.Black, new PointF(10, 70)); } } // @@ -233,11 +230,11 @@ private void Button1_Click(System.Object sender, System.EventArgs e) // and associate the Button2_Click method with the button's // Click event. // - private void Button2_Click(System.Object sender, System.EventArgs e) + private void Button2_Click(object sender, System.EventArgs e) { Button2.Width = 100; - Button2.Text = "Color: "+Button2.BackColor.Name; + Button2.Text = "Color: " + Button2.BackColor.Name; } // @@ -251,29 +248,31 @@ private void Button2_Click(System.Object sender, System.EventArgs e) // private void DemonstrateBlend(PaintEventArgs e) { - Blend blend1 = new Blend(9); - - // Set the values in the Factors array to be all green, - // go to all blue, and then go back to green. - blend1.Factors = new float[]{0.0F, 0.2F, 0.5F, 0.7F, 1.0F, - 0.7F, 0.5F, 0.2F, 0.0F}; + Blend blend1 = new Blend(9) + { + // Set the values in the Factors array to be all green, + // go to all blue, and then go back to green. + Factors = [0.0F, 0.2F, 0.5F, 0.7F, 1.0F, + 0.7F, 0.5F, 0.2F, 0.0F], - // Set the positions. - blend1.Positions = - new float[]{0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, - 0.7F, 0.8F, 1.0F}; + // Set the positions. + Positions = + [0.0F, 0.1F, 0.3F, 0.4F, 0.5F, 0.6F, + 0.7F, 0.8F, 1.0F] + }; // Declare a rectangle to draw the Blend in. Rectangle rectangle1 = new Rectangle(10, 10, 120, 100); // Create a new LinearGradientBrush using the rectangle, // green and blue. and 90-degree angle. - LinearGradientBrush brush1 = - new LinearGradientBrush(rectangle1, Color.LightGreen, - Color.Blue, 90, true); - - // Set the Blend property on the brush to the custom blend. - brush1.Blend = blend1; + LinearGradientBrush brush1 = + new LinearGradientBrush(rectangle1, Color.LightGreen, + Color.Blue, 90, true) + { + // Set the Blend property on the brush to the custom blend. + Blend = blend1 + }; // Fill in an ellipse with the brush. e.Graphics.FillEllipse(brush1, rectangle1); diff --git a/snippets/csharp/System.Drawing/Color/Overview/form1.cs b/snippets/csharp/System.Drawing/Color/Overview/form1.cs index 37cd6fe6b2f..f416c3e2b86 100644 --- a/snippets/csharp/System.Drawing/Color/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/Color/Overview/form1.cs @@ -1,40 +1,40 @@ -using System.Drawing; -using System; +using System; +using System.Drawing; using System.Windows.Forms; // The following code example demonstrates how to override the // OnClosed method on a class derived from Form. // -public class myForm: +public class myForm : Form { protected override void OnClosed(EventArgs e) { - MessageBox.Show("The form is now closing.", + MessageBox.Show("The form is now closing.", "Close Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); base.OnClosed(e); } public myForm() : base() - { + { } } // -public class Form1: myForm +public class Form1 : myForm { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.Paint += new PaintEventHandler(Form1_Paint); + Paint += new PaintEventHandler(Form1_Paint); addButton.Click += new EventHandler(addButton_Click); subtractButton.Click += new EventHandler(subtractButton_Click); TruncateAndRoundSizes(); @@ -47,10 +47,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -68,52 +65,52 @@ protected override void Dispose(bool disposing) [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.subtractButton = new System.Windows.Forms.Button(); - this.addButton = new System.Windows.Forms.Button(); - this.Label1 = new System.Windows.Forms.Label(); - this.Label2 = new System.Windows.Forms.Label(); - this.SuspendLayout(); + subtractButton = new System.Windows.Forms.Button(); + addButton = new System.Windows.Forms.Button(); + Label1 = new System.Windows.Forms.Label(); + Label2 = new System.Windows.Forms.Label(); + SuspendLayout(); // //subtractButton // - this.subtractButton.Location = new System.Drawing.Point(192, 40); - this.subtractButton.Name = "subtractButton"; - this.subtractButton.TabIndex = 0; - this.subtractButton.Text = "subtractButton"; + subtractButton.Location = new System.Drawing.Point(192, 40); + subtractButton.Name = "subtractButton"; + subtractButton.TabIndex = 0; + subtractButton.Text = "subtractButton"; // //addButton // - this.addButton.Location = new System.Drawing.Point(192, 80); - this.addButton.Name = "addButton"; - this.addButton.TabIndex = 1; - this.addButton.Text = "addButton"; + addButton.Location = new System.Drawing.Point(192, 80); + addButton.Name = "addButton"; + addButton.TabIndex = 1; + addButton.Text = "addButton"; // //Label1 // - this.Label1.Location = new System.Drawing.Point(24, 192); - this.Label1.Name = "Label1"; - this.Label1.Size = new System.Drawing.Size(240, 23); - this.Label1.TabIndex = 2; - this.Label1.Text = "Label1"; + Label1.Location = new System.Drawing.Point(24, 192); + Label1.Name = "Label1"; + Label1.Size = new System.Drawing.Size(240, 23); + Label1.TabIndex = 2; + Label1.Text = "Label1"; // //Label2 // - this.Label2.Location = new System.Drawing.Point(24, 224); - this.Label2.Name = "Label2"; - this.Label2.Size = new System.Drawing.Size(240, 23); - this.Label2.TabIndex = 3; - this.Label2.Text = "Label2"; + Label2.Location = new System.Drawing.Point(24, 224); + Label2.Name = "Label2"; + Label2.Size = new System.Drawing.Size(240, 23); + Label2.TabIndex = 3; + Label2.Text = "Label2"; // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Label2); - this.Controls.Add(this.Label1); - this.Controls.Add(this.addButton); - this.Controls.Add(this.subtractButton); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new System.Drawing.Size(292, 266); + Controls.Add(Label2); + Controls.Add(Label1); + Controls.Add(addButton); + Controls.Add(subtractButton); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion @@ -145,10 +142,10 @@ private void CreatePointsAndSizes(PaintEventArgs e) Size buttonSize = (Size)startPoint; if (buttonSize == subtractButton.Size) - // If the sizes are equal, tell the user. + // If the sizes are equal, tell the user. { - e.Graphics.DrawString("The sizes are equal.", - new Font(this.Font, FontStyle.Italic), + e.Graphics.DrawString("The sizes are equal.", + new Font(Font, FontStyle.Italic), Brushes.Indigo, 10.0F, 65.0F); } } @@ -168,12 +165,12 @@ private void ShowPropertiesOfSlateBlue(PaintEventArgs e) byte b = slateBlue.B; byte r = slateBlue.R; byte a = slateBlue.A; - string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " + - "red:{1}, green: {2}, blue {3}", new object[]{a, r, g, b}); - e.Graphics.DrawString(text, - new Font(this.Font, FontStyle.Italic), - new SolidBrush(slateBlue), - new RectangleF(new PointF(0.0F, 0.0F), this.Size)); + string text = string.Format("Slate Blue has these ARGB values: Alpha:{0}, " + + "red:{1}, green: {2}, blue {3}", new object[] { a, r, g, b }); + e.Graphics.DrawString(text, + new Font(Font, FontStyle.Italic), + new SolidBrush(slateBlue), + new RectangleF(new PointF(0.0F, 0.0F), Size)); } // @@ -189,7 +186,7 @@ private void Form1_Paint(object sender, PaintEventArgs e) // named subtractionButton and associate this method with the // button's Click event. // - private void subtractButton_Click(System.Object sender, System.EventArgs e) + private void subtractButton_Click(object sender, System.EventArgs e) { subtractButton.Size = subtractButton.Size - new Size(10, 10); } @@ -200,7 +197,7 @@ private void subtractButton_Click(System.Object sender, System.EventArgs e) // this example, paste it into a form that contains a button named // addButton and associate this method with the button's Click event. // - private void addButton_Click(System.Object sender, System.EventArgs e) + private void addButton_Click(object sender, System.EventArgs e) { addButton.Size = addButton.Size + new Size(10, 10); } @@ -225,12 +222,12 @@ private void TruncateAndRoundSizes() Size truncatedSize = Size.Truncate(theSize); //Print out the values on two labels. - Label1.Text = "Rounded size = "+roundedSize.ToString(); - Label2.Text = "Truncated size = "+truncatedSize.ToString(); + Label1.Text = "Rounded size = " + roundedSize.ToString(); + Label2.Text = "Truncated size = " + truncatedSize.ToString(); } // -// The following code example demonstrates how to use the + // The following code example demonstrates how to use the // Point#ctor(int) and Size#ctor(int, int) constructors and the // ContentAlignment enumeration. To run this example paste this code into // a Windows Form that contains a label named Label1 and call the diff --git a/snippets/csharp/System.Drawing/ColorConverter/Overview/form1.cs b/snippets/csharp/System.Drawing/ColorConverter/Overview/form1.cs index e0174e1bf36..7bfc46b3afa 100644 --- a/snippets/csharp/System.Drawing/ColorConverter/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/ColorConverter/Overview/form1.cs @@ -1,15 +1,15 @@ -using System.Drawing; -using System; +using System; +using System.Drawing; using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); @@ -22,10 +22,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -42,10 +39,10 @@ private void InitializeComponent() // // Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Name = "Form1"; - this.Text = "Form1"; - this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); + ClientSize = new System.Drawing.Size(292, 266); + Name = "Form1"; + Text = "Form1"; + Paint += new System.Windows.Forms.PaintEventHandler(Form1_Paint); } #endregion @@ -61,10 +58,10 @@ private void ShowPointConverter(PaintEventArgs e) { // Create the PointConverter. - System.ComponentModel.TypeConverter converter = + System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Point)); - Point point1 = (Point) converter.ConvertFromString("200, 200"); + Point point1 = (Point)converter.ConvertFromString("200, 200"); // Use the subtraction operator to get a second point. Point point2 = point1 - new Size(190, 190); @@ -80,18 +77,18 @@ private void ShowPointConverter(PaintEventArgs e) // into a form and call the ShowColorConverter method when // handling the form's Paint event, passing e as PaintEventArgs. // - + private void ShowColorConverter(PaintEventArgs e) { Color myColor = Color.PaleVioletRed; // Create the ColorConverter. - System.ComponentModel.TypeConverter converter = + System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(myColor); string colorAsString = converter.ConvertToString(Color.PaleVioletRed); - e.Graphics.DrawString(colorAsString, this.Font, + e.Graphics.DrawString(colorAsString, Font, Brushes.PaleVioletRed, 50.0F, 50.0F); } // @@ -107,10 +104,10 @@ private void ShowFontStringConversion(PaintEventArgs e) { // Create the FontConverter. - System.ComponentModel.TypeConverter converter = + System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font)); - Font font1 = (Font) converter.ConvertFromString("Arial, 12pt"); + Font font1 = (Font)converter.ConvertFromString("Arial, 12pt"); string fontName1 = converter.ConvertToInvariantString(font1); string fontName2 = converter.ConvertToString(font1); diff --git a/snippets/csharp/System.Drawing/ColorTranslator/FromHtml/form1.cs b/snippets/csharp/System.Drawing/ColorTranslator/FromHtml/form1.cs index bff7b281c79..a2ec69b95ce 100644 --- a/snippets/csharp/System.Drawing/ColorTranslator/FromHtml/form1.cs +++ b/snippets/csharp/System.Drawing/ColorTranslator/FromHtml/form1.cs @@ -1,61 +1,58 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicColorTranslatorCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.ColorTranslator.FromHtml(System.String) // @@ -63,12 +60,12 @@ public void FromHtml_Example(PaintEventArgs e) { // Create a string representation of an HTML color. string htmlColor = "Blue"; - + // Translate htmlColor to a GDI+ Color structure. Color myColor = ColorTranslator.FromHtml(htmlColor); - + // Fill a rectangle with myColor. - e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0, + e.Graphics.FillRectangle(new SolidBrush(myColor), 0, 0, 100, 100); } // @@ -79,12 +76,12 @@ public void FromOle_Example(PaintEventArgs e) { // Create an integer representation of an OLE color. int oleColor = 0xFF00; - + // Translate oleColor to a GDI+ Color structure. Color myColor = ColorTranslator.FromOle(oleColor); - + // Fill a rectangle with myColor. - e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0, + e.Graphics.FillRectangle(new SolidBrush(myColor), 0, 0, 100, 100); } // @@ -95,12 +92,12 @@ public void FromWin32_Example(PaintEventArgs e) { // Create an integer representation of a Windows color. int winColor = 0xA000; - + // Translate winColor to a GDI+ Color structure. Color myColor = ColorTranslator.FromWin32(winColor); - + // Fill a rectangle with myColor. - e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0, + e.Graphics.FillRectangle(new SolidBrush(myColor), 0, 0, 100, 100); } // @@ -111,10 +108,10 @@ public void ToHtml_Example(PaintEventArgs e) { // Create an instance of a Color structure. Color myColor = Color.Red; - + // Translate myColor to an HTML color. string htmlColor = ColorTranslator.ToHtml(myColor); - + // Show a message box with the value of htmlColor. MessageBox.Show(htmlColor); } @@ -124,12 +121,12 @@ public void ToHtml_Example(PaintEventArgs e) // public void ToOle_Example(PaintEventArgs e) { - // Create an instance of a Color structure. + // Create an instance of a Color structure. Color myColor = Color.Red; - + // Translate myColor to an OLE color. int oleColor = ColorTranslator.ToOle(myColor); - + // Show a message box with the value of oleColor. MessageBox.Show(oleColor.ToString()); } @@ -141,22 +138,22 @@ public void ToWin32_Example(PaintEventArgs e) { // Create an instance of a Color structure. Color myColor = Color.Red; - + // Translate myColor to an OLE color. int winColor = ColorTranslator.ToWin32(myColor); - + // Show a message box with the value of winColor. MessageBox.Show(winColor.ToString()); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Font/Clone/form1.cs b/snippets/csharp/System.Drawing/Font/Clone/form1.cs index d889d187abf..4473083066c 100644 --- a/snippets/csharp/System.Drawing/Font/Clone/form1.cs +++ b/snippets/csharp/System.Drawing/Font/Clone/form1.cs @@ -1,61 +1,58 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicFontExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.Font.Clone // @@ -63,10 +60,10 @@ public void Clone_Example(PaintEventArgs e) { // Create a Font object. Font myFont = new Font("Arial", 16); - + // Create a copy of myFont. Font cloneFont = (Font)myFont.Clone(); - + // Use cloneFont to draw text to the screen. e.Graphics.DrawString("This is a cloned font", cloneFont, Brushes.Black, 0, 0); @@ -79,13 +76,13 @@ public void Equals_Example(PaintEventArgs e) { // Create a Font object. Font firstFont = new Font("Arial", 16); - + // Create a second Font object. Font secondFont = new Font(new FontFamily("Arial"), 16); - + // Test to see if firstFont is identical to secondFont. bool fontTest = firstFont.Equals(secondFont); - + // Display a message box with the result of the test. MessageBox.Show(fontTest.ToString()); } @@ -97,16 +94,16 @@ public void Equals_Example(PaintEventArgs e) private static extern IntPtr GetStockObject(int fnObject); public void FromHfont_Example(PaintEventArgs e) { - + // Get a handle for a GDI font. IntPtr hFont = GetStockObject(0); - + // Create a Font object from hFont. Font hfontFont = Font.FromHfont(hFont); - + // Use hfontFont to draw text to the screen. e.Graphics.DrawString( - "This font is from a GDI HFONT", hfontFont,Brushes.Black, + "This font is from a GDI HFONT", hfontFont, Brushes.Black, 0, 0); } // @@ -115,13 +112,13 @@ public void FromHfont_Example(PaintEventArgs e) // public void GetHashCode_Example(PaintEventArgs e) { - + // Create a Font object. Font myFont = new Font("Arial", 16); - + // Get the hash code for myFont. int hashCode = myFont.GetHashCode(); - + // Display the hash code in a message box. MessageBox.Show(hashCode.ToString()); } @@ -131,17 +128,17 @@ public void GetHashCode_Example(PaintEventArgs e) // public void GetHeight_Example(PaintEventArgs e) { - + // Create a Font object. Font myFont = new Font("Arial", 16); - + //Draw text to the screen with myFont. - e.Graphics.DrawString("This is the first line",myFont, + e.Graphics.DrawString("This is the first line", myFont, Brushes.Black, new PointF(0, 0)); - + //Get the height of myFont. float height = myFont.GetHeight(e.Graphics); - + //Draw text immediately below the first line of text. e.Graphics.DrawString( "This is the second line", @@ -154,21 +151,21 @@ public void GetHeight_Example(PaintEventArgs e) // Snippet for: M:System.Drawing.Font.ToHfont // - //Reference the GDI DeleteObject method. + //Reference the GDI DeleteObject method. [System.Runtime.InteropServices.DllImport("GDI32.dll")] - public static extern bool DeleteObject(IntPtr objectHandle); + public static extern bool DeleteObject(IntPtr objectHandle); public void ToHfont_Example(PaintEventArgs e) { // Create a Font object. Font myFont = new Font("Arial", 16); - + // Get a handle to the Font object. IntPtr hFont = myFont.ToHfont(); - + // Display a message box with the value of hFont. MessageBox.Show(hFont.ToString()); - + //Dispose of the hFont. DeleteObject(hFont); } @@ -180,22 +177,22 @@ public void ToString_Example(PaintEventArgs e) { // Create a Font object. Font myFont = new Font("Arial", 16); - + // Get a string that represents myFont. string fontString = myFont.ToString(); - + // Display a message box with fontString. MessageBox.Show(fontString); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Font/Overview/form1.cs b/snippets/csharp/System.Drawing/Font/Overview/form1.cs index 863ebb94d33..f689a027a91 100644 --- a/snippets/csharp/System.Drawing/Font/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/Font/Overview/form1.cs @@ -2,18 +2,18 @@ using System.Drawing; using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.ComboBox1.SelectedIndexChanged += + ComboBox1.SelectedIndexChanged += new EventHandler(ComboBox1_SelectedIndexChanged); //Add any initialization after the InitializeComponent() call @@ -24,10 +24,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -40,59 +37,59 @@ protected override void Dispose(bool disposing) //Do not modify it using the code editor. internal System.Windows.Forms.ComboBox ComboBox1; internal System.Windows.Forms.Label Label1; -internal System.Windows.Forms.Button Button1; + internal System.Windows.Forms.Button Button1; internal System.Windows.Forms.Button Button2; [System.Diagnostics.DebuggerStepThrough] private void InitializeComponent() { - this.ComboBox1 = new System.Windows.Forms.ComboBox(); - this.Label1 = new System.Windows.Forms.Label(); -this.Button1 = new System.Windows.Forms.Button(); - this.Button2 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + ComboBox1 = new System.Windows.Forms.ComboBox(); + Label1 = new System.Windows.Forms.Label(); + Button1 = new System.Windows.Forms.Button(); + Button2 = new System.Windows.Forms.Button(); + SuspendLayout(); // //ComboBox1 // - this.ComboBox1.Items.AddRange(new object[]{"Smaller", "Bigger"}); - this.ComboBox1.Location = new System.Drawing.Point(64, 32); - this.ComboBox1.Name = "ComboBox1"; - this.ComboBox1.Size = new System.Drawing.Size(121, 21); - this.ComboBox1.TabIndex = 0; + ComboBox1.Items.AddRange(["Smaller", "Bigger"]); + ComboBox1.Location = new System.Drawing.Point(64, 32); + ComboBox1.Name = "ComboBox1"; + ComboBox1.Size = new System.Drawing.Size(121, 21); + ComboBox1.TabIndex = 0; // //Label1 // - this.Label1.Location = new System.Drawing.Point(48, 136); - this.Label1.Name = "Label1"; - this.Label1.Size = new System.Drawing.Size(184, 88); - this.Label1.TabIndex = 1; - this.Label1.Text = "Some text to change."; - // + Label1.Location = new System.Drawing.Point(48, 136); + Label1.Name = "Label1"; + Label1.Size = new System.Drawing.Size(184, 88); + Label1.TabIndex = 1; + Label1.Text = "Some text to change."; + // // Button1 - // - this.Button1.Location = new System.Drawing.Point(192, 56); - this.Button1.Name = "Button1"; - this.Button1.TabIndex = 2; - this.Button1.Text = "Button1"; - this.Button1.Click += new System.EventHandler(this.Button1_Click); + // + Button1.Location = new System.Drawing.Point(192, 56); + Button1.Name = "Button1"; + Button1.TabIndex = 2; + Button1.Text = "Button1"; + Button1.Click += new System.EventHandler(Button1_Click); // // Button2 // - this.Button2.Location = new System.Drawing.Point(200, 8); - this.Button2.Name = "Button2"; - this.Button2.TabIndex = 3; - this.Button2.Text = "Button2"; - this.Button2.Click += new System.EventHandler(this.Button2_Click); + Button2.Location = new System.Drawing.Point(200, 8); + Button2.Name = "Button2"; + Button2.TabIndex = 3; + Button2.Text = "Button2"; + Button2.Click += new System.EventHandler(Button2_Click); // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Controls.Add(this.Label1); - this.Controls.Add(this.ComboBox1); -this.Controls.Add(this.Button2); - this.Controls.Add(this.Button1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); + ClientSize = new System.Drawing.Size(292, 266); + Controls.Add(Label1); + Controls.Add(ComboBox1); + Controls.Add(Button2); + Controls.Add(Button1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); } #endregion @@ -105,15 +102,15 @@ private void InitializeComponent() // SelectedIndexChanged event of the ComboBox control. // - private void ComboBox1_SelectedIndexChanged(System.Object sender, + private void ComboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { // Cast the sender object back to a ComboBox. - ComboBox ComboBox1 = (ComboBox) sender; + ComboBox ComboBox1 = (ComboBox)sender; // Retrieve the selected item. - string selectedString = (string) ComboBox1.SelectedItem; + string selectedString = (string)ComboBox1.SelectedItem; // Convert it to lowercase. selectedString = selectedString.ToLower(); @@ -122,16 +119,16 @@ private void ComboBox1_SelectedIndexChanged(System.Object sender, float currentSize; // Switch on the selected item. - switch(selectedString) + switch (selectedString) { - // If Bigger is selected, get the current size from the - // Size property and increase it. Reset the font to the - // new size, using the current unit. + // If Bigger is selected, get the current size from the + // Size property and increase it. Reset the font to the + // new size, using the current unit. case "bigger": currentSize = Label1.Font.Size; currentSize += 2.0F; - Label1.Font = new Font(Label1.Font.Name, currentSize, + Label1.Font = new Font(Label1.Font.Name, currentSize, Label1.Font.Style, Label1.Font.Unit); // If Smaller is selected, get the current size, in points, @@ -141,25 +138,25 @@ private void ComboBox1_SelectedIndexChanged(System.Object sender, case "smaller": currentSize = Label1.Font.SizeInPoints; currentSize -= 1; - Label1.Font = new Font(Label1.Font.Name, currentSize, + Label1.Font = new Font(Label1.Font.Name, currentSize, Label1.Font.Style); break; } } // -// The following code example demonstrates how to use the + // The following code example demonstrates how to use the // Font.#ctor(Font, FontStyle) constructor. To run this example, paste this code into // a Windows Form that contains a button named Button1, and associate the // Button1_Click method with the Click event of the button. // - private void Button1_Click(System.Object sender, System.EventArgs e) + private void Button1_Click(object sender, System.EventArgs e) { - Button1.Font = new Font(this.Font, FontStyle.Italic); + Button1.Font = new Font(Font, FontStyle.Italic); } // - -// The following code example demonstrates how to use + + // The following code example demonstrates how to use // the Font.#ctor(FontFamily, Single, FontStyle, GraphicsUnit) constructor. // This example is designed to be used with Windows // Forms. To run this example paste this code into a form that contains a @@ -167,10 +164,10 @@ private void Button1_Click(System.Object sender, System.EventArgs e) // the Click event of the button. // - private void Button2_Click(System.Object sender, System.EventArgs e) + private void Button2_Click(object sender, System.EventArgs e) { - Button2.Font = new Font(FontFamily.GenericMonospace, 12.0F, + Button2.Font = new Font(FontFamily.GenericMonospace, 12.0F, FontStyle.Italic, GraphicsUnit.Pixel); } // diff --git a/snippets/csharp/System.Drawing/FontFamily/Equals/form1.cs b/snippets/csharp/System.Drawing/FontFamily/Equals/form1.cs index fe427a1ae79..5134c71a9bc 100644 --- a/snippets/csharp/System.Drawing/FontFamily/Equals/form1.cs +++ b/snippets/csharp/System.Drawing/FontFamily/Equals/form1.cs @@ -1,61 +1,58 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicFontFamilyCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.FontFamily.Equals(System.Object) // @@ -64,10 +61,10 @@ public void Equals_Example(PaintEventArgs e) // Create two FontFamily objects. FontFamily firstFontFamily = new FontFamily("Arial"); FontFamily secondFontFamily = new FontFamily("Times New Roman"); - + // Check to see if the two font families are equivalent. bool equalFonts = firstFontFamily.Equals(secondFontFamily); - + // Display the result of the test in a message box. MessageBox.Show(equalFonts.ToString()); } @@ -79,10 +76,10 @@ public void GetCellAscent_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily ascentFontFamily = new FontFamily("arial"); - + // Get the cell ascent of the font family in design units. int cellAscent = ascentFontFamily.GetCellAscent(FontStyle.Regular); - + // Draw the result as a string to the screen. e.Graphics.DrawString( "ascentFontFamily.GetCellAscent() returns " + cellAscent.ToString() + ".", @@ -98,10 +95,10 @@ public void GetCellDescent_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily descentFontFamily = new FontFamily("arial"); - + // Get the cell descent of the font family in design units. int cellDescent = descentFontFamily.GetCellDescent(FontStyle.Regular); - + // Draw the result as a string to the screen. e.Graphics.DrawString( "descentFontFamily.GetCellDescent() returns " + cellDescent.ToString() + ".", @@ -117,10 +114,10 @@ public void GetEmHeight_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily emFontFamily = new FontFamily("arial"); - + // Get the em height of the font family in design units. int emHeight = emFontFamily.GetEmHeight(FontStyle.Regular); - + // Draw the result as a string to the screen. e.Graphics.DrawString( "emFontFamily.GetEmHeight() returns " + emHeight.ToString() + ".", @@ -128,35 +125,35 @@ public void GetEmHeight_Example(PaintEventArgs e) Brushes.Black, new PointF(0, 0)); } - // + // + + // Snippet for: M:System.Drawing.FontFamily.GetFamilies(System.Drawing.Graphics) + // + public void GetFamilies_Example(PaintEventArgs e) + { + // Get an array of the available font families. + FontFamily[] families = FontFamily.GetFamilies(e.Graphics); + + // Draw text using each of the font families. + Font familiesFont; + string familyString; + float spacing = 0; -// Snippet for: M:System.Drawing.FontFamily.GetFamilies(System.Drawing.Graphics) - // - public void GetFamilies_Example(PaintEventArgs e) + foreach (FontFamily family in families) { - // Get an array of the available font families. - FontFamily[] families = FontFamily.GetFamilies(e.Graphics); - - // Draw text using each of the font families. - Font familiesFont; - string familyString; - float spacing = 0; - - foreach (FontFamily family in families) + if (family.IsStyleAvailable(FontStyle.Regular)) { - if (family.IsStyleAvailable(FontStyle.Regular)) - { - familiesFont = new Font(family, 16); - familyString = "This is the " + family.Name + " family."; - e.Graphics.DrawString( - familyString, - familiesFont, - Brushes.Black, - new PointF(0, spacing)); - spacing += familiesFont.Height; - } + familiesFont = new Font(family, 16); + familyString = "This is the " + family.Name + " family."; + e.Graphics.DrawString( + familyString, + familiesFont, + Brushes.Black, + new PointF(0, spacing)); + spacing += familiesFont.Height; } } + } // // Snippet for: M:System.Drawing.FontFamily.GetHashCode @@ -165,10 +162,10 @@ public void GetHashCode_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily myFontFamily = new FontFamily("Arial"); - + // Get the hash code for myFontFamily. int hashCode = myFontFamily.GetHashCode(); - + // Draw the value of hashCode to the screen as a string. e.Graphics.DrawString( "hashCode = " + hashCode.ToString(), @@ -184,10 +181,10 @@ public void GetLineSpacing_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily myFontFamily = new FontFamily("Arial"); - + // Get the line spacing for myFontFamily. int lineSpacing = myFontFamily.GetLineSpacing(FontStyle.Regular); - + // Draw the value of lineSpacing to the screen as a string. e.Graphics.DrawString( "lineSpacing = " + lineSpacing.ToString(), @@ -203,10 +200,10 @@ public void GetName_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily myFontFamily = new FontFamily("Arial"); - + // Get the name of myFontFamily. string familyName = myFontFamily.GetName(0); - + // Draw the name of the myFontFamily to the screen as a string. e.Graphics.DrawString( "The family name is " + familyName, @@ -222,14 +219,14 @@ public void IsStyleAvailable_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily myFontFamily = new FontFamily("Arial"); - + // Test whether myFontFamily is available in Italic. - if(myFontFamily.IsStyleAvailable(FontStyle.Italic)) + if (myFontFamily.IsStyleAvailable(FontStyle.Italic)) { - + // Create a Font object using myFontFamily. Font familyFont = new Font(myFontFamily, 16, FontStyle.Italic); - + // Use familyFont to draw text to the screen. e.Graphics.DrawString( myFontFamily.Name + " is available in Italic", @@ -246,7 +243,7 @@ public void ToString_Example(PaintEventArgs e) { // Create a FontFamily object. FontFamily myFontFamily = new FontFamily("Arial"); - + // Draw a string representation of myFontFamily to the screen. e.Graphics.DrawString( myFontFamily.ToString(), @@ -256,13 +253,13 @@ public void ToString_Example(PaintEventArgs e) } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Graphics/Clip/form1.cs b/snippets/csharp/System.Drawing/Graphics/Clip/form1.cs index 32811100fa1..ae30a773a47 100644 --- a/snippets/csharp/System.Drawing/Graphics/Clip/form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/Clip/form1.cs @@ -1,20 +1,20 @@ using System; using System.Drawing; -using System.Windows.Forms; using System.Drawing.Drawing2D; +using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.Paint += new PaintEventHandler(Form1_Paint); + Paint += new PaintEventHandler(Form1_Paint); //Add any initialization after the InitializeComponent() call } @@ -24,10 +24,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -44,9 +41,9 @@ private void InitializeComponent() // //Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Name = "Form1"; - this.Text = "Form1"; + ClientSize = new System.Drawing.Size(292, 266); + Name = "Form1"; + Text = "Form1"; } #endregion @@ -66,7 +63,7 @@ private void FillRegionExcludingPath(PaintEventArgs e) Region myRegion = new Region(new Rectangle(20, 20, 100, 100)); // Create the GraphicsPath. - System.Drawing.Drawing2D.GraphicsPath path = + System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); // Add a circle to the graphics path. @@ -177,7 +174,7 @@ private void SetAndFillClip(PaintEventArgs e) // Demonstrate the clip region by drawing a string // at the outer edge of the region. - e.Graphics.DrawString("Outside of Clip", new Font("Arial", + e.Graphics.DrawString("Outside of Clip", new Font("Arial", 12.0F, FontStyle.Regular), Brushes.Black, 0.0F, 0.0F); } // @@ -197,37 +194,37 @@ private void ChangeTextRenderingHintAndTextContrast(PaintEventArgs e) Graphics formGraphics = e.Graphics; // Declare a new font. - Font myFont = new Font(FontFamily.GenericSansSerif, 20, + Font myFont = new Font(FontFamily.GenericSansSerif, 20, FontStyle.Regular); // Set the TextRenderingHint property. - formGraphics.TextRenderingHint = + formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; // Draw the string. - formGraphics.DrawString("Hello World", myFont, + formGraphics.DrawString("Hello World", myFont, Brushes.Firebrick, 20.0F, 20.0F); // Change the TextRenderingHint property. - formGraphics.TextRenderingHint = + formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; // Draw the string again. - formGraphics.DrawString("Hello World", myFont, + formGraphics.DrawString("Hello World", myFont, Brushes.Firebrick, 20.0F, 60.0F); // Set the text contrast to a high-contrast setting. formGraphics.TextContrast = 0; // Draw the string. - formGraphics.DrawString("Hello World", myFont, + formGraphics.DrawString("Hello World", myFont, Brushes.DodgerBlue, 20.0F, 100.0F); // Set the text contrast to a low-contrast setting. formGraphics.TextContrast = 12; // Draw the string again. - formGraphics.DrawString("Hello World", myFont, + formGraphics.DrawString("Hello World", myFont, Brushes.DodgerBlue, 20.0F, 140.0F); // Dispose of the font object. diff --git a/snippets/csharp/System.Drawing/Graphics/CopyFromScreen/Form1.cs b/snippets/csharp/System.Drawing/Graphics/CopyFromScreen/Form1.cs index 2253ee5c06d..3463648b793 100644 --- a/snippets/csharp/System.Drawing/Graphics/CopyFromScreen/Form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/CopyFromScreen/Form1.cs @@ -1,8 +1,8 @@ // using System; -using System.Windows.Forms; using System.Drawing; using System.Drawing.Printing; +using System.Windows.Forms; public class Form1 : Form @@ -15,7 +15,7 @@ public Form1() printButton.Text = "Print Form"; printButton.Click += new EventHandler(printButton_Click); printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); - this.Controls.Add(printButton); + Controls.Add(printButton); } void printButton_Click(object sender, EventArgs e) @@ -28,14 +28,14 @@ void printButton_Click(object sender, EventArgs e) private void CaptureScreen() { - Graphics myGraphics = this.CreateGraphics(); - Size s = this.Size; + Graphics myGraphics = CreateGraphics(); + Size s = Size; memoryImage = new Bitmap(s.Width, s.Height, myGraphics); Graphics memoryGraphics = Graphics.FromImage(memoryImage); - memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s); + memoryGraphics.CopyFromScreen(Location.X, Location.Y, 0, 0, s); } - private void printDocument1_PrintPage(System.Object sender, + private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(memoryImage, 0, 0); diff --git a/snippets/csharp/System.Drawing/Graphics/DrawImage/form1.cs b/snippets/csharp/System.Drawing/Graphics/DrawImage/form1.cs index 5230a44a7bd..3826d4aa3b7 100644 --- a/snippets/csharp/System.Drawing/Graphics/DrawImage/form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/DrawImage/form1.cs @@ -1,11 +1,11 @@ using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.Drawing.Drawing2D; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using System.Windows.Forms; namespace System.Drawing.ClassicGraphicsExamples2CS { @@ -34,16 +34,13 @@ public Form1() /// /// Clean up any resources being used. /// - protected override void Dispose( bool disposing ) + protected override void Dispose(bool disposing) { - if( disposing ) + if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } - base.Dispose( disposing ); + base.Dispose(disposing); } #region Windows Form Designer generated code @@ -53,9 +50,9 @@ protected override void Dispose( bool disposing ) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; } #endregion @@ -65,58 +62,58 @@ private void InitializeComponent() // Define DrawImageAbort callback method. private bool DrawImageCallback8(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageRect4FloatAttribAbortData(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback8); IntPtr imageCallbackData = new IntPtr(1); - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); - + // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); - + // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); - + // Draw adjusted image to screen. try { checked { - + // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, @@ -144,13 +141,13 @@ Graphics.DrawImageAbort imageCallback // public void DrawImageRectF(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying image. RectangleF rect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F); - + // Draw image to screen. e.Graphics.DrawImage(newImage, rect); } @@ -160,17 +157,17 @@ public void DrawImageRectF(PaintEventArgs e) // public void DrawImageRectFRectF(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying image. RectangleF destRect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F); - + // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, srcRect, units); } @@ -180,14 +177,14 @@ public void DrawImageRectFRectF(PaintEventArgs e) // public void DrawImage2Int(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner of image. int x = 100; int y = 100; - + // Draw image to screen. e.Graphics.DrawImage(newImage, x, y); } @@ -197,18 +194,18 @@ public void DrawImage2Int(PaintEventArgs e) // public void DrawImage2IntRect(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner of image. int x = 100; int y = 100; - + // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, srcRect, units); } @@ -218,18 +215,18 @@ public void DrawImage2IntRect(PaintEventArgs e) // public void DrawImage4Int(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner. - + // of image and for size of image. int x = 100; int y = 100; int width = 450; int height = 150; - + // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, width, height); } @@ -239,14 +236,14 @@ public void DrawImage4Int(PaintEventArgs e) // public void DrawImage2Float(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner of image. float x = 100.0F; float y = 100.0F; - + // Draw image to screen. e.Graphics.DrawImage(newImage, x, y); } @@ -256,18 +253,18 @@ public void DrawImage2Float(PaintEventArgs e) // public void DrawImage2FloatRectF(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner of image. float x = 100.0F; float y = 100.0F; - + // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, srcRect, units); } @@ -277,18 +274,18 @@ public void DrawImage2FloatRectF(PaintEventArgs e) // public void DrawImage4Float(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner. - + // of image and for size of image. float x = 100.0F; float y = 100.0F; float width = 450.0F; float height = 150.0F; - + // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, width, height); } @@ -298,13 +295,13 @@ public void DrawImage4Float(PaintEventArgs e) // public void DrawImageUnscaledPoint(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create point for upper-left corner of image. Point ulCorner = new Point(100, 100); - + // Draw image to screen. e.Graphics.DrawImageUnscaled(newImage, ulCorner); } @@ -314,14 +311,14 @@ public void DrawImageUnscaledPoint(PaintEventArgs e) // public void DrawImageUnscaledInt(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create coordinates for upper-left corner of image. int x = 100; int y = 100; - + // Draw image to screen. e.Graphics.DrawImageUnscaled(newImage, x, y); } @@ -331,14 +328,14 @@ public void DrawImageUnscaledInt(PaintEventArgs e) // public void DrawLinePoint(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points that define line. Point point1 = new Point(100, 100); Point point2 = new Point(500, 100); - + // Draw line to screen. e.Graphics.DrawLine(blackPen, point1, point2); } @@ -348,14 +345,14 @@ public void DrawLinePoint(PaintEventArgs e) // public void DrawLinePointF(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points that define line. PointF point1 = new PointF(100.0F, 100.0F); PointF point2 = new PointF(500.0F, 100.0F); - + // Draw line to screen. e.Graphics.DrawLine(blackPen, point1, point2); } @@ -365,16 +362,16 @@ public void DrawLinePointF(PaintEventArgs e) // public void DrawLineInt(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create coordinates of points that define line. int x1 = 100; int y1 = 100; int x2 = 500; int y2 = 100; - + // Draw line to screen. e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); } @@ -384,16 +381,16 @@ public void DrawLineInt(PaintEventArgs e) // public void DrawLineFloat(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create coordinates of points that define line. float x1 = 100.0F; float y1 = 100.0F; float x2 = 500.0F; float y2 = 100.0F; - + // Draw line to screen. e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); } @@ -403,19 +400,19 @@ public void DrawLineFloat(PaintEventArgs e) // public void DrawLinesPoint(PaintEventArgs e) { - + // Create pen. Pen pen = new Pen(Color.Black, 3); - + // Create array of points that define lines to draw. Point[] points = - { + [ new Point(10, 10), new Point(10, 100), new Point(200, 50), new Point(250, 300) - }; - + ]; + //Draw lines to screen. e.Graphics.DrawLines(pen, points); } @@ -425,19 +422,19 @@ public void DrawLinesPoint(PaintEventArgs e) // public void DrawLinesPointF(PaintEventArgs e) { - + // Create pen. Pen pen = new Pen(Color.Black, 3); - + // Create array of points that define lines to draw. PointF[] points = - { + [ new PointF(10.0F, 10.0F), new PointF(10.0F, 100.0F), new PointF(200.0F, 50.0F), new PointF(250.0F, 300.0F) - }; - + ]; + //Draw lines to screen. e.Graphics.DrawLines(pen, points); } @@ -447,14 +444,14 @@ public void DrawLinesPointF(PaintEventArgs e) // public void DrawPathEllipse(PaintEventArgs e) { - + // Create graphics path object and add ellipse. GraphicsPath graphPath = new GraphicsPath(); graphPath.AddEllipse(0, 0, 200, 100); - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Draw graphics path to screen. e.Graphics.DrawPath(blackPen, graphPath); } @@ -464,17 +461,17 @@ public void DrawPathEllipse(PaintEventArgs e) // public void DrawPieRectangle(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create rectangle for ellipse. Rectangle rect = new Rectangle(0, 0, 200, 100); - + // Create start and sweep angles. - float startAngle = 0.0F; + float startAngle = 0.0F; float sweepAngle = 45.0F; - + // Draw pie to screen. e.Graphics.DrawPie(blackPen, rect, startAngle, sweepAngle); } @@ -484,17 +481,17 @@ public void DrawPieRectangle(PaintEventArgs e) // public void DrawPieRectangleF(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create rectangle for ellipse. RectangleF rect = new RectangleF(0.0F, 0.0F, 200.0F, 100.0F); - + // Create start and sweep angles. - float startAngle = 0.0F; + float startAngle = 0.0F; float sweepAngle = 45.0F; - + // Draw pie to screen. e.Graphics.DrawPie(blackPen, rect, startAngle, sweepAngle); } @@ -504,20 +501,20 @@ public void DrawPieRectangleF(PaintEventArgs e) // public void DrawPieInt(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create location and size of ellipse. int x = 0; int y = 0; int width = 200; int height = 100; - + // Create start and sweep angles. - int startAngle = 0; + int startAngle = 0; int sweepAngle = 45; - + // Draw pie to screen. e.Graphics.DrawPie(blackPen, x, y, width, height, startAngle, sweepAngle); } @@ -527,20 +524,20 @@ public void DrawPieInt(PaintEventArgs e) // public void DrawPieFloat(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create location and size of ellipse. float x = 0.0F; float y = 0.0F; float width = 200.0F; float height = 100.0F; - + // Create start and sweep angles. - float startAngle = 0.0F; + float startAngle = 0.0F; float sweepAngle = 45.0F; - + // Draw pie to screen. e.Graphics.DrawPie(blackPen, x, y, width, height, startAngle, sweepAngle); } @@ -550,20 +547,20 @@ public void DrawPieFloat(PaintEventArgs e) // public void DrawPolygonPointF(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points that define polygon. - PointF point1 = new PointF(50.0F, 50.0F); - PointF point2 = new PointF(100.0F, 25.0F); - PointF point3 = new PointF(200.0F, 5.0F); - PointF point4 = new PointF(250.0F, 50.0F); + PointF point1 = new PointF(50.0F, 50.0F); + PointF point2 = new PointF(100.0F, 25.0F); + PointF point3 = new PointF(200.0F, 5.0F); + PointF point4 = new PointF(250.0F, 50.0F); PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); PointF[] curvePoints = - { + [ point1, point2, point3, @@ -571,8 +568,8 @@ public void DrawPolygonPointF(PaintEventArgs e) point5, point6, point7 - }; - + ]; + // Draw polygon curve to screen. e.Graphics.DrawPolygon(blackPen, curvePoints); } @@ -582,20 +579,20 @@ public void DrawPolygonPointF(PaintEventArgs e) // public void DrawPolygonPoint(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points that define polygon. - Point point1 = new Point(50, 50); - Point point2 = new Point(100, 25); - Point point3 = new Point(200, 5); - Point point4 = new Point(250, 50); + Point point1 = new Point(50, 50); + Point point2 = new Point(100, 25); + Point point3 = new Point(200, 5); + Point point4 = new Point(250, 50); Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); Point[] curvePoints = - { + [ point1, point2, point3, @@ -603,8 +600,8 @@ public void DrawPolygonPoint(PaintEventArgs e) point5, point6, point7 - }; - + ]; + // Draw polygon to screen. e.Graphics.DrawPolygon(blackPen, curvePoints); } @@ -614,13 +611,13 @@ public void DrawPolygonPoint(PaintEventArgs e) // public void DrawRectangleRectangle(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create rectangle. Rectangle rect = new Rectangle(0, 0, 200, 200); - + // Draw rectangle to screen. e.Graphics.DrawRectangle(blackPen, rect); } @@ -630,16 +627,16 @@ public void DrawRectangleRectangle(PaintEventArgs e) // public void DrawRectangleInt(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create location and size of rectangle. int x = 0; int y = 0; int width = 200; int height = 200; - + // Draw rectangle to screen. e.Graphics.DrawRectangle(blackPen, x, y, width, height); } @@ -649,16 +646,16 @@ public void DrawRectangleInt(PaintEventArgs e) // public void DrawRectangleFloat(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create location and size of rectangle. float x = 0.0F; float y = 0.0F; float width = 200.0F; float height = 200.0F; - + // Draw rectangle to screen. e.Graphics.DrawRectangle(blackPen, x, y, width, height); } @@ -668,18 +665,18 @@ public void DrawRectangleFloat(PaintEventArgs e) // public void DrawRectanglesRectangle(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create array of rectangles. Rectangle[] rects = - { + [ new Rectangle( 0, 0, 100, 200), new Rectangle(100, 200, 250, 50), new Rectangle(300, 0, 50, 100) - }; - + ]; + // Draw rectangles to screen. e.Graphics.DrawRectangles(blackPen, rects); } @@ -689,18 +686,18 @@ public void DrawRectanglesRectangle(PaintEventArgs e) // public void DrawRectanglesRectangleF(PaintEventArgs e) { - + // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create array of rectangles. RectangleF[] rects = - { + [ new RectangleF( 0.0F, 0.0F, 100.0F, 200.0F), new RectangleF(100.0F, 200.0F, 250.0F, 50.0F), new RectangleF(300.0F, 0.0F, 50.0F, 100.0F) - }; - + ]; + // Draw rectangles to screen. e.Graphics.DrawRectangles(blackPen, rects); } @@ -710,17 +707,17 @@ public void DrawRectanglesRectangleF(PaintEventArgs e) // public void DrawStringPointF(PaintEventArgs e) { - + // Create string to draw. - String drawString = "Sample Text"; - + string drawString = "Sample Text"; + // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); - + // Create point for upper-left corner of drawing. PointF drawPoint = new PointF(150.0F, 150.0F); - + // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint); } @@ -730,21 +727,23 @@ public void DrawStringPointF(PaintEventArgs e) // public void DrawStringPointFFormat(PaintEventArgs e) { - + // Create string to draw. - String drawString = "Sample Text"; - + string drawString = "Sample Text"; + // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); - + // Create point for upper-left corner of drawing. PointF drawPoint = new PointF(150.0F, 50.0F); - + // Set format of string. - StringFormat drawFormat = new StringFormat(); - drawFormat.FormatFlags = StringFormatFlags.DirectionVertical; - + StringFormat drawFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; + // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint, drawFormat); } @@ -754,25 +753,25 @@ public void DrawStringPointFFormat(PaintEventArgs e) // public void DrawStringRectangleF(PaintEventArgs e) { - + // Create string to draw. - String drawString = "Sample Text"; - + string drawString = "Sample Text"; + // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); - + // Create rectangle for drawing. float x = 150.0F; float y = 150.0F; float width = 200.0F; float height = 50.0F; RectangleF drawRect = new RectangleF(x, y, width, height); - + // Draw rectangle to screen. Pen blackPen = new Pen(Color.Black); e.Graphics.DrawRectangle(blackPen, x, y, width, height); - + // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect); } @@ -782,29 +781,31 @@ public void DrawStringRectangleF(PaintEventArgs e) // public void DrawStringRectangleFFormat(PaintEventArgs e) { - + // Create string to draw. - String drawString = "Sample Text"; - + string drawString = "Sample Text"; + // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); - + // Create rectangle for drawing. float x = 150.0F; float y = 150.0F; float width = 200.0F; float height = 50.0F; RectangleF drawRect = new RectangleF(x, y, width, height); - + // Draw rectangle to screen. Pen blackPen = new Pen(Color.Black); e.Graphics.DrawRectangle(blackPen, x, y, width, height); - + // Set format of string. - StringFormat drawFormat = new StringFormat(); - drawFormat.Alignment = StringAlignment.Center; - + StringFormat drawFormat = new StringFormat + { + Alignment = StringAlignment.Center + }; + // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect, drawFormat); } @@ -814,18 +815,18 @@ public void DrawStringRectangleFFormat(PaintEventArgs e) // public void DrawStringFloat(PaintEventArgs e) { - + // Create string to draw. - String drawString = "Sample Text"; - + string drawString = "Sample Text"; + // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); - + // Create point for upper-left corner of drawing. float x = 150.0F; float y = 150.0F; - + // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y); } @@ -835,22 +836,24 @@ public void DrawStringFloat(PaintEventArgs e) // public void DrawStringFloatFormat(PaintEventArgs e) { - + // Create string to draw. - String drawString = "Sample Text"; - + string drawString = "Sample Text"; + // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); - + // Create point for upper-left corner of drawing. float x = 150.0F; - float y = 50.0F; - + float y = 50.0F; + // Set format of string. - StringFormat drawFormat = new StringFormat(); - drawFormat.FormatFlags = StringFormatFlags.DirectionVertical; - + StringFormat drawFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; + // Draw string to screen. e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat); } @@ -860,19 +863,19 @@ public void DrawStringFloatFormat(PaintEventArgs e) // public void EndContainerState(PaintEventArgs e) { - + // Begin graphics container. GraphicsContainer containerState = e.Graphics.BeginContainer(); - + // Translate world transformation. e.Graphics.TranslateTransform(100.0F, 100.0F); - + // Fill translated rectangle in container with red. e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); - + // End graphics container. e.Graphics.EndContainer(containerState); - + // Fill untransformed rectangle with green. e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0, 0, 200, 200); } @@ -882,16 +885,16 @@ public void EndContainerState(PaintEventArgs e) // public void ExcludeClipRegion(PaintEventArgs e) { - + // Create rectangle for region. Rectangle excludeRect = new Rectangle(100, 100, 200, 200); - + // Create region for exclusion. Region excludeRegion = new Region(excludeRect); - + // Set clipping region to exclude region. e.Graphics.ExcludeClip(excludeRegion); - + // Fill large rectangle to show clipping region. e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 300, 300); } @@ -901,13 +904,13 @@ public void ExcludeClipRegion(PaintEventArgs e) // public void ExcludeClipRectangle(PaintEventArgs e) { - + // Create rectangle for exclusion. Rectangle excludeRect = new Rectangle(100, 100, 200, 200); - + // Set clipping region to exclude rectangle. e.Graphics.ExcludeClip(excludeRect); - + // Fill large rectangle to show clipping region. e.Graphics.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 300, 300); } @@ -917,17 +920,17 @@ public void ExcludeClipRectangle(PaintEventArgs e) // public void FillClosedCurvePoint(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + //Create array of points for curve. Point point1 = new Point(100, 100); - Point point2 = new Point(200, 50); + Point point2 = new Point(200, 50); Point point3 = new Point(250, 200); Point point4 = new Point(50, 150); - Point[] points = {point1, point2, point3, point4}; - + Point[] points = [point1, point2, point3, point4]; + // Fill curve on screen. e.Graphics.FillClosedCurve(redBrush, points); } @@ -937,20 +940,20 @@ public void FillClosedCurvePoint(PaintEventArgs e) // public void FillClosedCurvePointFillMode(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + //Create array of points for curve. Point point1 = new Point(100, 100); - Point point2 = new Point(200, 50); + Point point2 = new Point(200, 50); Point point3 = new Point(250, 200); Point point4 = new Point(50, 150); - Point[] points = {point1, point2, point3, point4}; - + Point[] points = [point1, point2, point3, point4]; + // Set fill mode. FillMode newFillMode = FillMode.Winding; - + // Fill curve on screen. e.Graphics.FillClosedCurve(redBrush, points, newFillMode); } @@ -960,23 +963,23 @@ public void FillClosedCurvePointFillMode(PaintEventArgs e) // public void FillClosedCurvePointFillModeTension(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create array of points for curve. Point point1 = new Point(100, 100); - Point point2 = new Point(200, 50); + Point point2 = new Point(200, 50); Point point3 = new Point(250, 200); Point point4 = new Point(50, 150); - Point[] points = {point1, point2, point3, point4}; - + Point[] points = [point1, point2, point3, point4]; + // Set fill mode. FillMode newFillMode = FillMode.Winding; - + // Set tension. float tension = 1.0F; - + // Fill curve on screen. e.Graphics.FillClosedCurve(redBrush, points, newFillMode, tension); } @@ -986,17 +989,17 @@ public void FillClosedCurvePointFillModeTension(PaintEventArgs e) // public void FillClosedCurvePointF(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + //Create array of points for curve. PointF point1 = new PointF(100.0F, 100.0F); - PointF point2 = new PointF(200.0F, 50.0F); + PointF point2 = new PointF(200.0F, 50.0F); PointF point3 = new PointF(250.0F, 200.0F); PointF point4 = new PointF(50.0F, 150.0F); - PointF[] points = {point1, point2, point3, point4}; - + PointF[] points = [point1, point2, point3, point4]; + // Fill curve on screen. e.Graphics.FillClosedCurve(redBrush, points); } @@ -1006,20 +1009,20 @@ public void FillClosedCurvePointF(PaintEventArgs e) // public void FillClosedCurvePointFFillMode(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create array of points for curve. PointF point1 = new PointF(100.0F, 100.0F); - PointF point2 = new PointF(200.0F, 50.0F); + PointF point2 = new PointF(200.0F, 50.0F); PointF point3 = new PointF(250.0F, 200.0F); PointF point4 = new PointF(50.0F, 150.0F); - PointF[] points = {point1, point2, point3, point4}; - + PointF[] points = [point1, point2, point3, point4]; + // Set fill mode. FillMode newFillMode = FillMode.Winding; - + // Fill curve on screen. e.Graphics.FillClosedCurve(redBrush, points, newFillMode); } @@ -1029,23 +1032,23 @@ public void FillClosedCurvePointFFillMode(PaintEventArgs e) // public void FillClosedCurvePointFFillModeTension(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create array of points for curve. PointF point1 = new PointF(100.0F, 100.0F); - PointF point2 = new PointF(200.0F, 50.0F); + PointF point2 = new PointF(200.0F, 50.0F); PointF point3 = new PointF(250.0F, 200.0F); PointF point4 = new PointF(50.0F, 150.0F); - PointF[] points = {point1, point2, point3, point4}; - + PointF[] points = [point1, point2, point3, point4]; + // Set fill mode. FillMode newFillMode = FillMode.Winding; - + // Set tension. float tension = 1.0F; - + // Fill curve on screen. e.Graphics.FillClosedCurve(redBrush, points, newFillMode, tension); } @@ -1055,17 +1058,17 @@ public void FillClosedCurvePointFFillModeTension(PaintEventArgs e) // public void FillEllipseRectangle(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create rectangle for ellipse. int x = 0; int y = 0; int width = 200; int height = 100; Rectangle rect = new Rectangle(x, y, width, height); - + // Fill ellipse on screen. e.Graphics.FillEllipse(redBrush, rect); } @@ -1075,17 +1078,17 @@ public void FillEllipseRectangle(PaintEventArgs e) // public void FillEllipseRectangleF(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create rectangle for ellipse. float x = 0.0F; float y = 0.0F; float width = 200.0F; float height = 100.0F; RectangleF rect = new RectangleF(x, y, width, height); - + // Fill ellipse on screen. e.Graphics.FillEllipse(redBrush, rect); } @@ -1095,16 +1098,16 @@ public void FillEllipseRectangleF(PaintEventArgs e) // public void FillEllipseInt(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create location and size of ellipse. int x = 0; int y = 0; int width = 200; int height = 100; - + // Fill ellipse on screen. e.Graphics.FillEllipse(redBrush, x, y, width, height); } @@ -1114,16 +1117,16 @@ public void FillEllipseInt(PaintEventArgs e) // public void FillEllipseFloat(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create location and size of ellipse. float x = 0.0F; float y = 0.0F; float width = 200.0F; float height = 100.0F; - + // Fill ellipse on screen. e.Graphics.FillEllipse(redBrush, x, y, width, height); } @@ -1133,14 +1136,14 @@ public void FillEllipseFloat(PaintEventArgs e) // public void FillPathEllipse(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create graphics path object and add ellipse. GraphicsPath graphPath = new GraphicsPath(); graphPath.AddEllipse(0, 0, 200, 100); - + // Fill graphics path to screen. e.Graphics.FillPath(redBrush, graphPath); } @@ -1150,17 +1153,17 @@ public void FillPathEllipse(PaintEventArgs e) // public void FillPieRectangle(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create rectangle for ellipse. Rectangle rect = new Rectangle(0, 0, 200, 100); - + // Create start and sweep angles. - float startAngle = 0.0F; + float startAngle = 0.0F; float sweepAngle = 45.0F; - + // Fill pie to screen. e.Graphics.FillPie(redBrush, rect, startAngle, sweepAngle); } @@ -1170,20 +1173,20 @@ public void FillPieRectangle(PaintEventArgs e) // public void FillPieInt(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create location and size of ellipse. int x = 0; int y = 0; int width = 200; int height = 100; - + // Create start and sweep angles. - int startAngle = 0; + int startAngle = 0; int sweepAngle = 45; - + // Fill pie to screen. e.Graphics.FillPie(redBrush, x, y, width, height, startAngle, sweepAngle); } @@ -1193,20 +1196,20 @@ public void FillPieInt(PaintEventArgs e) // public void FillPieFloat(PaintEventArgs e) { - + // Create solid brush. SolidBrush redBrush = new SolidBrush(Color.Red); - + // Create location and size of ellipse. float x = 0.0F; float y = 0.0F; float width = 200.0F; float height = 100.0F; - + // Create start and sweep angles. - float startAngle = 0.0F; + float startAngle = 0.0F; float sweepAngle = 45.0F; - + // Fill pie to screen. e.Graphics.FillPie(redBrush, x, y, width, height, startAngle, sweepAngle); } @@ -1228,7 +1231,7 @@ public void FillPolygonPoint(PaintEventArgs e) Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); - Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + Point[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw polygon to screen. e.Graphics.FillPolygon(blueBrush, curvePoints); @@ -1251,7 +1254,7 @@ public void FillPolygonPointFillMode(PaintEventArgs e) Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); - Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + Point[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Define fill mode. FillMode newFillMode = FillMode.Winding; @@ -1277,7 +1280,7 @@ public void FillPolygonPointF(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Fill polygon to screen. e.Graphics.FillPolygon(blueBrush, curvePoints); @@ -1300,7 +1303,7 @@ public void FillPolygonPointFFillMode(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Define fill mode. FillMode newFillMode = FillMode.Winding; @@ -1314,7 +1317,7 @@ public void FillPolygonPointFFillMode(PaintEventArgs e) /// The main entry point for the application. /// [STAThread] - static void Main() + static void Main() { Application.Run(new Form1()); } diff --git a/snippets/csharp/System.Drawing/Graphics/EnumerateMetafile/Form1.cs b/snippets/csharp/System.Drawing/Graphics/EnumerateMetafile/Form1.cs index fbb471fe883..7304a3e4d93 100644 --- a/snippets/csharp/System.Drawing/Graphics/EnumerateMetafile/Form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/EnumerateMetafile/Form1.cs @@ -3,10 +3,9 @@ using System; using System.Drawing; using System.Drawing.Imaging; -using System.Windows.Forms; - // for Marshal.Copy -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; +using System.Windows.Forms; public class Form1 : Form { @@ -49,4 +48,4 @@ static void Main() Application.Run(new Form1()); } } -// \ No newline at end of file +// diff --git a/snippets/csharp/System.Drawing/Graphics/FillRectangle/form1.cs b/snippets/csharp/System.Drawing/Graphics/FillRectangle/form1.cs index d5b33c81b87..7eeb0ef2ab7 100644 --- a/snippets/csharp/System.Drawing/Graphics/FillRectangle/form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/FillRectangle/form1.cs @@ -1,11 +1,11 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; +using System.Windows.Forms; namespace System.Drawing.ClassicGraphicsExamples3CS { @@ -38,10 +38,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -53,9 +50,9 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300, 300); - this.Text = "Form1"; + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; } #endregion @@ -138,7 +135,7 @@ private void FillRectanglesRectangle(PaintEventArgs e) SolidBrush blueBrush = new SolidBrush(Color.Blue); // Create array of rectangles. - Rectangle[] rects = { new Rectangle(0, 0, 100, 200), new Rectangle(100, 200, 250, 50), new Rectangle(300, 0, 50, 100) }; + Rectangle[] rects = [new Rectangle(0, 0, 100, 200), new Rectangle(100, 200, 250, 50), new Rectangle(300, 0, 50, 100)]; // Fill rectangles to screen. e.Graphics.FillRectangles(blueBrush, rects); @@ -154,7 +151,7 @@ private void FillRectanglesRectangleF(PaintEventArgs e) SolidBrush blueBrush = new SolidBrush(Color.Blue); // Create array of rectangles. - RectangleF[] rects = { new RectangleF(0.0F, 0.0F, 100.0F, 200.0F), new RectangleF(100.0F, 200.0F, 250.0F, 50.0F), new RectangleF(300.0F, 0.0F, 50.0F, 100.0F) }; + RectangleF[] rects = [new RectangleF(0.0F, 0.0F, 100.0F, 200.0F), new RectangleF(100.0F, 200.0F, 250.0F, 50.0F), new RectangleF(300.0F, 0.0F, 50.0F, 100.0F)]; // Fill rectangles to screen. e.Graphics.FillRectangles(blueBrush, rects); @@ -205,7 +202,7 @@ private void FromHwndHwnd(PaintEventArgs e) { // Get handle to form. - IntPtr hwnd = this.Handle; + IntPtr hwnd = Handle; // Create new graphics object using handle to window. Graphics newGraphics = Graphics.FromHwnd(hwnd); @@ -644,7 +641,7 @@ private void MeasureCharacterRangesRegions(PaintEventArgs e) Font stringFont = new Font("Times New Roman", 16.0F); // Set character ranges to "First" and "Second". - CharacterRange[] characterRanges = { new CharacterRange(0, 5), new CharacterRange(10, 6) }; + CharacterRange[] characterRanges = [new CharacterRange(0, 5), new CharacterRange(10, 6)]; // Create rectangle for layout. float x = 50.0F; @@ -654,16 +651,18 @@ private void MeasureCharacterRangesRegions(PaintEventArgs e) RectangleF layoutRect = new RectangleF(x, y, width, height); // Set string format. - StringFormat stringFormat = new StringFormat(); - stringFormat.FormatFlags = StringFormatFlags.DirectionVertical; + StringFormat stringFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; stringFormat.SetMeasurableCharacterRanges(characterRanges); // Draw string to screen. e.Graphics.DrawString(measureString, stringFont, Brushes.Black, x, y, stringFormat); // Measure two ranges in string. - Region[] stringRegions = e.Graphics.MeasureCharacterRanges(measureString, - stringFont, layoutRect, stringFormat); + Region[] stringRegions = e.Graphics.MeasureCharacterRanges(measureString, + stringFont, layoutRect, stringFormat); // Draw rectangle for first measured range. RectangleF measureRect1 = stringRegions[0].GetBounds(e.Graphics); @@ -711,8 +710,10 @@ private void MeasureStringPointFFormat(PaintEventArgs e) PointF ulCorner = new PointF(x, y); // Set string format. - StringFormat newStringFormat = new StringFormat(); - newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical; + StringFormat newStringFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; // Measure string. SizeF stringSize = new SizeF(); @@ -763,8 +764,10 @@ private void MeasureStringSizeFFormat(PaintEventArgs e) SizeF layoutSize = new SizeF(100.0F, 200.0F); // Set string format. - StringFormat newStringFormat = new StringFormat(); - newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical; + StringFormat newStringFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; // Measure string. SizeF stringSize = new SizeF(); @@ -791,8 +794,10 @@ private void MeasureStringSizeFFormatInts(PaintEventArgs e) SizeF layoutSize = new SizeF(100.0F, 200.0F); // Set string format. - StringFormat newStringFormat = new StringFormat(); - newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical; + StringFormat newStringFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; // Measure string. int charactersFitted; @@ -849,8 +854,10 @@ private void MeasureStringWidthFormat(PaintEventArgs e) int stringWidth = 100; // Set string format. - StringFormat newStringFormat = new StringFormat(); - newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical; + StringFormat newStringFormat = new StringFormat + { + FormatFlags = StringFormatFlags.DirectionVertical + }; // Measure string. SizeF stringSize = new SizeF(); @@ -1143,7 +1150,7 @@ private void SetClipGraphics(PaintEventArgs e) { // Create temporary graphics object and set its clipping region. - Graphics newGraphics = this.CreateGraphics(); + Graphics newGraphics = CreateGraphics(); newGraphics.SetClip(new Rectangle(0, 0, 100, 100)); // Update clipping region of graphics to clipping region of new @@ -1165,7 +1172,7 @@ private void SetClipGraphicsCombine(PaintEventArgs e) { // Create temporary graphics object and set its clipping region. - Graphics newGraphics = this.CreateGraphics(); + Graphics newGraphics = CreateGraphics(); newGraphics.SetClip(new Rectangle(0, 0, 100, 100)); // Update clipping region of graphics to clipping region of new @@ -1267,7 +1274,7 @@ private void TransformPointsPoint(PaintEventArgs e) { // Create array of two points. - Point[] points = { new Point(0, 0), new Point(100, 50) }; + Point[] points = [new Point(0, 0), new Point(100, 50)]; // Draw line connecting two untransformed points. e.Graphics.DrawLine(new Pen(Color.Blue, 3), points[0], points[1]); @@ -1292,7 +1299,7 @@ private void TransformPointsPointF(PaintEventArgs e) { // Create array of two points. - PointF[] points = { new PointF(0.0F, 0.0F), new PointF(100.0F, 50.0F) }; + PointF[] points = [new PointF(0.0F, 0.0F), new PointF(100.0F, 50.0F)]; // Draw line connecting two untransformed points. e.Graphics.DrawLine(new Pen(Color.Blue, 3), points[0], points[1]); diff --git a/snippets/csharp/System.Drawing/Graphics/Overview/form1.cs b/snippets/csharp/System.Drawing/Graphics/Overview/form1.cs index 427cb30e844..fcb686bd23f 100644 --- a/snippets/csharp/System.Drawing/Graphics/Overview/form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/Overview/form1.cs @@ -1,64 +1,61 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; -using System.Drawing.Imaging; +using System.Drawing; using System.Drawing.Drawing2D; +using System.Drawing.Imaging; using System.Drawing.Text; +using System.Windows.Forms; namespace System.Drawing.ClassicGraphicsExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.Graphics.AddMetafileComment(System.Byte[]) // @@ -66,40 +63,40 @@ private void AddMetafileCommentBytes(PaintEventArgs e) { // Create temporary Graphics object for metafile // creation and get handle to its device context. - Graphics newGraphics = this.CreateGraphics(); + Graphics newGraphics = CreateGraphics(); IntPtr hdc = newGraphics.GetHdc(); - + // Create metafile object to record. Metafile metaFile1 = new Metafile("SampMeta.emf", hdc); - + // Create graphics object to record metaFile. Graphics metaGraphics = Graphics.FromImage(metaFile1); - + // Draw rectangle in metaFile. metaGraphics.DrawRectangle(new Pen(Color.Black, 5), 0, 0, 100, 100); - + // Create comment and add to metaFile. - byte[] metaComment = {(byte)'T', (byte)'e', (byte)'s', (byte)'t'}; + byte[] metaComment = [(byte)'T', (byte)'e', (byte)'s', (byte)'t']; metaGraphics.AddMetafileComment(metaComment); - + // Dispose of graphics object. metaGraphics.Dispose(); - + // Dispose of metafile. metaFile1.Dispose(); - + // Release handle to temporary device context. newGraphics.ReleaseHdc(hdc); - + // Dispose of scratch graphics object. newGraphics.Dispose(); - + // Create existing metafile object to draw. Metafile metaFile2 = new Metafile("SampMeta.emf"); - + // Draw metaFile to screen. e.Graphics.DrawImage(metaFile2, new Point(0, 0)); - + // Dispose of metafile. metaFile2.Dispose(); } @@ -111,16 +108,16 @@ private void BeginContainerVoid(PaintEventArgs e) { // Begin graphics container. GraphicsContainer containerState = e.Graphics.BeginContainer(); - + // Translate world transformation. e.Graphics.TranslateTransform(100.0F, 100.0F); - + // Fill translated rectangle in container with red. e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); - + // End graphics container. e.Graphics.EndContainer(containerState); - + // Fill untransformed rectangle with green. e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0, 0, 200, 200); } @@ -133,18 +130,18 @@ private void BeginContainerRectangle(PaintEventArgs e) // Define transformation for container. Rectangle srcRect = new Rectangle(0, 0, 200, 200); Rectangle destRect = new Rectangle(100, 100, 150, 150); - + // Begin graphics container. GraphicsContainer containerState = e.Graphics.BeginContainer( destRect, srcRect, GraphicsUnit.Pixel); - + // Fill red rectangle in container. e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); - + // End graphics container. e.Graphics.EndContainer(containerState); - + // Fill untransformed rectangle with green. e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0, 0, 200, 200); } @@ -157,18 +154,18 @@ private void BeginContainerRectangleF(PaintEventArgs e) // Define transformation for container. RectangleF srcRect = new RectangleF(0.0F, 0.0F, 200.0F, 200.0F); RectangleF destRect = new RectangleF(100.0F, 100.0F, 150.0F, 150.0F); - + // Begin graphics container. GraphicsContainer containerState = e.Graphics.BeginContainer( destRect, srcRect, GraphicsUnit.Pixel); - + // Fill red rectangle in container. e.Graphics.FillRectangle(new SolidBrush(Color.Red), 0.0F, 0.0F, 200.0F, 200.0F); - + // End graphics container. e.Graphics.EndContainer(containerState); - + // Fill untransformed rectangle with green. e.Graphics.FillRectangle(new SolidBrush(Color.Green), 0.0F, 0.0F, 200.0F, 200.0F); } @@ -189,16 +186,16 @@ private void FromImageImage1(PaintEventArgs e) { // Create image. Image imageFile = Image.FromFile("SampImag.jpg"); - + // Create graphics object for alteration. Graphics newGraphics = Graphics.FromImage(imageFile); - + // Alter image. newGraphics.FillRectangle(new SolidBrush(Color.Black), 100, 50, 100, 100); - + // Draw image to screen. e.Graphics.DrawImage(imageFile, new PointF(0.0F, 0.0F)); - + // Release graphics object. newGraphics.Dispose(); } @@ -208,16 +205,16 @@ private void FromImageImage1(PaintEventArgs e) // private void DrawArcRectangle(PaintEventArgs e) { - // Create pen. - Pen blackPen= new Pen(Color.Black, 3); - + // Create pen. + Pen blackPen = new Pen(Color.Black, 3); + // Create rectangle to bound ellipse. Rectangle rect = new Rectangle(0, 0, 100, 200); - + // Create start and sweep angles on ellipse. - float startAngle = 45.0F; + float startAngle = 45.0F; float sweepAngle = 270.0F; - + // Draw arc to screen. e.Graphics.DrawArc(blackPen, rect, startAngle, sweepAngle); } @@ -228,15 +225,15 @@ private void DrawArcRectangle(PaintEventArgs e) private void DrawArcRectangleF(PaintEventArgs e) { // Create pen. - Pen blackPen= new Pen(Color.Black, 3); - + Pen blackPen = new Pen(Color.Black, 3); + // Create rectangle to bound ellipse. RectangleF rect = new RectangleF(0.0F, 0.0F, 100.0F, 200.0F); - + // Create start and sweep angles on ellipse. - float startAngle = 45.0F; + float startAngle = 45.0F; float sweepAngle = 270.0F; - + // Draw arc to screen. e.Graphics.DrawArc(blackPen, rect, startAngle, sweepAngle); } @@ -247,18 +244,18 @@ private void DrawArcRectangleF(PaintEventArgs e) private void DrawArcInt(PaintEventArgs e) { // Create pen. - Pen blackPen= new Pen(Color.Black, 3); - + Pen blackPen = new Pen(Color.Black, 3); + // Create coordinates of rectangle to bound ellipse. int x = 0; int y = 0; int width = 100; int height = 200; - + // Create start and sweep angles on ellipse. - int startAngle = 45; + int startAngle = 45; int sweepAngle = 270; - + // Draw arc to screen. e.Graphics.DrawArc(blackPen, x, y, width, height, startAngle, sweepAngle); } @@ -269,18 +266,18 @@ private void DrawArcInt(PaintEventArgs e) private void DrawArcFloat(PaintEventArgs e) { // Create pen. - Pen blackPen= new Pen(Color.Black, 3); - + Pen blackPen = new Pen(Color.Black, 3); + // Create coordinates of rectangle to bound ellipse. float x = 0.0F; float y = 0.0F; float width = 100.0F; float height = 200.0F; - + // Create start and sweep angles on ellipse. - float startAngle = 45.0F; + float startAngle = 45.0F; float sweepAngle = 270.0F; - + // Draw arc to screen. e.Graphics.DrawArc(blackPen, x, y, width, height, startAngle, sweepAngle); } @@ -292,13 +289,13 @@ private void DrawBezierPoint(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points for curve. Point start = new Point(100, 100); Point control1 = new Point(200, 10); Point control2 = new Point(350, 50); Point end = new Point(500, 100); - + // Draw arc to screen. e.Graphics.DrawBezier(blackPen, start, control1, control2, end); } @@ -310,13 +307,13 @@ private void DrawBezierPointF(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points for curve. PointF start = new PointF(100.0F, 100.0F); PointF control1 = new PointF(200.0F, 10.0F); PointF control2 = new PointF(350.0F, 50.0F); PointF end = new PointF(500.0F, 100.0F); - + // Draw arc to screen. e.Graphics.DrawBezier(blackPen, start, control1, control2, end); } @@ -328,17 +325,17 @@ private void DrawBezierFloat(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create coordinates of points for curve. float startX = 100.0F; float startY = 100.0F; float controlX1 = 200.0F; - float controlY1 = 10.0F; + float controlY1 = 10.0F; float controlX2 = 350.0F; - float controlY2 = 50.0F; + float controlY2 = 50.0F; float endX = 500.0F; float endY = 100.0F; - + // Draw arc to screen. e.Graphics.DrawBezier(blackPen, startX, startY, controlX1, controlY1, @@ -353,7 +350,7 @@ private void DrawBeziersPoint(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points for curve. Point start = new Point(100, 100); Point control1 = new Point(200, 10); @@ -363,11 +360,11 @@ private void DrawBeziersPoint(PaintEventArgs e) Point control4 = new Point(650, 250); Point end2 = new Point(500, 300); Point[] bezierPoints = - { + [ start, control1, control2, end1, control3, control4, end2 - }; - + ]; + // Draw arc to screen. e.Graphics.DrawBeziers(blackPen, bezierPoints); } @@ -379,7 +376,7 @@ private void DrawBeziersPointF(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create points for curve. PointF start = new PointF(100.0F, 100.0F); PointF control1 = new PointF(200.0F, 10.0F); @@ -388,9 +385,9 @@ private void DrawBeziersPointF(PaintEventArgs e) PointF control3 = new PointF(600.0F, 150.0F); PointF control4 = new PointF(650.0F, 250.0F); PointF end2 = new PointF(500.0F, 300.0F); - PointF[] bezierPoints = { start, control1, control2, end1, - control3, control4, end2 }; - + PointF[] bezierPoints = [ start, control1, control2, end1, + control3, control4, end2 ]; + // Draw arc to screen. e.Graphics.DrawBeziers(blackPen, bezierPoints); } @@ -401,19 +398,19 @@ private void DrawBeziersPointF(PaintEventArgs e) private void DrawClosedCurvePoint(PaintEventArgs e) { // Create pens. - Pen redPen = new Pen(Color.Red, 3); + Pen redPen = new Pen(Color.Red, 3); Pen greenPen = new Pen(Color.Green, 3); - + // Create points that define curve. - Point point1 = new Point(50, 50); - Point point2 = new Point(100, 25); - Point point3 = new Point(200, 5); - Point point4 = new Point(250, 50); + Point point1 = new Point(50, 50); + Point point2 = new Point(100, 25); + Point point3 = new Point(200, 5); + Point point4 = new Point(250, 50); Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); Point[] curvePoints = - { + [ point1, point2, point3, @@ -421,11 +418,11 @@ private void DrawClosedCurvePoint(PaintEventArgs e) point5, point6, point7 - }; - + ]; + // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); - + // Draw closed curve to screen. e.Graphics.DrawClosedCurve(greenPen, curvePoints); } @@ -448,7 +445,7 @@ private void DrawClosedCurvePointTension(PaintEventArgs e) Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); - Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + Point[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -479,7 +476,7 @@ private void DrawClosedCurvePointF(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -506,7 +503,7 @@ private void DrawClosedCurvePointFTension(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -537,7 +534,7 @@ private void DrawCurvePoint(PaintEventArgs e) Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); - Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + Point[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -564,7 +561,7 @@ private void DrawCurvePointSegmentTension(PaintEventArgs e) Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); - Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + Point[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -596,7 +593,7 @@ private void DrawCurvePointTension(PaintEventArgs e) Point point5 = new Point(300, 100); Point point6 = new Point(350, 200); Point point7 = new Point(250, 250); - Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + Point[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -626,7 +623,7 @@ private void DrawCurvePointF(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -653,7 +650,7 @@ private void DrawCurvePointFSegments(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -684,7 +681,7 @@ private void DrawCurvePointFSegmentTension(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -716,7 +713,7 @@ private void DrawCurvePointFTension(PaintEventArgs e) PointF point5 = new PointF(300.0F, 100.0F); PointF point6 = new PointF(350.0F, 200.0F); PointF point7 = new PointF(250.0F, 250.0F); - PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7}; + PointF[] curvePoints = [point1, point2, point3, point4, point5, point6, point7]; // Draw lines between original points to screen. e.Graphics.DrawLines(redPen, curvePoints); @@ -735,10 +732,10 @@ private void DrawEllipseRectangle(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create rectangle for ellipse. Rectangle rect = new Rectangle(0, 0, 200, 100); - + // Draw ellipse to screen. e.Graphics.DrawEllipse(blackPen, rect); } @@ -750,10 +747,10 @@ private void DrawEllipseRectangleF(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create rectangle for ellipse. RectangleF rect = new RectangleF(0.0F, 0.0F, 200.0F, 100.0F); - + // Draw ellipse to screen. e.Graphics.DrawEllipse(blackPen, rect); } @@ -765,13 +762,13 @@ private void DrawEllipseInt(PaintEventArgs e) { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create location and size of ellipse. int x = 0; int y = 0; int width = 200; int height = 100; - + // Draw ellipse to screen. e.Graphics.DrawEllipse(blackPen, x, y, width, height); } @@ -780,16 +777,16 @@ private void DrawEllipseInt(PaintEventArgs e) // Snippet for: M:System.Drawing.Graphics.DrawEllipse(System.Drawing.Pen,System.Single,System.Single,System.Single,System.Single) // private void DrawEllipseFloat(PaintEventArgs e) - { + { // Create pen. Pen blackPen = new Pen(Color.Black, 3); - + // Create location and size of ellipse. float x = 0.0F; float y = 0.0F; float width = 200.0F; float height = 100.0F; - + // Draw ellipse to screen. e.Graphics.DrawEllipse(blackPen, x, y, width, height); } @@ -798,13 +795,13 @@ private void DrawEllipseFloat(PaintEventArgs e) // Snippet for: M:System.Drawing.Graphics.DrawIcon(System.Drawing.Icon,System.Drawing.Rectangle) // private void DrawIconRectangle(PaintEventArgs e) - { + { // Create icon. Icon newIcon = new Icon("SampIcon.ico"); - + // Create rectangle for icon. Rectangle rect = new Rectangle(100, 100, 200, 200); - + // Draw icon to screen. e.Graphics.DrawIcon(newIcon, rect); } @@ -816,11 +813,11 @@ private void DrawIconInt(PaintEventArgs e) { // Create icon. Icon newIcon = new Icon("SampIcon.ico"); - + // Create coordinates for upper-left corner of icon. int x = 100; int y = 100; - + // Draw icon to screen. e.Graphics.DrawIcon(newIcon, x, y); } @@ -832,10 +829,10 @@ private void DrawIconUnstretchedRectangle(PaintEventArgs e) { // Create icon. Icon newIcon = new Icon("SampIcon.ico"); - + // Create rectangle for icon. Rectangle rect = new Rectangle(100, 100, 200, 200); - + // Draw icon to screen. e.Graphics.DrawIconUnstretched(newIcon, rect); } @@ -844,13 +841,13 @@ private void DrawIconUnstretchedRectangle(PaintEventArgs e) // Snippet for: M:System.Drawing.Graphics.DrawImage(System.Drawing.Image,System.Drawing.Point) // private void DrawImagePoint(PaintEventArgs e) - { + { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create Point for upper-left corner of image. Point ulCorner = new Point(100, 100); - + // Draw image to screen. e.Graphics.DrawImage(newImage, ulCorner); } @@ -862,13 +859,13 @@ private void DrawImagePara(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(550, 100); Point llCorner = new Point(150, 250); - Point[] destPara = {ulCorner, urCorner, llCorner}; - + Point[] destPara = [ulCorner, urCorner, llCorner]; + // Draw image to screen. e.Graphics.DrawImage(newImage, destPara); } @@ -880,17 +877,17 @@ private void DrawImageParaRect(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(325, 100); Point llCorner = new Point(150, 250); - Point[] destPara = {ulCorner, urCorner, llCorner}; - + Point[] destPara = [ulCorner, urCorner, llCorner]; + // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, destPara, srcRect, units); } @@ -902,30 +899,30 @@ private void DrawImageParaRectAttrib(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing image. Point ulCorner1 = new Point(100, 100); Point urCorner1 = new Point(325, 100); Point llCorner1 = new Point(150, 250); - Point[] destPara1 = {ulCorner1, urCorner1, llCorner1}; - + Point[] destPara1 = [ulCorner1, urCorner1, llCorner1]; + // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); - + // Create parallelogram for drawing adjusted image. Point ulCorner2 = new Point(325, 100); Point urCorner2 = new Point(550, 100); Point llCorner2 = new Point(375, 250); - Point[] destPara2 = {ulCorner2, urCorner2, llCorner2}; - + Point[] destPara2 = [ulCorner2, urCorner2, llCorner2]; + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); - + // Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr); } @@ -937,50 +934,50 @@ private void DrawImageParaRectAttrib(PaintEventArgs e) // Define DrawImageAbort callback method. private bool DrawImageCallback1(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageParaRectAttribAbort(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback1); - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing original image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(550, 100); Point llCorner = new Point(150, 250); - Point[] destPara1 = {ulCorner, urCorner, llCorner}; - + Point[] destPara1 = [ulCorner, urCorner, llCorner]; + // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); - + // Create parallelogram for drawing adjusted image. Point ulCorner2 = new Point(325, 100); Point urCorner2 = new Point(550, 100); Point llCorner2 = new Point(375, 250); - Point[] destPara2 = {ulCorner2, urCorner2, llCorner2}; - + Point[] destPara2 = [ulCorner2, urCorner2, llCorner2]; + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -988,7 +985,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw image to screen. e.Graphics.DrawImage( newImage, @@ -1016,51 +1013,51 @@ Graphics.DrawImageAbort imageCallback // Define DrawImageAbort callback method. private bool DrawImageCallback2(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageParaRectAttribAbortData(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback2); int imageCallbackData = 1; - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing original image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(550, 100); Point llCorner = new Point(150, 250); - Point[] destPara1 = {ulCorner, urCorner, llCorner}; - + Point[] destPara1 = [ulCorner, urCorner, llCorner]; + // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); - + // Create parallelogram for drawing adjusted image. Point ulCorner2 = new Point(325, 100); Point urCorner2 = new Point(550, 100); Point llCorner2 = new Point(375, 250); - Point[] destPara2 = {ulCorner2, urCorner2, llCorner2}; - + Point[] destPara2 = [ulCorner2, urCorner2, llCorner2]; + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -1068,7 +1065,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw image to screen. e.Graphics.DrawImage( newImage, @@ -1095,13 +1092,13 @@ Graphics.DrawImageAbort imageCallback // private void DrawImagePointF(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create point for upper-left corner of image. PointF ulCorner = new PointF(100.0F, 100.0F); - + // Draw image to screen. e.Graphics.DrawImage(newImage, ulCorner); } @@ -1111,16 +1108,16 @@ private void DrawImagePointF(PaintEventArgs e) // private void DrawImageParaF(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing image. PointF ulCorner = new PointF(100.0F, 100.0F); PointF urCorner = new PointF(550.0F, 100.0F); PointF llCorner = new PointF(150.0F, 250.0F); - PointF[] destPara = {ulCorner, urCorner, llCorner}; - + PointF[] destPara = [ulCorner, urCorner, llCorner]; + // Draw image to screen. e.Graphics.DrawImage(newImage, destPara); } @@ -1130,20 +1127,20 @@ private void DrawImageParaF(PaintEventArgs e) // private void DrawImageParaFRectF(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing image. PointF ulCorner = new PointF(100.0F, 100.0F); PointF urCorner = new PointF(550.0F, 100.0F); PointF llCorner = new PointF(150.0F, 250.0F); - PointF[] destPara = {ulCorner, urCorner, llCorner}; - + PointF[] destPara = [ulCorner, urCorner, llCorner]; + // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, destPara, srcRect, units); } @@ -1153,33 +1150,33 @@ private void DrawImageParaFRectF(PaintEventArgs e) // private void DrawImageParaFRectFAttrib(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing original image. PointF ulCorner1 = new PointF(100.0F, 100.0F); PointF urCorner1 = new PointF(325.0F, 100.0F); PointF llCorner1 = new PointF(150.0F, 250.0F); - PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1}; - + PointF[] destPara1 = [ulCorner1, urCorner1, llCorner1]; + // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; - + // Create parallelogram for drawing adjusted image. PointF ulCorner2 = new PointF(325.0F, 100.0F); PointF urCorner2 = new PointF(550.0F, 100.0F); PointF llCorner2 = new PointF(375.0F, 250.0F); - PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2}; - + PointF[] destPara2 = [ulCorner2, urCorner2, llCorner2]; + // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); - + // Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr); } @@ -1191,50 +1188,50 @@ private void DrawImageParaFRectFAttrib(PaintEventArgs e) // Define DrawImageAbort callback method. private bool DrawImageCallback3(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageParaFRectAttribAbort(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback3); - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing original image. PointF ulCorner1 = new PointF(100.0F, 100.0F); PointF urCorner1 = new PointF(325.0F, 100.0F); PointF llCorner1 = new PointF(150.0F, 250.0F); - PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1}; - + PointF[] destPara1 = [ulCorner1, urCorner1, llCorner1]; + // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; - + // Create parallelogram for drawing adjusted image. PointF ulCorner2 = new PointF(325.0F, 100.0F); PointF urCorner2 = new PointF(550.0F, 100.0F); PointF llCorner2 = new PointF(375.0F, 250.0F); - PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2}; - + PointF[] destPara2 = [ulCorner2, urCorner2, llCorner2]; + // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -1242,7 +1239,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, @@ -1270,51 +1267,51 @@ Graphics.DrawImageAbort imageCallback // Define DrawImageAbort callback method. private bool DrawImageCallback4(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageParaFRectAttribAbortData(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback4); int imageCallbackData = 1; - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create parallelogram for drawing original image. PointF ulCorner1 = new PointF(100.0F, 100.0F); PointF urCorner1 = new PointF(325.0F, 100.0F); PointF llCorner1 = new PointF(150.0F, 250.0F); - PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1}; - + PointF[] destPara1 = [ulCorner1, urCorner1, llCorner1]; + // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; - + // Create parallelogram for drawing adjusted image. PointF ulCorner2 = new PointF(325.0F, 100.0F); PointF urCorner2 = new PointF(550.0F, 100.0F); PointF llCorner2 = new PointF(375.0F, 250.0F); - PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2}; - + PointF[] destPara2 = [ulCorner2, urCorner2, llCorner2]; + // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -1322,7 +1319,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, @@ -1349,13 +1346,13 @@ Graphics.DrawImageAbort imageCallback // private void DrawImageRect(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); - + // Draw image to screen. e.Graphics.DrawImage(newImage, destRect); } @@ -1365,17 +1362,17 @@ private void DrawImageRect(PaintEventArgs e) // private void DrawImageRectRect(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); - + // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, srcRect, units); } @@ -1385,20 +1382,20 @@ private void DrawImageRectRect(PaintEventArgs e) // private void DrawImageRect4Int(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); - + // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units); } @@ -1408,30 +1405,30 @@ private void DrawImageRect4Int(PaintEventArgs e) // private void DrawImageRect4IntAtrrib(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); - + // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); - + // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); - + // Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr); } @@ -1443,47 +1440,47 @@ private void DrawImageRect4IntAtrrib(PaintEventArgs e) // Define DrawImageAbort callback method. private bool DrawImageCallback5(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageRect4IntAtrribAbort(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback5); - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); - + // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); - + // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -1491,7 +1488,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, @@ -1520,48 +1517,48 @@ Graphics.DrawImageAbort imageCallback // Define DrawImageAbort callback method. private bool DrawImageCallback6(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageRect4IntAtrribAbortData(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback6); IntPtr imageCallbackData = new IntPtr(1); - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); - + // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); - + // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -1569,7 +1566,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, @@ -1597,20 +1594,20 @@ Graphics.DrawImageAbort imageCallback // private void DrawImageRect4Float(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); - + // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units); } @@ -1620,30 +1617,30 @@ private void DrawImageRect4Float(PaintEventArgs e) // private void DrawImageRect4FloatAttrib(PaintEventArgs e) { - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); - + // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); - + // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); - + // Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr); } @@ -1655,47 +1652,47 @@ private void DrawImageRect4FloatAttrib(PaintEventArgs e) // Define DrawImageAbort callback method. private bool DrawImageCallback7(IntPtr callBackData) { - + // Test for call that passes callBackData parameter. - if(callBackData==IntPtr.Zero) + if (callBackData == IntPtr.Zero) { - + // If no callBackData passed, abort DrawImage method. return true; } else { - + // If callBackData passed, continue DrawImage method. return false; } } private void DrawImageRect4FloatAttribAbort(PaintEventArgs e) { - + // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback7); - + // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); - + // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; - + // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); - + // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); - + // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); @@ -1703,7 +1700,7 @@ Graphics.DrawImageAbort imageCallback { checked { - + // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, @@ -1729,25 +1726,25 @@ Graphics.DrawImageAbort imageCallback // Snippet for: T:System.Drawing.Image // private void ImageExampleForm_Paint(object sender, PaintEventArgs e) - { + { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); - + // Create Point for upper-left corner of image. Point ulCorner = new Point(100, 100); - + // Draw image to screen. e.Graphics.DrawImage(newImage, ulCorner); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Graphics/SmoothingMode/form1.cs b/snippets/csharp/System.Drawing/Graphics/SmoothingMode/form1.cs index 8741e8bd3df..a7d8559ba96 100644 --- a/snippets/csharp/System.Drawing/Graphics/SmoothingMode/form1.cs +++ b/snippets/csharp/System.Drawing/Graphics/SmoothingMode/form1.cs @@ -2,18 +2,18 @@ using System.Drawing; using System.Windows.Forms; -public class Form1: +public class Form1 : System.Windows.Forms.Form { #region " Windows Form Designer generated code " public Form1() : base() - { + { //This call is required by the Windows Form Designer. InitializeComponent(); - this.Paint += new PaintEventHandler(Form1_Paint); + Paint += new PaintEventHandler(Form1_Paint); //Add any initialization after the InitializeComponent() call } @@ -23,10 +23,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - if (components != null) - { - components.Dispose(); - } + components?.Dispose(); } base.Dispose(disposing); } @@ -41,7 +38,7 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { components = new System.ComponentModel.Container(); - this.Text = "Form1"; + Text = "Form1"; } #endregion @@ -57,16 +54,17 @@ private void ShowLineJoin(PaintEventArgs e) { // Create a new pen. - Pen skyBluePen = new Pen(Brushes.DeepSkyBlue); - - // Set the pen's width. - skyBluePen.Width = 8.0F; + Pen skyBluePen = new Pen(Brushes.DeepSkyBlue) + { + // Set the pen's width. + Width = 8.0F, - // Set the LineJoin property. - skyBluePen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel; + // Set the LineJoin property. + LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel + }; // Draw a rectangle. - e.Graphics.DrawRectangle(skyBluePen, + e.Graphics.DrawRectangle(skyBluePen, new Rectangle(40, 40, 150, 200)); //Dispose of the pen. @@ -86,13 +84,14 @@ private void ShowStartAndEndCaps(PaintEventArgs e) { // Create a new custom pen. - Pen redPen = new Pen(Brushes.Red, 6.0F); - - // Set the StartCap property. - redPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; + Pen redPen = new Pen(Brushes.Red, 6.0F) + { + // Set the StartCap property. + StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor, - // Set the EndCap property. - redPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; + // Set the EndCap property. + EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor + }; // Draw a line. e.Graphics.DrawLine(redPen, 40.0F, 40.0F, 145.0F, 185.0F); @@ -115,26 +114,27 @@ private void ShowPensAndSmoothingMode(PaintEventArgs e) { // Set the SmoothingMode property to smooth the line. - e.Graphics.SmoothingMode = + e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // Create a new Pen object. - Pen greenPen = new Pen(Color.Green); - - // Set the width to 6. - greenPen.Width = 6.0F; + Pen greenPen = new Pen(Color.Green) + { + // Set the width to 6. + Width = 6.0F, - // Set the DashCap to round. - greenPen.DashCap = System.Drawing.Drawing2D.DashCap.Round; + // Set the DashCap to round. + DashCap = System.Drawing.Drawing2D.DashCap.Round, - // Create a custom dash pattern. - greenPen.DashPattern = new float[]{4.0F, 2.0F, 1.0F, 3.0F}; + // Create a custom dash pattern. + DashPattern = [4.0F, 2.0F, 1.0F, 3.0F] + }; // Draw a line. e.Graphics.DrawLine(greenPen, 20.0F, 20.0F, 100.0F, 240.0F); // Change the SmoothingMode to none. - e.Graphics.SmoothingMode = + e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; // Draw another line. @@ -152,7 +152,7 @@ private void ShowPensAndSmoothingMode(PaintEventArgs e) // private void UsePensClass(PaintEventArgs e) { - e.Graphics.DrawEllipse(Pens.SlateBlue, + e.Graphics.DrawEllipse(Pens.SlateBlue, new Rectangle(40, 40, 140, 140)); } // diff --git a/snippets/csharp/System.Drawing/Image/Save/form1.cs b/snippets/csharp/System.Drawing/Image/Save/form1.cs index 7016af3e29e..a51608d9726 100644 --- a/snippets/csharp/System.Drawing/Image/Save/form1.cs +++ b/snippets/csharp/System.Drawing/Image/Save/form1.cs @@ -12,50 +12,50 @@ public static void Main() Encoder myEncoder; EncoderParameter myEncoderParameter; EncoderParameters myEncoderParameters; - + // Create a Bitmap object based on a BMP file. myBitmap = new Bitmap("Shapes.bmp"); - + // Get an ImageCodecInfo object that represents the JPEG codec. myImageCodecInfo = GetEncoderInfo("image/jpeg"); - + // Create an Encoder object based on the GUID - + // for the Quality parameter category. myEncoder = Encoder.Quality; - + // Create an EncoderParameters object. - + // An EncoderParameters object has an array of EncoderParameter - + // objects. In this case, there is only one - + // EncoderParameter object in the array. myEncoderParameters = new EncoderParameters(1); - + // Save the bitmap as a JPEG file with quality level 25. myEncoderParameter = new EncoderParameter(myEncoder, 25L); myEncoderParameters.Param[0] = myEncoderParameter; myBitmap.Save("Shapes025.jpg", myImageCodecInfo, myEncoderParameters); - + // Save the bitmap as a JPEG file with quality level 50. myEncoderParameter = new EncoderParameter(myEncoder, 50L); myEncoderParameters.Param[0] = myEncoderParameter; myBitmap.Save("Shapes050.jpg", myImageCodecInfo, myEncoderParameters); - + // Save the bitmap as a JPEG file with quality level 75. myEncoderParameter = new EncoderParameter(myEncoder, 75L); myEncoderParameters.Param[0] = myEncoderParameter; myBitmap.Save("Shapes075.jpg", myImageCodecInfo, myEncoderParameters); } - private static ImageCodecInfo GetEncoderInfo(String mimeType) + private static ImageCodecInfo GetEncoderInfo(string mimeType) { int j; ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); - for(j = 0; j < encoders.Length; ++j) + for (j = 0; j < encoders.Length; ++j) { - if(encoders[j].MimeType == mimeType) + if (encoders[j].MimeType == mimeType) return encoders[j]; } return null; diff --git a/snippets/csharp/System.Drawing/ImageAnimator/Animate/form1.cs b/snippets/csharp/System.Drawing/ImageAnimator/Animate/form1.cs index 69363caa01a..a22d4e78883 100644 --- a/snippets/csharp/System.Drawing/ImageAnimator/Animate/form1.cs +++ b/snippets/csharp/System.Drawing/ImageAnimator/Animate/form1.cs @@ -4,46 +4,46 @@ using System.Drawing; using System.Windows.Forms; -public class animateImage : Form +public class animateImage : Form { - + //Create a Bitmpap Object. Bitmap animatedImage = new Bitmap("SampleAnimation.gif"); bool currentlyAnimating = false; - + //This method begins the animation. - public void AnimateImage() + public void AnimateImage() { - if (!currentlyAnimating) + if (!currentlyAnimating) { - + //Begin the animation only once. - ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged)); + ImageAnimator.Animate(animatedImage, new EventHandler(OnFrameChanged)); currentlyAnimating = true; } } - private void OnFrameChanged(object o, EventArgs e) + private void OnFrameChanged(object o, EventArgs e) { - + //Force a call to the Paint event handler. - this.Invalidate(); + Invalidate(); } - protected override void OnPaint(PaintEventArgs e) + protected override void OnPaint(PaintEventArgs e) { - + //Begin the animation. AnimateImage(); - + //Get the next frame ready for rendering. ImageAnimator.UpdateFrames(); - + //Draw the next frame in the animation. - e.Graphics.DrawImage(this.animatedImage, new Point(0, 0)); + e.Graphics.DrawImage(animatedImage, new Point(0, 0)); } - public static void Main() + public static void Main() { Application.Run(new animateImage()); } diff --git a/snippets/csharp/System.Drawing/Pen/Clone/form1.cs b/snippets/csharp/System.Drawing/Pen/Clone/form1.cs index edbaafc43b6..e4804e4bc99 100644 --- a/snippets/csharp/System.Drawing/Pen/Clone/form1.cs +++ b/snippets/csharp/System.Drawing/Pen/Clone/form1.cs @@ -1,78 +1,75 @@ using System; -using System.Drawing; -using System.Drawing.Drawing2D; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; namespace System.Drawing.ClassicPensExampleCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { // // Form1 // - this.ClientSize = new System.Drawing.Size(292, 266); - this.Name = "Form1"; - this.Text = "Form1"; - this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); + ClientSize = new System.Drawing.Size(292, 266); + Name = "Form1"; + Text = "Form1"; + Paint += new System.Windows.Forms.PaintEventHandler(Form1_Paint); } - #endregion + #endregion // Snippet for: M:System.Drawing.Pen.Clone // public void Clone_Example(PaintEventArgs e) { - + // Create a Pen object. Pen myPen = new Pen(Color.Black, 5); - + // Clone myPen. Pen clonePen = (Pen)myPen.Clone(); - + // Draw a line with clonePen. e.Graphics.DrawLine(clonePen, 0, 0, 100, 100); } @@ -82,17 +79,17 @@ public void Clone_Example(PaintEventArgs e) // public void MultiplyTransform_Example1(PaintEventArgs e) { - + // Create a Pen object. Pen myPen = new Pen(Color.Black, 5); - + // Create a translation matrix. Matrix penMatrix = new Matrix(); penMatrix.Scale(3, 1); - + // Multiply the transformation matrix of myPen by transMatrix. myPen.MultiplyTransform(penMatrix); - + // Draw a line to the screen. e.Graphics.DrawLine(myPen, 0, 0, 100, 100); } @@ -102,17 +99,17 @@ public void MultiplyTransform_Example1(PaintEventArgs e) // public void MultiplyTransform_Example2(PaintEventArgs e) { - + // Create a Pen object. Pen myPen = new Pen(Color.Black, 5); - + // Create a translation matrix. Matrix penMatrix = new Matrix(); penMatrix.Scale(3, 1); - + // Multiply the transformation matrix of myPen by transMatrix. myPen.MultiplyTransform(penMatrix, MatrixOrder.Prepend); - + // Draw a line to the screen. e.Graphics.DrawLine(myPen, 0, 0, 100, 100); } @@ -122,19 +119,19 @@ public void MultiplyTransform_Example2(PaintEventArgs e) // public void ResetTransform_Example(PaintEventArgs e) { - + // Create a Pen object. Pen myPen = new Pen(Color.Black, 3); - + // Scale the transformation matrix of myPen. myPen.ScaleTransform(2, 1); - + // Draw a line with myPen. e.Graphics.DrawLine(myPen, 10, 0, 10, 200); - + // Reset the transformation matrix of myPen to identity. myPen.ResetTransform(); - + // Draw a second line with myPen. e.Graphics.DrawLine(myPen, 100, 0, 100, 200); } @@ -144,19 +141,19 @@ public void ResetTransform_Example(PaintEventArgs e) // public void RotateTransform_Example1(PaintEventArgs e) { - + // Create a Pen object. Pen rotatePen = new Pen(Color.Black, 5); - + // Draw a rectangle with rotatePen. e.Graphics.DrawRectangle(rotatePen, 10, 10, 100, 100); - + // Scale rotatePen by 2X in the x-direction. rotatePen.ScaleTransform(2, 1); - + // Rotate rotatePen 90 degrees clockwise. rotatePen.RotateTransform(90); - + // Draw a second rectangle with rotatePen. e.Graphics.DrawRectangle(rotatePen, 140, 10, 100, 100); } @@ -166,19 +163,19 @@ public void RotateTransform_Example1(PaintEventArgs e) // public void RotateTransform_Example2(PaintEventArgs e) { - + // Create a Pen object. Pen rotatePen = new Pen(Color.Black, 5); - + // Scale rotatePen by 2X in the x-direction. rotatePen.ScaleTransform(2, 1); - + // Draw a rectangle with rotatePen. e.Graphics.DrawRectangle(rotatePen, 10, 10, 100, 100); - + // Rotate rotatePen 90 degrees clockwise. rotatePen.RotateTransform(90, MatrixOrder.Append); - + // Draw a second rectangle with rotatePen. e.Graphics.DrawRectangle(rotatePen, 120, 10, 100, 100); } @@ -188,16 +185,16 @@ public void RotateTransform_Example2(PaintEventArgs e) // public void ScaleTransform_Example1(PaintEventArgs e) { - + // Create a Pen object. Pen scalePen = new Pen(Color.Black, 5); - + // Draw a rectangle with scalePen. e.Graphics.DrawRectangle(scalePen, 10, 10, 100, 100); - + // Scale scalePen by 2X in the x-direction. scalePen.ScaleTransform(2, 1); - + // Draw a second rectangle with rotatePen. e.Graphics.DrawRectangle(scalePen, 120, 10, 100, 100); } @@ -207,16 +204,16 @@ public void ScaleTransform_Example1(PaintEventArgs e) // public void ScaleTransform_Example2(PaintEventArgs e) { - + // Create a Pen object. Pen scalePen = new Pen(Color.Black, 5); - + // Draw a rectangle with scalePen. e.Graphics.DrawRectangle(scalePen, 10, 10, 100, 100); - + // Scale scalePen by 2X in the x-direction. scalePen.ScaleTransform(2, 1, MatrixOrder.Prepend); - + // Draw a second rectangle with rotatePen. e.Graphics.DrawRectangle(scalePen, 120, 10, 100, 100); } @@ -226,31 +223,33 @@ public void ScaleTransform_Example2(PaintEventArgs e) // public void SetLineCap_Example(PaintEventArgs e) { - + // Create a Pen object with a dash pattern. - Pen capPen = new Pen(Color.Black, 5); - capPen.DashStyle = DashStyle.Dash; - + Pen capPen = new Pen(Color.Black, 5) + { + DashStyle = DashStyle.Dash + }; + // Set the start and end caps for capPen. capPen.SetLineCap(LineCap.ArrowAnchor, LineCap.Flat, DashCap.Flat); - + // Draw a line with capPen. e.Graphics.DrawLine(capPen, 10, 10, 200, 10); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { - SetLineCap_Example(e); + SetLineCap_Example(e); } - } + } } diff --git a/snippets/csharp/System.Drawing/Rectangle/Inflate/form1.cs b/snippets/csharp/System.Drawing/Rectangle/Inflate/form1.cs index 45486ed4528..d4b1b6a2970 100644 --- a/snippets/csharp/System.Drawing/Rectangle/Inflate/form1.cs +++ b/snippets/csharp/System.Drawing/Rectangle/Inflate/form1.cs @@ -1,76 +1,73 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicRectangleExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.Rectangle.Inflate(System.Drawing.Rectangle,System.Int32,System.Int32) // public void RectangleInflateTest(PaintEventArgs e) { - + // Create a rectangle. Rectangle rect = new Rectangle(100, 100, 50, 50); - + // Draw the uninflated rectangle to screen. e.Graphics.DrawRectangle(Pens.Black, rect); - + // Call Inflate. Rectangle rect2 = Rectangle.Inflate(rect, 50, 50); - + // Draw the inflated rectangle to screen. e.Graphics.DrawRectangle(Pens.Red, rect2); } @@ -80,19 +77,19 @@ public void RectangleInflateTest(PaintEventArgs e) // public void RectangleInflateTest2(PaintEventArgs e) { - + // Create a rectangle. Rectangle rect = new Rectangle(100, 100, 50, 50); - + // Draw the uninflated rectangle to screen. e.Graphics.DrawRectangle(Pens.Black, rect); - + // Set up the inflate size. Size inflateSize = new Size(50, 50); - + // Call Inflate. rect.Inflate(inflateSize); - + // Draw the inflated rectangle to screen. e.Graphics.DrawRectangle(Pens.Red, rect); } @@ -102,28 +99,28 @@ public void RectangleInflateTest2(PaintEventArgs e) // public void RectangleInflateTest3(PaintEventArgs e) { - + // Create a rectangle. Rectangle rect = new Rectangle(100, 100, 50, 50); - + // Draw the uninflated rectangle to screen. e.Graphics.DrawRectangle(Pens.Black, rect); - + // Call Inflate. rect.Inflate(50, 50); - + // Draw the inflated rectangle to screen. e.Graphics.DrawRectangle(Pens.Red, rect); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Rectangle/Overview/Class1.cs b/snippets/csharp/System.Drawing/Rectangle/Overview/Class1.cs index 49290a5b838..4d1db0469ae 100644 --- a/snippets/csharp/System.Drawing/Rectangle/Overview/Class1.cs +++ b/snippets/csharp/System.Drawing/Rectangle/Overview/Class1.cs @@ -1,11 +1,11 @@ using System; -using System.Diagnostics; -using System.Windows.Forms; -using System.Xml; -using System.Data; using System.Collections; +using System.Data; +using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; +using System.Windows.Forms; +using System.Xml; public class Form1 : Form { @@ -61,8 +61,10 @@ public void Method41(PaintEventArgs e) { // Pen blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 1); - Pen greenPen = new Pen(Color.FromArgb(255, 0, 255, 0), 10); - greenPen.Alignment = PenAlignment.Center; + Pen greenPen = new Pen(Color.FromArgb(255, 0, 255, 0), 10) + { + Alignment = PenAlignment.Center + }; // Draw the line with the wide green pen. e.Graphics.DrawLine(greenPen, 10, 100, 100, 50); @@ -75,8 +77,10 @@ public void Method42(PaintEventArgs e) { // Pen blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 1); - Pen greenPen = new Pen(Color.FromArgb(255, 0, 255, 0), 10); - greenPen.Alignment = PenAlignment.Center; + Pen greenPen = new Pen(Color.FromArgb(255, 0, 255, 0), 10) + { + Alignment = PenAlignment.Center + }; // Draw the rectangle with the wide green pen. e.Graphics.DrawRectangle(greenPen, 10, 100, 50, 50); @@ -98,9 +102,11 @@ public void Method43(PaintEventArgs e) public void Method51(PaintEventArgs e) { // - float[] dashValues = { 5, 2, 15, 4 }; - Pen blackPen = new Pen(Color.Black, 5); - blackPen.DashPattern = dashValues; + float[] dashValues = [5, 2, 15, 4]; + Pen blackPen = new Pen(Color.Black, 5) + { + DashPattern = dashValues + }; e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5)); // } @@ -124,9 +130,11 @@ public void Method61(PaintEventArgs e) public void Method71(PaintEventArgs e) { // - Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255), 8); - pen.StartCap = LineCap.ArrowAnchor; - pen.EndCap = LineCap.RoundAnchor; + Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255), 8) + { + StartCap = LineCap.ArrowAnchor, + EndCap = LineCap.RoundAnchor + }; e.Graphics.DrawLine(pen, 20, 175, 300, 175); // } diff --git a/snippets/csharp/System.Drawing/RectangleF/Inflate/form1.cs b/snippets/csharp/System.Drawing/RectangleF/Inflate/form1.cs index c371599c557..f014569a1ca 100644 --- a/snippets/csharp/System.Drawing/RectangleF/Inflate/form1.cs +++ b/snippets/csharp/System.Drawing/RectangleF/Inflate/form1.cs @@ -1,80 +1,77 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicRectangleFExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.RectangleF.Inflate(System.Drawing.SizeF) // public void RectangleFInflateExample(PaintEventArgs e) { - + // Create a RectangleF structure. RectangleF myRectF = new RectangleF(100, 20, 100, 100); - + // Draw myRect to the screen. Rectangle myRect = Rectangle.Truncate(myRectF); e.Graphics.DrawRectangle(Pens.Black, myRect); - + // Create a Size structure. SizeF inflateSize = new SizeF(100, 0); - + // Inflate myRect. myRectF.Inflate(inflateSize); - + // Draw the inflated rectangle to the screen. myRect = Rectangle.Truncate(myRectF); e.Graphics.DrawRectangle(Pens.Red, myRect); @@ -85,24 +82,24 @@ public void RectangleFInflateExample(PaintEventArgs e) // public void RectangleFIntersectExample(PaintEventArgs e) { - + // Create two rectangles. RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50); RectangleF secondRectangleF = new RectangleF(50, 20, 50, 50); - + // Convert the RectangleF structures to Rectangle structures and draw them to the - + // screen. Rectangle firstRect = Rectangle.Truncate(firstRectangleF); Rectangle secondRect = Rectangle.Truncate(secondRectangleF); e.Graphics.DrawRectangle(Pens.Black, firstRect); e.Graphics.DrawRectangle(Pens.Red, secondRect); - + // Get the intersection. RectangleF intersectRectangleF = RectangleF.Intersect(firstRectangleF, secondRectangleF); - + // Draw the intersectRectangleF to the screen. Rectangle intersectRect = Rectangle.Truncate(intersectRectangleF); @@ -114,36 +111,36 @@ public void RectangleFIntersectExample(PaintEventArgs e) // public void RectangleFUnionExample(PaintEventArgs e) { - + // Create two rectangles and draw them to the screen. RectangleF firstRectangleF = new RectangleF(0, 0, 75, 50); RectangleF secondRectangleF = new RectangleF(100, 100, 20, 20); - + // Convert the RectangleF structures to Rectangle structures and draw them to the - + // screen. Rectangle firstRect = Rectangle.Truncate(firstRectangleF); Rectangle secondRect = Rectangle.Truncate(secondRectangleF); e.Graphics.DrawRectangle(Pens.Black, firstRect); e.Graphics.DrawRectangle(Pens.Red, secondRect); - + // Get the union rectangle. RectangleF unionRectangleF = RectangleF.Union(firstRectangleF, secondRectangleF); - + // Draw the unionRectangleF to the screen. Rectangle unionRect = Rectangle.Truncate(unionRectangleF); e.Graphics.DrawRectangle(Pens.Blue, unionRect); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/Region/Complement/form1.cs b/snippets/csharp/System.Drawing/Region/Complement/form1.cs index e9cea93a53e..fa21665fe14 100644 --- a/snippets/csharp/System.Drawing/Region/Complement/form1.cs +++ b/snippets/csharp/System.Drawing/Region/Complement/form1.cs @@ -1,88 +1,85 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; -using System.Drawing.Drawing2D; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; namespace System.Drawing.ClassicRegionExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.Region.Complement(System.Drawing.Drawing2D.GraphicsPath) // public void Complement_Path_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // Create the second rectangle and draw it to the screen in red. Rectangle complementRect = new Rectangle(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, complementRect); - + // Create a graphics path and add the second rectangle to it. GraphicsPath complementPath = new GraphicsPath(); complementPath.AddRectangle(complementRect); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the complement of myRegion when combined with - + // complementPath. myRegion.Complement(complementPath); - + // Fill the complement area with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); @@ -93,24 +90,24 @@ public void Complement_Path_Example(PaintEventArgs e) // public void Complement_RectF_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // Create the second rectangle and draw it to the screen in red. RectangleF complementRect = new RectangleF(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(complementRect)); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the complement of the region combined with the second - + // rectangle. myRegion.Complement(complementRect); - + // Fill the complement area with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); @@ -121,26 +118,26 @@ public void Complement_RectF_Example(PaintEventArgs e) // public void Complement_Region_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // Create the second rectangle and draw it to the screen in red. Rectangle complementRect = new Rectangle(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, complementRect); - + // Create a region from the first rectangle. Region myRegion = new Region(regionRect); - + // Create a complement region. Region complementRegion = new Region(complementRect); - + // Get the complement of myRegion when combined with - + // complementRegion. myRegion.Complement(complementRegion); - + // Fill the complement area with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); @@ -151,24 +148,24 @@ public void Complement_Region_Example(PaintEventArgs e) // public void Exclude_RectF_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // Create the second rectangle and draw it to the screen in red. RectangleF complementRect = new RectangleF(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(complementRect)); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the nonexcluded area of myRegion when combined with - + // complementRect. myRegion.Exclude(complementRect); - + // Fill the nonexcluded area of myRegion with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); @@ -179,21 +176,21 @@ public void Exclude_RectF_Example(PaintEventArgs e) // public void GetBoundsExample(PaintEventArgs e) { - + // Create a GraphicsPath and add an ellipse to it. GraphicsPath myPath = new GraphicsPath(); Rectangle ellipseRect = new Rectangle(20, 20, 100, 100); myPath.AddEllipse(ellipseRect); - + // Fill the path with blue and draw it to the screen. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillPath(myBrush, myPath); - + // Create a region using the GraphicsPath. Region myRegion = new Region(myPath); - + // Get the bounding rectangle for myRegion and draw it to the - + // screen in Red. RectangleF boundsRect = myRegion.GetBounds(e.Graphics); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect)); @@ -204,26 +201,26 @@ public void GetBoundsExample(PaintEventArgs e) // public void GetRegionDataExample(PaintEventArgs e) { - + // Create a rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the RegionData for this region. RegionData myRegionData = myRegion.GetRegionData(); int myRegionDataLength = myRegionData.Data.Length; DisplayRegionData(e, myRegionDataLength, myRegionData); } - + // THIS IS A HELPER FUNCTION FOR GetRegionData. public void DisplayRegionData(PaintEventArgs e, int len, RegionData dat) { - + // Display the result. int i; float x = 20, y = 140; @@ -234,9 +231,9 @@ public void DisplayRegionData(PaintEventArgs e, myBrush, new PointF(x, y)); y = 160; - for(i = 0; i < len; i++) + for (i = 0; i < len; i++) { - if(x > 300) + if (x > 300) { y += 20; x = 20; @@ -254,24 +251,24 @@ public void DisplayRegionData(PaintEventArgs e, // public void Intersect_RectF_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // create the second rectangle and draw it to the screen in red. RectangleF complementRect = new RectangleF(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(complementRect)); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the area of intersection for myRegion when combined with - + // complementRect. myRegion.Intersect(complementRect); - + // Fill the intersection area of myRegion with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); @@ -282,21 +279,21 @@ public void Intersect_RectF_Example(PaintEventArgs e) // public void IsVisible_RectF_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in blue. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Blue, regionRect); - + // Create the second rectangle and draw it to the screen in red. RectangleF myRect = new RectangleF(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(myRect)); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Determine if myRect is contained in the region. bool contained = myRegion.IsVisible(myRect); - + // Display the result. Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); @@ -311,25 +308,25 @@ public void IsVisible_RectF_Example(PaintEventArgs e) // public void TransformExample(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in blue. Rectangle regionRect = new Rectangle(100, 50, 100, 100); e.Graphics.DrawRectangle(Pens.Blue, regionRect); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Create a transform matrix and set it to have a 45 degree - + // rotation. Matrix transformMatrix = new Matrix(); transformMatrix.RotateAt(45, new Point(100, 50)); - + // Apply the transform to the region. myRegion.Transform(transformMatrix); - + // Fill the transformed region with red and draw it to the screen - + // in red. SolidBrush myBrush = new SolidBrush(Color.Red); e.Graphics.FillRegion(myBrush, myRegion); @@ -340,17 +337,17 @@ public void TransformExample(PaintEventArgs e) // public void TranslateExample(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in blue. Rectangle regionRect = new Rectangle(100, 50, 100, 100); e.Graphics.DrawRectangle(Pens.Blue, regionRect); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Apply the translation to the region. myRegion.Translate(150, 100); - + // Fill the transformed region with red and draw it to the screen in red. SolidBrush myBrush = new SolidBrush(Color.Red); e.Graphics.FillRegion(myBrush, myRegion); @@ -361,24 +358,24 @@ public void TranslateExample(PaintEventArgs e) // public void Union_RectF_Example(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // create the second rectangle and draw it to the screen in red. RectangleF unionRect = new RectangleF(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(unionRect)); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the area of union for myRegion when combined with - + // complementRect. myRegion.Union(unionRect); - + // Fill the union area of myRegion with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); @@ -389,37 +386,37 @@ public void Union_RectF_Example(PaintEventArgs e) // public void XorExample(PaintEventArgs e) { - + // Create the first rectangle and draw it to the screen in black. Rectangle regionRect = new Rectangle(20, 20, 100, 100); e.Graphics.DrawRectangle(Pens.Black, regionRect); - + // create the second rectangle and draw it to the screen in red. RectangleF xorRect = new RectangleF(90, 30, 100, 100); e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(xorRect)); - + // Create a region using the first rectangle. Region myRegion = new Region(regionRect); - + // Get the area of overlap for myRegion when combined with - + // complementRect. myRegion.Xor(xorRect); - + // Fill the Xor area of myRegion with blue. SolidBrush myBrush = new SolidBrush(Color.Blue); e.Graphics.FillRegion(myBrush, myRegion); } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/StringFormat/GetTabStops/form1.cs b/snippets/csharp/System.Drawing/StringFormat/GetTabStops/form1.cs index 7be93150f20..6c8f4a6110c 100644 --- a/snippets/csharp/System.Drawing/StringFormat/GetTabStops/form1.cs +++ b/snippets/csharp/System.Drawing/StringFormat/GetTabStops/form1.cs @@ -1,96 +1,93 @@ using System; -using System.Drawing; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Windows.Forms; namespace System.Drawing.ClassicStringFormatExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.StringFormat.GetTabStops(System.Single@) // public void GetSetTabStopsExample1(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Tools used for drawing, painting. - Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0)); - SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); - + Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0)); + SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); + // Layout and format for text. - Font myFont = new Font("Times New Roman", 12); + Font myFont = new Font("Times New Roman", 12); StringFormat myStringFormat = new StringFormat(); - Rectangle enclosingRectangle = new Rectangle(20, 20, 500, 100); - float[] tabStops = {150.0f, 100.0f, 100.0f}; - + Rectangle enclosingRectangle = new Rectangle(20, 20, 500, 100); + float[] tabStops = [150.0f, 100.0f, 100.0f]; + // Text with tabbed columns. - string myString = + string myString = "Name\tTab 1\tTab 2\tTab 3\nGeorge Brown\tOne\tTwo\tThree"; - + // Set the tab stops, paint the text specified by myString, and draw the - + // rectangle that encloses the text. myStringFormat.SetTabStops(0.0f, tabStops); g.DrawString(myString, myFont, blueBrush, enclosingRectangle, myStringFormat); g.DrawRectangle(redPen, enclosingRectangle); - + // Get the tab stops. - float firstTabOffset; + float firstTabOffset; float[] tabStopsObtained = myStringFormat.GetTabStops(out firstTabOffset); - for(int j = 0; j < tabStopsObtained.Length; j++) + for (int j = 0; j < tabStopsObtained.Length; j++) { - + // Inspect or use the value in tabStopsObtained[j]. Console.WriteLine("\n Tab stop {0} = {1}", j, tabStopsObtained[j]); } @@ -101,37 +98,37 @@ public void GetSetTabStopsExample1(PaintEventArgs e) // public void SetDigitSubExample(PaintEventArgs e) { - Graphics g = e.Graphics; - SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); - Font myFont = new Font("Courier New", 12); + Graphics g = e.Graphics; + SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); + Font myFont = new Font("Courier New", 12); StringFormat myStringFormat = new StringFormat(); - string myString = "0 1 2 3 4 5 6 7 8 9"; + string myString = "0 1 2 3 4 5 6 7 8 9"; // Arabic (0x0C01) digits. - + // Use National substitution method. myStringFormat.SetDigitSubstitution(0x0C01, StringDigitSubstitute.National); g.DrawString( "Arabic:\nMethod of substitution = National: " + myString, myFont, blueBrush, new PointF(10.0f, 20.0f), myStringFormat); - + // Use Traditional substitution method. myStringFormat.SetDigitSubstitution(0x0C01, StringDigitSubstitute.Traditional); g.DrawString( "Method of substitution = Traditional: " + myString, myFont, blueBrush, new PointF(10.0f, 55.0f), myStringFormat); - + // Thai (0x041E) digits. - + // Use National substitution method. myStringFormat.SetDigitSubstitution(0x041E, StringDigitSubstitute.National); g.DrawString( "Thai:\nMethod of substitution = National: " + myString, myFont, blueBrush, new PointF(10.0f, 85.0f), myStringFormat); - + // Use Traditional substitution method. myStringFormat.SetDigitSubstitution(0x041E, StringDigitSubstitute.Traditional); @@ -145,46 +142,46 @@ public void SetDigitSubExample(PaintEventArgs e) // public void SetMeasCharRangesExample(PaintEventArgs e) { - Graphics g = e.Graphics; - SolidBrush redBrush = new SolidBrush(Color.FromArgb(50, 255, 0, 0)); - + Graphics g = e.Graphics; + SolidBrush redBrush = new SolidBrush(Color.FromArgb(50, 255, 0, 0)); + // Layout rectangles, font, and string format used for displaying string. - Rectangle layoutRectA = new Rectangle(20, 20, 165, 80); - Rectangle layoutRectB = new Rectangle(20, 110, 165, 80); - Rectangle layoutRectC = new Rectangle(20, 200, 240, 80); - Font tnrFont = new Font("Times New Roman", 16); + Rectangle layoutRectA = new Rectangle(20, 20, 165, 80); + Rectangle layoutRectB = new Rectangle(20, 110, 165, 80); + Rectangle layoutRectC = new Rectangle(20, 200, 240, 80); + Font tnrFont = new Font("Times New Roman", 16); StringFormat strFormat = new StringFormat(); - + // Ranges of character positions within a string. - CharacterRange[] charRanges = { new CharacterRange(3, 5), - new CharacterRange(15, 2), new CharacterRange(30, 15)}; - + CharacterRange[] charRanges = [ new CharacterRange(3, 5), + new CharacterRange(15, 2), new CharacterRange(30, 15)]; + // Each region specifies the area occupied by the characters within a // range of positions. the values are obtained by using a method that // measures the character ranges. - Region[] charRegions = new Region[charRanges.Length]; - + Region[] charRegions = new Region[charRanges.Length]; + // String to be displayed. - string str = + string str = "The quick, brown fox easily jumps over the lazy dog."; - + // Set the char ranges for the string format. strFormat.SetMeasurableCharacterRanges(charRanges); - + // loop counter (unsigned 8-bit integer) - byte i; - + byte i; + // Measure the char ranges for a given string and layout rectangle. Each // area occupied by the characters in a range is stored as a region. Then // draw the string and layout rectangle, and paint the regions. charRegions = g.MeasureCharacterRanges(str, tnrFont, layoutRectA, strFormat); - g.DrawString(str, tnrFont, Brushes.Blue, layoutRectA, strFormat); + g.DrawString(str, tnrFont, Brushes.Blue, layoutRectA, strFormat); g.DrawRectangle(Pens.Black, layoutRectA); - + // Paint the regions. for (i = 0; i < charRegions.Length; i++) - g.FillRegion(redBrush, charRegions[i]); + g.FillRegion(redBrush, charRegions[i]); // Repeat the above steps, but include trailing spaces in the char // range measurement by setting the appropriate string format flag. @@ -195,11 +192,11 @@ public void SetMeasCharRangesExample(PaintEventArgs e) g.DrawRectangle(Pens.Black, layoutRectB); for (i = 0; i < charRegions.Length; i++) - g.FillRegion(redBrush, charRegions[i]); - + g.FillRegion(redBrush, charRegions[i]); + // Clear all the format flags. - strFormat.FormatFlags = 0; - + strFormat.FormatFlags = 0; + // Repeat the steps, but use a different layout rectangle. the dimensions // of the layout rectangle and the size of the font both affect the // character range measurement. @@ -207,10 +204,10 @@ public void SetMeasCharRangesExample(PaintEventArgs e) layoutRectC, strFormat); g.DrawString(str, tnrFont, Brushes.Blue, layoutRectC, strFormat); g.DrawRectangle(Pens.Black, layoutRectC); - + // Paint the regions. for (i = 0; i < charRegions.Length; i++) - g.FillRegion(redBrush, charRegions[i]); + g.FillRegion(redBrush, charRegions[i]); } // @@ -218,35 +215,35 @@ public void SetMeasCharRangesExample(PaintEventArgs e) // public void GetSetTabStopsExample2(PaintEventArgs e) { - Graphics g = e.Graphics; - + Graphics g = e.Graphics; + // Tools used for drawing, painting. - Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0)); - SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); - + Pen redPen = new Pen(Color.FromArgb(255, 255, 0, 0)); + SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); + // Layout and format for text. - Font myFont = new Font("Times New Roman", 12); + Font myFont = new Font("Times New Roman", 12); StringFormat myStringFormat = new StringFormat(); - Rectangle enclosingRectangle = new Rectangle(20, 20, 500, 100); - float[] tabStops = {150.0f, 100.0f, 100.0f}; - + Rectangle enclosingRectangle = new Rectangle(20, 20, 500, 100); + float[] tabStops = [150.0f, 100.0f, 100.0f]; + // Text with tabbed columns. - string myString = + string myString = "Name\tTab 1\tTab 2\tTab 3\nGeorge Brown\tOne\tTwo\tThree"; - + // Set the tab stops, paint the text specified by myString, draw the // rectangle that encloses the text. myStringFormat.SetTabStops(0.0f, tabStops); g.DrawString(myString, myFont, blueBrush, enclosingRectangle, myStringFormat); g.DrawRectangle(redPen, enclosingRectangle); - + // Get the tab stops. - float firstTabOffset; + float firstTabOffset; float[] tabStopsObtained = myStringFormat.GetTabStops(out firstTabOffset); - for(int j = 0; j < tabStopsObtained.Length; j++) + for (int j = 0; j < tabStopsObtained.Length; j++) { - + // Inspect or use the value in tabStopsObtained[j]. Console.WriteLine("\n Tab stop {0} = {1}", j, tabStopsObtained[j]); } @@ -257,25 +254,25 @@ public void GetSetTabStopsExample2(PaintEventArgs e) // public void ToStringExample(PaintEventArgs e) { - Graphics g = e.Graphics; - SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); - Font myFont = new Font("Times New Roman", 14); + Graphics g = e.Graphics; + SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); + Font myFont = new Font("Times New Roman", 14); StringFormat myStringFormat = new StringFormat(); - + // String variable to hold the values of the StringFormat object. - string strFmtString; - + string strFmtString; + // Convert the string format object to a string (only certain information // in the object is converted) and display the string. strFmtString = myStringFormat.ToString(); g.DrawString("Before changing properties: " + myStringFormat, myFont, blueBrush, 20, 40); - + // Change some properties of the string format myStringFormat.Trimming = StringTrimming.None; - myStringFormat.FormatFlags = StringFormatFlags.NoWrap + myStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip; - + // Convert the string format object to a string and display the string. // The string will be different because the properties of the string // format have changed. @@ -285,13 +282,13 @@ public void ToStringExample(PaintEventArgs e) } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/TextureBrush/Clone/form1.cs b/snippets/csharp/System.Drawing/TextureBrush/Clone/form1.cs index c37860d44ce..4f9045f8ba9 100644 --- a/snippets/csharp/System.Drawing/TextureBrush/Clone/form1.cs +++ b/snippets/csharp/System.Drawing/TextureBrush/Clone/form1.cs @@ -1,74 +1,71 @@ using System; -using System.Drawing; -using System.Drawing.Drawing2D; using System.Collections; using System.ComponentModel; -using System.Windows.Forms; using System.Data; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; namespace System.Drawing.ClassicTextureBrushExamplesCS { - /// - /// Summary description for Form1. - /// - public class Form1 : System.Windows.Forms.Form - { - /// - /// Required designer variable. - /// - private System.ComponentModel.Container components = null; - - public Form1() - { - // - // Required for Windows Form Designer support - // - InitializeComponent(); - - // - // TODO: Add any constructor code after InitializeComponent call - // - } - - /// - /// Clean up any resources being used. - /// - protected override void Dispose( bool disposing ) - { - if( disposing ) - { - if (components != null) - { - components.Dispose(); - } - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.Size = new System.Drawing.Size(300,300); - this.Text = "Form1"; - } - #endregion + /// + /// Summary description for Form1. + /// + public class Form1 : System.Windows.Forms.Form + { + /// + /// Required designer variable. + /// + private System.ComponentModel.Container components = null; + + public Form1() + { + // + // Required for Windows Form Designer support + // + InitializeComponent(); + + // + // TODO: Add any constructor code after InitializeComponent call + // + } + + /// + /// Clean up any resources being used. + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + components?.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + Size = new System.Drawing.Size(300, 300); + Text = "Form1"; + } + #endregion // Snippet for: M:System.Drawing.TextureBrush.Clone // public void Clone_Example(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Create an exact copy of tBrush. TextureBrush cloneBrush = (TextureBrush)tBrush.Clone(); - + // Fill a rectangle with cloneBrush. e.Graphics.FillRectangle(cloneBrush, 0, 0, 100, 100); } @@ -78,17 +75,17 @@ public void Clone_Example(PaintEventArgs e) // public void MultiplyTransform_Example1(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Create a transformation matrix. Matrix translateMatrix = new Matrix(); translateMatrix.Translate(50, 0); - + // Multiply the transformation matrix of tBrush by translateMatrix. tBrush.MultiplyTransform(translateMatrix, MatrixOrder.Prepend); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 110, 100, 100); } @@ -98,17 +95,17 @@ public void MultiplyTransform_Example1(PaintEventArgs e) // public void MultiplyTransform_Example2(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Create a transformation matrix. Matrix translateMatrix = new Matrix(); translateMatrix.Translate(50, 0); - + // Multiply the transformation matrix of tBrush by translateMatrix. tBrush.MultiplyTransform(translateMatrix); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 110, 100, 100); } @@ -118,19 +115,19 @@ public void MultiplyTransform_Example2(PaintEventArgs e) // public void ResetTransform_Example(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Rotate the texture image by 90 degrees. tBrush.RotateTransform(90); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); - + // Reset transformation matrix to identity. tBrush.ResetTransform(); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 110, 100, 100); } @@ -140,13 +137,13 @@ public void ResetTransform_Example(PaintEventArgs e) // public void RotateTransform_Example1(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Rotate the texture image by 90 degrees. tBrush.RotateTransform(90); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); } @@ -156,13 +153,13 @@ public void RotateTransform_Example1(PaintEventArgs e) // public void RotateTransform_Example2(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Rotate the texture image by 90 degrees. tBrush.RotateTransform(90, MatrixOrder.Prepend); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); } @@ -172,13 +169,13 @@ public void RotateTransform_Example2(PaintEventArgs e) // public void ScaleTransform_Example1(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Scale the texture image 2X in the x-direction. tBrush.ScaleTransform(2, 1); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); } @@ -188,13 +185,13 @@ public void ScaleTransform_Example1(PaintEventArgs e) // public void ScaleTransform_Example2(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Scale the texture image 2X in the x-direction. tBrush.ScaleTransform(2, 1, MatrixOrder.Prepend); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); } @@ -204,41 +201,41 @@ public void ScaleTransform_Example2(PaintEventArgs e) // public void TranslateTransform_Example1(PaintEventArgs e) { - + // Create a TextureBrush object. TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - + // Move the texture image 2X in the x-direction. tBrush.TranslateTransform(50, 0, MatrixOrder.Prepend); - + // Fill a rectangle with tBrush. e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); } - // + // - // Snippet for: M:System.Drawing.TextureBrush.TranslateTransform(System.Single,System.Single,System.Drawing.Drawing2D.MatrixOrder) - // - public void TranslateTransform_Example2(PaintEventArgs e) - { - - // Create a TextureBrush object. - TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); - - // Move the texture image 2X in the x-direction. - tBrush.TranslateTransform(50, 0); - - // Fill a rectangle with tBrush. - e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); - } + // Snippet for: M:System.Drawing.TextureBrush.TranslateTransform(System.Single,System.Single,System.Drawing.Drawing2D.MatrixOrder) + // + public void TranslateTransform_Example2(PaintEventArgs e) + { + + // Create a TextureBrush object. + TextureBrush tBrush = new TextureBrush(new Bitmap("texture.jpg")); + + // Move the texture image 2X in the x-direction. + tBrush.TranslateTransform(50, 0); + + // Fill a rectangle with tBrush. + e.Graphics.FillRectangle(tBrush, 0, 0, 100, 100); + } // - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - Application.Run(new Form1()); - } - } + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.Run(new Form1()); + } + } } diff --git a/snippets/csharp/System.Drawing/ToolboxBitmapAttribute/Overview/usercontrol1.cs b/snippets/csharp/System.Drawing/ToolboxBitmapAttribute/Overview/usercontrol1.cs index ceb2b0e957c..4e5dfb7f241 100644 --- a/snippets/csharp/System.Drawing/ToolboxBitmapAttribute/Overview/usercontrol1.cs +++ b/snippets/csharp/System.Drawing/ToolboxBitmapAttribute/Overview/usercontrol1.cs @@ -1,40 +1,40 @@ using System; +using System.ComponentModel; using System.Drawing; using System.Windows.Forms; -using System.ComponentModel; - class Form1 : Form +class Form1 : Form +{ + private Button button1 = new Button(); + public Form1() { - private Button button1 = new Button(); - public Form1() - { - //InitializeComponent(); - this.Controls.Add(button1); - } + //InitializeComponent(); + Controls.Add(button1); + } - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.Run(new Form1()); - } - // - private Image GetImageOfCustomControl(Control userControl) + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.Run(new Form1()); + } + // + private Image GetImageOfCustomControl(Control userControl) + { + Image controlImage = null; + AttributeCollection attrCol = + TypeDescriptor.GetAttributes(userControl); + ToolboxBitmapAttribute imageAttr = (ToolboxBitmapAttribute) + attrCol[typeof(ToolboxBitmapAttribute)]; + if (imageAttr != null) { - Image controlImage = null; - AttributeCollection attrCol = - TypeDescriptor.GetAttributes(userControl); - ToolboxBitmapAttribute imageAttr = (ToolboxBitmapAttribute) - attrCol[typeof(ToolboxBitmapAttribute)]; - if (imageAttr != null) - { - controlImage = imageAttr.GetImage(userControl); - } - - return controlImage; + controlImage = imageAttr.GetImage(userControl); } - // + + return controlImage; } + // +} // The following code example demonstrates how to use the // ToolBoxBitmapAttribute#ctor(string) costructor to set stop.bmp as the @@ -42,7 +42,7 @@ private Image GetImageOfCustomControl(Control userControl) // the existence of a 16-by-16-pixel bitmap named stop.bmp at c:\. // [System.Drawing.ToolboxBitmap("c:\\stop.bmp")] -public class StopSignControl: +public class StopSignControl : System.Windows.Forms.UserControl { @@ -50,37 +50,37 @@ public class StopSignControl: internal System.Windows.Forms.Button Button1; public StopSignControl() : base() - { - this.Label1 = new System.Windows.Forms.Label(); - this.Button1 = new System.Windows.Forms.Button(); - - this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) 0)); - - this.Label1.ForeColor = System.Drawing.Color.Red; - this.Label1.Location = new System.Drawing.Point(24, 56); - this.Label1.Name = "Label1"; - this.Label1.TabIndex = 0; - this.Label1.Text = "Stop!"; - this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - - this.Button1.Enabled = false; - this.Button1.Location = new System.Drawing.Point(56, 88); - this.Button1.Name = "Button1"; - this.Button1.Size = new System.Drawing.Size(40, 32); - this.Button1.TabIndex = 1; - this.Button1.Text = "stop"; - - this.Controls.Add(this.Button1); - this.Controls.Add(this.Label1); - this.Name = "StopSignControl"; + { + Label1 = new System.Windows.Forms.Label(); + Button1 = new System.Windows.Forms.Button(); + + Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)0)); + + Label1.ForeColor = System.Drawing.Color.Red; + Label1.Location = new System.Drawing.Point(24, 56); + Label1.Name = "Label1"; + Label1.TabIndex = 0; + Label1.Text = "Stop!"; + Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + + Button1.Enabled = false; + Button1.Location = new System.Drawing.Point(56, 88); + Button1.Name = "Button1"; + Button1.Size = new System.Drawing.Size(40, 32); + Button1.TabIndex = 1; + Button1.Text = "stop"; + + Controls.Add(Button1); + Controls.Add(Label1); + Name = "StopSignControl"; } private void StopSignControl_MouseEnter(object sender, System.EventArgs e) { Label1.Text.ToUpper(); - Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, - System.Drawing.FontStyle.Bold); + Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, + System.Drawing.FontStyle.Bold); Button1.Enabled = true; } @@ -88,8 +88,8 @@ private void StopSignControl_MouseLeave(object sender, System.EventArgs e) { Label1.Text.ToLower(); - Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, - System.Drawing.FontStyle.Regular); + Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, + System.Drawing.FontStyle.Regular); Button1.Enabled = false; } } @@ -102,7 +102,7 @@ private void StopSignControl_MouseLeave(object sender, System.EventArgs e) // BuildAction property set to EmbeddedResource. // [System.Drawing.ToolboxBitmap(typeof(StopSignControl2), "StopSignControl2.bmp")] -public class StopSignControl2: +public class StopSignControl2 : System.Windows.Forms.UserControl { @@ -110,34 +110,34 @@ public class StopSignControl2: internal System.Windows.Forms.Button Button1; public StopSignControl2() : base() - { - this.Label1 = new System.Windows.Forms.Label(); - this.Button1 = new System.Windows.Forms.Button(); - - this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", - 12.0F, System.Drawing.FontStyle.Regular, - System.Drawing.GraphicsUnit.Point, ((byte) 0)); - this.Label1.ForeColor = System.Drawing.Color.Red; - this.Label1.Location = new System.Drawing.Point(24, 56); - this.Label1.Name = "Label1"; - this.Label1.TabIndex = 0; - this.Label1.Text = "Stop!"; - this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.Button1.Enabled = false; - this.Button1.Location = new System.Drawing.Point(56, 88); - this.Button1.Name = "Button1"; - this.Button1.Size = new System.Drawing.Size(40, 32); - this.Button1.TabIndex = 1; - this.Button1.Text = "stop"; - this.Controls.Add(this.Button1); - this.Controls.Add(this.Label1); - this.Name = "StopSignControl"; + { + Label1 = new System.Windows.Forms.Label(); + Button1 = new System.Windows.Forms.Button(); + + Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", + 12.0F, System.Drawing.FontStyle.Regular, + System.Drawing.GraphicsUnit.Point, ((byte)0)); + Label1.ForeColor = System.Drawing.Color.Red; + Label1.Location = new System.Drawing.Point(24, 56); + Label1.Name = "Label1"; + Label1.TabIndex = 0; + Label1.Text = "Stop!"; + Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + Button1.Enabled = false; + Button1.Location = new System.Drawing.Point(56, 88); + Button1.Name = "Button1"; + Button1.Size = new System.Drawing.Size(40, 32); + Button1.TabIndex = 1; + Button1.Text = "stop"; + Controls.Add(Button1); + Controls.Add(Label1); + Name = "StopSignControl"; } private void StopSignControl_MouseEnter(object sender, System.EventArgs e) { Label1.Text.ToUpper(); - Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, + Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 14.0F, System.Drawing.FontStyle.Bold); Button1.Enabled = true; } @@ -146,8 +146,8 @@ private void StopSignControl_MouseLeave(object sender, System.EventArgs e) { Label1.Text.ToLower(); - Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, - System.Drawing.FontStyle.Regular); + Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, 12.0F, + System.Drawing.FontStyle.Regular); Button1.Enabled = false; } } @@ -158,7 +158,7 @@ private void StopSignControl_MouseLeave(object sender, System.EventArgs e) // to the toolbox icon for a UserControl named StopSignControl3. // [System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.Button))] -public class StopSignControl3: +public class StopSignControl3 : System.Windows.Forms.UserControl { @@ -166,44 +166,44 @@ public class StopSignControl3: internal System.Windows.Forms.Button Button1; public StopSignControl3() : base() - { - this.Label1 = new System.Windows.Forms.Label(); - this.Button1 = new System.Windows.Forms.Button(); - - this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", - 12.0F, System.Drawing.FontStyle.Regular, - System.Drawing.GraphicsUnit.Point, ((byte) 0)); - this.Label1.ForeColor = System.Drawing.Color.Red; - this.Label1.Location = new System.Drawing.Point(24, 56); - this.Label1.Name = "Label1"; - this.Label1.TabIndex = 0; - this.Label1.Text = "Stop!"; - this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - - this.Button1.Enabled = false; - this.Button1.Location = new System.Drawing.Point(56, 88); - this.Button1.Name = "Button1"; - this.Button1.Size = new System.Drawing.Size(40, 32); - this.Button1.TabIndex = 1; - this.Button1.Text = "stop"; - this.Controls.Add(this.Button1); - this.Controls.Add(this.Label1); - this.Name = "StopSignControl"; + { + Label1 = new System.Windows.Forms.Label(); + Button1 = new System.Windows.Forms.Button(); + + Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", + 12.0F, System.Drawing.FontStyle.Regular, + System.Drawing.GraphicsUnit.Point, ((byte)0)); + Label1.ForeColor = System.Drawing.Color.Red; + Label1.Location = new System.Drawing.Point(24, 56); + Label1.Name = "Label1"; + Label1.TabIndex = 0; + Label1.Text = "Stop!"; + Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + + Button1.Enabled = false; + Button1.Location = new System.Drawing.Point(56, 88); + Button1.Name = "Button1"; + Button1.Size = new System.Drawing.Size(40, 32); + Button1.TabIndex = 1; + Button1.Text = "stop"; + Controls.Add(Button1); + Controls.Add(Label1); + Name = "StopSignControl"; } private void StopSignControl_MouseEnter(object sender, System.EventArgs e) { Label1.Text.ToUpper(); Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, - 14.0F, System.Drawing.FontStyle.Bold); + 14.0F, System.Drawing.FontStyle.Bold); Button1.Enabled = true; } private void StopSignControl_MouseLeave(object sender, System.EventArgs e) { Label1.Text.ToLower(); - Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, - 12.0F, System.Drawing.FontStyle.Regular); + Label1.Font = new System.Drawing.Font(Label1.Font.FontFamily, + 12.0F, System.Drawing.FontStyle.Regular); Button1.Enabled = false; } }