diff --git a/snippets/csharp/System.Drawing.Design/BitmapEditor/Overview/usercontrol1.cs b/snippets/csharp/System.Drawing.Design/BitmapEditor/Overview/usercontrol1.cs
index 997e6ee8507..a87c4526ab0 100644
--- a/snippets/csharp/System.Drawing.Design/BitmapEditor/Overview/usercontrol1.cs
+++ b/snippets/csharp/System.Drawing.Design/BitmapEditor/Overview/usercontrol1.cs
@@ -2,16 +2,16 @@
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
+using System.Data;
using System.Drawing;
using System.Drawing.Design;
-using System.Data;
using System.Windows.Forms;
namespace BitmapEditorExample
{
- public class UserControl1 : System.Windows.Forms.UserControl
- {
- private System.ComponentModel.Container components = null;
+ public class UserControl1 : System.Windows.Forms.UserControl
+ {
+ private System.ComponentModel.Container components = null;
//
[EditorAttribute(typeof(System.Drawing.Design.BitmapEditor),
@@ -31,20 +31,20 @@ public Bitmap testBitmap
private Bitmap testBmp;
//
- public UserControl1()
- {
- InitializeComponent();
- }
+ public UserControl1()
+ {
+ InitializeComponent();
+ }
- #region Component 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();
- }
- #endregion
- }
+ #region Component 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();
+ }
+ #endregion
+ }
}
diff --git a/snippets/csharp/System.Drawing.Design/CategoryNameCollection/Overview/toolboxcategorynamescontrol.cs b/snippets/csharp/System.Drawing.Design/CategoryNameCollection/Overview/toolboxcategorynamescontrol.cs
index 26166a13d7a..693ddefb03c 100644
--- a/snippets/csharp/System.Drawing.Design/CategoryNameCollection/Overview/toolboxcategorynamescontrol.cs
+++ b/snippets/csharp/System.Drawing.Design/CategoryNameCollection/Overview/toolboxcategorynamescontrol.cs
@@ -3,15 +3,15 @@
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
+using System.Data;
using System.Drawing;
using System.Drawing.Design;
-using System.Data;
using System.Windows.Forms;
namespace ToolboxCategoryNamesControl
{
public class ToolboxCategoryNamesControl : System.Windows.Forms.UserControl
- {
+ {
private System.Drawing.Design.IToolboxService toolboxService;
private System.Drawing.Design.CategoryNameCollection categoryNames;
diff --git a/snippets/csharp/System.Drawing.Design/IPropertyValueUIService/Overview/propertyuicomponent.cs b/snippets/csharp/System.Drawing.Design/IPropertyValueUIService/Overview/propertyuicomponent.cs
index 2026b11aba9..8fd5e60822c 100644
--- a/snippets/csharp/System.Drawing.Design/IPropertyValueUIService/Overview/propertyuicomponent.cs
+++ b/snippets/csharp/System.Drawing.Design/IPropertyValueUIService/Overview/propertyuicomponent.cs
@@ -10,8 +10,8 @@ namespace PropertyValueUIServiceExample
// This component obtains the IPropertyValueUIService and adds a
// PropertyValueUIHandler that provides PropertyValueUIItem objects,
// which provide an image, ToolTip, and invoke event handler to
- // any properties named HorizontalMargin and VerticalMargin,
- // such as the example integer properties on this component.
+ // any properties named HorizontalMargin and VerticalMargin,
+ // such as the example integer properties on this component.
public class PropertyUIComponent : System.ComponentModel.Component
{
// Example property for which to provide a PropertyValueUIItem.
@@ -22,14 +22,10 @@ public class PropertyUIComponent : System.ComponentModel.Component
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int VerticalMargin { get; set; }
- // Field storing the value of the VerticalMargin property.
- private int vMargin;
-
// Constructor.
public PropertyUIComponent(System.ComponentModel.IContainer container)
{
- if (container != null)
- container.Add(this);
+ container?.Add(this);
HorizontalMargin = 0;
VerticalMargin = 0;
}
@@ -48,10 +44,10 @@ private void marginPropertyValueUIHandler(
{
// A PropertyValueUIHandler added to the IPropertyValueUIService
// is queried once for each property of a component and passed
- // a PropertyDescriptor that represents the characteristics of
- // the property when the Properties window is set to a new
- // component. A PropertyValueUIHandler can determine whether
- // to add a PropertyValueUIItem for the object to its ValueUIItem
+ // a PropertyDescriptor that represents the characteristics of
+ // the property when the Properties window is set to a new
+ // component. A PropertyValueUIHandler can determine whether
+ // to add a PropertyValueUIItem for the object to its ValueUIItem
// list depending on the values of the PropertyDescriptor.
if (propDesc.DisplayName.Equals("HorizontalMargin"))
{
@@ -67,7 +63,7 @@ private void marginPropertyValueUIHandler(
}
//
- // Invoke handler associated with the PropertyValueUIItem objects
+ // Invoke handler associated with the PropertyValueUIItem objects
// provided by the marginPropertyValueUIHandler.
private void marginInvoke(System.ComponentModel.ITypeDescriptorContext context, System.ComponentModel.PropertyDescriptor propDesc, PropertyValueUIItem item)
{
@@ -75,7 +71,7 @@ private void marginInvoke(System.ComponentModel.ITypeDescriptorContext context,
}
// Component.Site override to add the marginPropertyValueUIHandler
- // when the component is sited, and to remove it when the site is
+ // when the component is sited, and to remove it when the site is
// set to null.
public override System.ComponentModel.ISite Site
{
@@ -89,14 +85,12 @@ public override System.ComponentModel.ISite Site
{
base.Site = value;
IPropertyValueUIService uiService = (IPropertyValueUIService)this.GetService(typeof(IPropertyValueUIService));
- if (uiService != null)
- uiService.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
+ uiService?.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
}
else
{
IPropertyValueUIService uiService = (IPropertyValueUIService)this.GetService(typeof(IPropertyValueUIService));
- if (uiService != null)
- uiService.RemovePropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
+ uiService?.RemovePropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
base.Site = value;
}
}
diff --git a/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/itoolboxservicecontrol.cs b/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/itoolboxservicecontrol.cs
index 38c09d637be..62aa6e4e055 100644
--- a/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/itoolboxservicecontrol.cs
+++ b/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/itoolboxservicecontrol.cs
@@ -3,21 +3,21 @@
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
-using System.Drawing;
-using System.Drawing.Design;
using System.Data;
using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Design;
using System.Windows.Forms;
namespace IToolboxServiceExample
-{
- // Provides an example control that functions in design mode to
- // demonstrate use of the IToolboxService to list and select toolbox
- // categories and items, and to add components or controls
+{
+ // Provides an example control that functions in design mode to
+ // demonstrate use of the IToolboxService to list and select toolbox
+ // categories and items, and to add components or controls
// to the parent form using code.
[DesignerAttribute(typeof(WindowMessageDesigner), typeof(IDesigner))]
public class IToolboxServiceControl : System.Windows.Forms.UserControl
- {
+ {
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private IToolboxService toolboxService = null;
@@ -30,7 +30,7 @@ public IToolboxServiceControl()
listBox2.DoubleClick += new EventHandler(this.CreateComponent);
controlSpacingMultiplier = 0;
}
-
+
// Obtain or reset IToolboxService reference on each siting of control.
public override System.ComponentModel.ISite Site
{
@@ -39,18 +39,18 @@ public override System.ComponentModel.ISite Site
return base.Site;
}
set
- {
+ {
base.Site = value;
- // If the component was sited, attempt to obtain
+ // If the component was sited, attempt to obtain
// an IToolboxService instance.
- if( base.Site != null )
+ if (base.Site != null)
{
toolboxService = (IToolboxService)this.GetService(typeof(IToolboxService));
- // If an IToolboxService was located, update the
+ // If an IToolboxService was located, update the
// category list.
- if( toolboxService != null )
- UpdateLists();
+ if (toolboxService != null)
+ UpdateLists();
}
else
{
@@ -59,25 +59,25 @@ public override System.ComponentModel.ISite Site
}
}
- // Updates the list of categories and the list of items in the
+ // Updates the list of categories and the list of items in the
// selected category.
private void UpdateLists()
{
- if( toolboxService != null )
+ if (toolboxService != null)
{
this.listBox1.SelectedIndexChanged -= new System.EventHandler(this.UpdateSelectedCategory);
this.listBox2.SelectedIndexChanged -= new System.EventHandler(this.UpdateSelectedItem);
listBox1.Items.Clear();
- for( int i=0; i 10 )
+ if (parentForm != null && comps[i].GetType().IsSubclassOf(typeof(System.Windows.Forms.Control)))
+ {
+ ((System.Windows.Forms.Control)comps[i]).Location = new Point(20 * controlSpacingMultiplier, 20 * controlSpacingMultiplier);
+ if (controlSpacingMultiplier > 10)
controlSpacingMultiplier = 0;
else
controlSpacingMultiplier++;
- parentForm.Controls.Add( (System.Windows.Forms.Control)comps[i] );
+ parentForm.Controls.Add((System.Windows.Forms.Control)comps[i]);
}
}
}
@@ -167,53 +167,53 @@ protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
e.Graphics.DrawString("Category List", new Font("Arial", 8), new SolidBrush(Color.Black), 8, 26);
e.Graphics.DrawString("Items in Category", new Font("Arial", 8), new SolidBrush(Color.Black), 208, 26);
e.Graphics.DrawString("(Double-click item to add to parent form)", new Font("Arial", 7), new SolidBrush(Color.Black), 232, 12);
- }
+ }
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
- this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left);
this.listBox1.Location = new System.Drawing.Point(8, 41);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(192, 368);
this.listBox1.TabIndex = 0;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.UpdateSelectedCategory);
- this.listBox2.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
+ this.listBox2.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.listBox2.Location = new System.Drawing.Point(208, 41);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(228, 368);
this.listBox2.TabIndex = 3;
this.BackColor = System.Drawing.Color.Beige;
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
+ this.Controls.AddRange([
this.listBox2,
- this.listBox1});
+ this.listBox1]);
this.Location = new System.Drawing.Point(500, 400);
this.Name = "IToolboxServiceControl";
this.Size = new System.Drawing.Size(442, 422);
this.ResumeLayout(false);
- }
+ }
}
-
- // This designer passes window messages to the controls at design time.
+
+ // This designer passes window messages to the controls at design time.
public class WindowMessageDesigner : System.Windows.Forms.Design.ControlDesigner
{
public WindowMessageDesigner()
{
}
-
+
// Window procedure override passes events to control.
protected override void WndProc(ref System.Windows.Forms.Message m)
- {
- if( m.HWnd == this.Control.Handle )
- base.WndProc(ref m);
- else
- this.DefWndProc(ref m);
- }
+ {
+ if (m.HWnd == this.Control.Handle)
+ base.WndProc(ref m);
+ else
+ this.DefWndProc(ref m);
+ }
}
}
//
diff --git a/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/textdatatextboxcomponent.cs b/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/textdatatextboxcomponent.cs
index 75983c56d88..33e5d609595 100644
--- a/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/textdatatextboxcomponent.cs
+++ b/snippets/csharp/System.Drawing.Design/IToolboxService/Overview/textdatatextboxcomponent.cs
@@ -9,8 +9,8 @@
namespace TextDataTextBoxComponent
{
- // Component that adds a "Text" data format ToolboxItemCreatorCallback
- // to the Toolbox. This component uses a custom ToolboxItem that
+ // Component that adds a "Text" data format ToolboxItemCreatorCallback
+ // to the Toolbox. This component uses a custom ToolboxItem that
// creates a TextBox containing the text data.
public class TextDataTextBoxComponent : Component
{
@@ -18,10 +18,10 @@ public class TextDataTextBoxComponent : Component
private IToolboxService ts;
public TextDataTextBoxComponent()
- {
+ {
}
- // ISite override to register TextBox creator
+ // ISite override to register TextBox creator.
public override System.ComponentModel.ISite Site
{
get
@@ -31,7 +31,7 @@ public override System.ComponentModel.ISite Site
set
{
if( value != null )
- {
+ {
base.Site = value;
if (!creatorAdded)
@@ -46,27 +46,27 @@ public override System.ComponentModel.ISite Site
RemoveTextTextBoxCreator();
}
- base.Site = value;
+ base.Site = value;
}
}
}
- // Adds a "Text" data format creator to the toolbox that creates
+ // Adds a "Text" data format creator to the toolbox that creates
// a textbox from a text fragment pasted to the toolbox.
private void AddTextTextBoxCreator()
{
ts = (IToolboxService)GetService(typeof(IToolboxService));
- if (ts != null)
+ if (ts != null)
{
- ToolboxItemCreatorCallback textCreator =
- new ToolboxItemCreatorCallback(this.CreateTextBoxForText);
+ ToolboxItemCreatorCallback textCreator =
+ new(this.CreateTextBoxForText);
try
{
ts.AddCreator(
- textCreator,
- "Text",
+ textCreator,
+ "Text",
(IDesignerHost)GetService(typeof(IDesignerHost)));
creatorAdded = true;
@@ -74,32 +74,32 @@ private void AddTextTextBoxCreator()
catch(Exception ex)
{
MessageBox.Show(
- ex.ToString(),
+ ex.ToString(),
"Exception Information");
- }
+ }
}
}
// Removes any "Text" data format creator from the toolbox.
private void RemoveTextTextBoxCreator()
{
- if (ts != null)
+ if (ts != null)
{
ts.RemoveCreator(
- "Text",
- (IDesignerHost)GetService(typeof(IDesignerHost)));
+ "Text",
+ (IDesignerHost)GetService(typeof(IDesignerHost)));
creatorAdded = false;
}
}
- // ToolboxItemCreatorCallback delegate format method to create
+ // ToolboxItemCreatorCallback delegate format method to create
// the toolbox item.
private ToolboxItem CreateTextBoxForText(
- object serializedObject,
+ object serializedObject,
string format)
{
- DataObject o = new DataObject((IDataObject)serializedObject);
+ DataObject o = new((IDataObject)serializedObject);
string[] formats = o.GetFormats();
@@ -118,7 +118,7 @@ protected override void Dispose(bool disposing)
{
RemoveTextTextBoxCreator();
}
- }
+ }
}
// Custom toolbox item creates a TextBox and sets its Text property
@@ -133,26 +133,26 @@ public TextToolboxItem(string text) : base()
this.text = text;
}
- // ToolboxItem.CreateComponentsCore override to create the TextBox
+ // ToolboxItem.CreateComponentsCore override to create the TextBox
// and link a method to set its Text property.
protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
- System.Windows.Forms.TextBox textbox =
+ System.Windows.Forms.TextBox textbox =
(TextBox)host.CreateComponent(typeof(TextBox));
-
- // Because the designer resets the text of the textbox, use
- // a SetTextMethodHandler to set the text to the value of
+
+ // Because the designer resets the text of the textbox, use
+ // a SetTextMethodHandler to set the text to the value of
// the text data.
Control c = host.RootComponent as Control;
c.BeginInvoke(
- new SetTextMethodHandler(OnSetText),
- new object[] {textbox, text});
-
- return new System.ComponentModel.IComponent[] { textbox };
- }
+ new SetTextMethodHandler(OnSetText),
+ [textbox, text]);
+
+ return [textbox];
+ }
// Method to set the text property of a TextBox after it is initialized.
- private void OnSetText(Control c, string text)
+ private void OnSetText(Control c, string text)
{
c.Text = text;
}
diff --git a/snippets/csharp/System.Drawing.Design/ToolboxItemCollection/.ctor/class1.cs b/snippets/csharp/System.Drawing.Design/ToolboxItemCollection/.ctor/class1.cs
index af2c7179f34..6444e40963d 100644
--- a/snippets/csharp/System.Drawing.Design/ToolboxItemCollection/.ctor/class1.cs
+++ b/snippets/csharp/System.Drawing.Design/ToolboxItemCollection/.ctor/class1.cs
@@ -7,23 +7,23 @@
namespace ToolboxItemCollectionExample
{
- class Class1
- {
- [STAThread]
- static void Main(string[] args)
- {
+ class Class1
+ {
+ [STAThread]
+ static void Main(string[] args)
+ {
//
// Create a new ToolboxItemCollection using a ToolboxItem array.
- ToolboxItemCollection collection =
- new ToolboxItemCollection( new ToolboxItem[] {
- new ToolboxItem(typeof(System.Windows.Forms.Label)),
- new ToolboxItem(typeof(System.Windows.Forms.TextBox)) } );
+ ToolboxItemCollection collection = new ToolboxItemCollection(
+ [
+ new ToolboxItem(typeof(Label)),
+ new ToolboxItem(typeof(TextBox))
+ ]);
//
//
// Create a new ToolboxItemCollection using an existing ToolboxItemCollection.
- ToolboxItemCollection coll =
- new ToolboxItemCollection( collection );
+ ToolboxItemCollection coll = new ToolboxItemCollection(collection);
//
//
@@ -34,23 +34,27 @@ static void Main(string[] args)
//
// Get the ToolboxItem at each index.
ToolboxItem item = null;
- for( int index = 0; index
//
- // If the collection contains the specified ToolboxItem,
+ // If the collection contains the specified ToolboxItem,
// retrieve the collection index of the specified item.
int indx = -1;
- if( collection.Contains( item ) )
- indx = collection.IndexOf( item );
+ if (collection.Contains(item))
+ {
+ indx = collection.IndexOf(item);
+ }
//
//
// Copy the ToolboxItemCollection to the specified array.
ToolboxItem[] items = new ToolboxItem[collection.Count];
- collection.CopyTo( items, 0 );
+ collection.CopyTo(items, 0);
//
- }
- }
-}
\ No newline at end of file
+ }
+ }
+}
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditor/Overview/angleeditor.cs b/snippets/csharp/System.Drawing.Design/UITypeEditor/Overview/angleeditor.cs
index d6acee85001..d7447209b56 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditor/Overview/angleeditor.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditor/Overview/angleeditor.cs
@@ -8,9 +8,9 @@
namespace AngleEditor
{
- // This UITypeEditor can be associated with Int32, Double and Single
+ // This UITypeEditor can be associated with int, double, and float
// properties to provide a design-mode angle selection interface.
- public class AngleEditor : System.Drawing.Design.UITypeEditor
+ public class AngleEditor : UITypeEditor
{
public AngleEditor()
{
@@ -26,25 +26,25 @@ public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.
// Displays the UI for value selection.
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
{
- // Return the value if the value is not of type Int32, Double and Single.
- if( value.GetType() != typeof(double) && value.GetType() != typeof(float) && value.GetType() != typeof(int) )
+ // Return the value if the value isn't of type int, double, or float.
+ if (value.GetType() != typeof(double) && value.GetType() != typeof(float) && value.GetType() != typeof(int))
return value;
// Uses the IWindowsFormsEditorService to display a
// drop-down UI in the Properties window.
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
- if( edSvc != null )
+ if (edSvc != null)
{
// Display an angle selection control and retrieve the value.
- AngleControl angleControl = new AngleControl((double)value);
- edSvc.DropDownControl( angleControl );
+ AngleControl angleControl = new((double)value);
+ edSvc.DropDownControl(angleControl);
- // Return the value in the appropraite data format.
- if( value.GetType() == typeof(double) )
+ // Return the value in the appropriate data format.
+ if (value.GetType() == typeof(double))
return angleControl.angle;
- else if( value.GetType() == typeof(float) )
+ else if (value.GetType() == typeof(float))
return (float)angleControl.angle;
- else if( value.GetType() == typeof(int) )
+ else if (value.GetType() == typeof(int))
return (int)angleControl.angle;
}
return value;
@@ -53,19 +53,19 @@ public override object EditValue(System.ComponentModel.ITypeDescriptorContext co
// Draws a representation of the property's value.
public override void PaintValue(System.Drawing.Design.PaintValueEventArgs e)
{
- int normalX = (e.Bounds.Width/2);
- int normalY = (e.Bounds.Height/2);
+ int normalX = (e.Bounds.Width / 2);
+ int normalY = (e.Bounds.Height / 2);
// Fill background and ellipse and center point.
e.Graphics.FillRectangle(new SolidBrush(Color.DarkBlue), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
- e.Graphics.FillEllipse(new SolidBrush(Color.White), e.Bounds.X+1, e.Bounds.Y+1, e.Bounds.Width-3, e.Bounds.Height-3);
- e.Graphics.FillEllipse(new SolidBrush(Color.SlateGray), normalX+e.Bounds.X-1, normalY+e.Bounds.Y-1, 3, 3);
+ e.Graphics.FillEllipse(new SolidBrush(Color.White), e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.Width - 3, e.Bounds.Height - 3);
+ e.Graphics.FillEllipse(new SolidBrush(Color.SlateGray), normalX + e.Bounds.X - 1, normalY + e.Bounds.Y - 1, 3, 3);
// Draw line along the current angle.
- double radians = ((double)e.Value*Math.PI) / (double)180;
- e.Graphics.DrawLine( new Pen(new SolidBrush(Color.Red), 1), normalX+e.Bounds.X, normalY+e.Bounds.Y,
- e.Bounds.X+ ( normalX + (int)( (double)normalX * Math.Cos( radians ) ) ),
- e.Bounds.Y+ ( normalY + (int)( (double)normalY * Math.Sin( radians ) ) ) );
+ double radians = ((double)e.Value * Math.PI) / (double)180;
+ e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), normalX + e.Bounds.X, normalY + e.Bounds.Y,
+ e.Bounds.X + (normalX + (int)((double)normalX * Math.Cos(radians))),
+ e.Bounds.Y + (normalY + (int)((double)normalY * Math.Sin(radians))));
}
// Indicates whether the UITypeEditor supports painting a
@@ -91,92 +91,92 @@ internal class AngleControl : System.Windows.Forms.UserControl
public AngleControl(double initial_angle)
{
this.angle = initial_angle;
- this.SetStyle( ControlStyles.AllPaintingInWmPaint, true );
+ this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// Set angle origin point at center of control.
- int originX = (this.Width/2);
- int originY = (this.Height/2);
+ int originX = (this.Width / 2);
+ int originY = (this.Height / 2);
// Fill background and ellipse and center point.
e.Graphics.FillRectangle(new SolidBrush(Color.DarkBlue), 0, 0, this.Width, this.Height);
- e.Graphics.FillEllipse(new SolidBrush(Color.White), 1, 1, this.Width-3, this.Height-3);
- e.Graphics.FillEllipse(new SolidBrush(Color.SlateGray), originX-1, originY-1, 3, 3);
+ e.Graphics.FillEllipse(new SolidBrush(Color.White), 1, 1, this.Width - 3, this.Height - 3);
+ e.Graphics.FillEllipse(new SolidBrush(Color.SlateGray), originX - 1, originY - 1, 3, 3);
// Draw angle markers.
- int startangle = (270-rotation)%360;
- e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), (this.Width/2)-10, 10);
- startangle = (startangle+90)%360;
- e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), this.Width-18, (this.Height/2)-6);
- startangle = (startangle+90)%360;
- e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), (this.Width/2)-6, this.Height-18);
- startangle = (startangle+90)%360;
- e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), 10, (this.Height/2)-6);
+ int startangle = (270 - rotation) % 360;
+ e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), (this.Width / 2) - 10, 10);
+ startangle = (startangle + 90) % 360;
+ e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), this.Width - 18, (this.Height / 2) - 6);
+ startangle = (startangle + 90) % 360;
+ e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), (this.Width / 2) - 6, this.Height - 18);
+ startangle = (startangle + 90) % 360;
+ e.Graphics.DrawString(startangle.ToString(), new Font("Arial", 8), new SolidBrush(Color.DarkGray), 10, (this.Height / 2) - 6);
// Draw line along the current angle.
- double radians = ((((angle+rotation)+360)%360)*Math.PI) / (double)180;
- e.Graphics.DrawLine( new Pen(new SolidBrush(Color.Red), 1), originX, originY,
- originX + (int)( (double)originX * (double)Math.Cos( radians ) ),
- originY + (int)( (double)originY * (double)Math.Sin( radians ) ) );
+ double radians = ((((angle + rotation) + 360) % 360) * Math.PI) / (double)180;
+ e.Graphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), originX, originY,
+ originX + (int)((double)originX * (double)Math.Cos(radians)),
+ originY + (int)((double)originY * (double)Math.Sin(radians)));
// Output angle information.
- e.Graphics.FillRectangle(new SolidBrush(Color.Gray), this.Width-84, 3, 82, 13);
- e.Graphics.DrawString("Angle: "+angle.ToString("F4"), new Font("Arial", 8), new SolidBrush(Color.Yellow), this.Width-84, 2);
+ e.Graphics.FillRectangle(new SolidBrush(Color.Gray), this.Width - 84, 3, 82, 13);
+ e.Graphics.DrawString("Angle: " + angle.ToString("F4"), new Font("Arial", 8), new SolidBrush(Color.Yellow), this.Width - 84, 2);
// Draw square at mouse position of last angle adjustment.
- e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 1), dbx-2, dby-2, 4, 4);
+ e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 1), dbx - 2, dby - 2, 4, 4);
// Draw rotation adjustment buttons.
- if( overButton == 1 )
+ if (overButton == 1)
{
- e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width-28, this.Height-14, 12, 12);
- e.Graphics.FillRectangle(new SolidBrush(Color.Gray), 2, this.Height-13, 110, 12);
- e.Graphics.DrawString("Rotate 90 degrees left", new Font("Arial", 8), new SolidBrush(Color.White), 2, this.Height-14);
+ e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width - 28, this.Height - 14, 12, 12);
+ e.Graphics.FillRectangle(new SolidBrush(Color.Gray), 2, this.Height - 13, 110, 12);
+ e.Graphics.DrawString("Rotate 90 degrees left", new Font("Arial", 8), new SolidBrush(Color.White), 2, this.Height - 14);
}
else
{
- e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width-28, this.Height-14, 12, 12);
+ e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width - 28, this.Height - 14, 12, 12);
}
- if ( overButton == 2 )
+ if (overButton == 2)
{
- e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width-14, this.Height-14, 12, 12);
- e.Graphics.FillRectangle(new SolidBrush(Color.Gray), 2, this.Height-13, 116, 12);
- e.Graphics.DrawString("Rotate 90 degrees right", new Font("Arial", 8), new SolidBrush(Color.White), 2, this.Height-14);
+ e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width - 14, this.Height - 14, 12, 12);
+ e.Graphics.FillRectangle(new SolidBrush(Color.Gray), 2, this.Height - 13, 116, 12);
+ e.Graphics.DrawString("Rotate 90 degrees right", new Font("Arial", 8), new SolidBrush(Color.White), 2, this.Height - 14);
}
else
{
- e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width-14, this.Height-14, 12, 12);
+ e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width - 14, this.Height - 14, 12, 12);
}
- e.Graphics.DrawEllipse(new Pen(new SolidBrush(Color.White), 1), this.Width-11, this.Height-11, 6, 6);
- e.Graphics.DrawEllipse(new Pen(new SolidBrush(Color.White), 1), this.Width-25, this.Height-11, 6, 6);
- if( overButton == 1 )
- e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width-25, this.Height-6, 4, 4);
+ e.Graphics.DrawEllipse(new Pen(new SolidBrush(Color.White), 1), this.Width - 11, this.Height - 11, 6, 6);
+ e.Graphics.DrawEllipse(new Pen(new SolidBrush(Color.White), 1), this.Width - 25, this.Height - 11, 6, 6);
+ if (overButton == 1)
+ e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width - 25, this.Height - 6, 4, 4);
else
- e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width-25, this.Height-6, 4, 4);
- if( overButton == 2 )
- e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width-8, this.Height-6, 4, 4);
+ e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width - 25, this.Height - 6, 4, 4);
+ if (overButton == 2)
+ e.Graphics.FillRectangle(new SolidBrush(Color.Green), this.Width - 8, this.Height - 6, 4, 4);
else
- e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width-8, this.Height-6, 4, 4);
- e.Graphics.FillPolygon(new SolidBrush(Color.White), new Point[] { new Point(this.Width-7, this.Height-8), new Point(this.Width-3, this.Height-8), new Point(this.Width-5, this.Height-4) });
- e.Graphics.FillPolygon(new SolidBrush(Color.White), new Point[] { new Point(this.Width-26, this.Height-8), new Point(this.Width-21, this.Height-8), new Point(this.Width-25, this.Height-4) });
+ e.Graphics.FillRectangle(new SolidBrush(Color.DarkGreen), this.Width - 8, this.Height - 6, 4, 4);
+ e.Graphics.FillPolygon(new SolidBrush(Color.White), [new(this.Width - 7, this.Height - 8), new(this.Width - 3, this.Height - 8), new(this.Width - 5, this.Height - 4)]);
+ e.Graphics.FillPolygon(new SolidBrush(Color.White), [new(this.Width - 26, this.Height - 8), new(this.Width - 21, this.Height - 8), new(this.Width - 25, this.Height - 4)]);
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
// Handle rotation adjustment button clicks.
- if( e.X >= this.Width-28 && e.X <= this.Width-2 && e.Y >= this.Height-14 && e.Y <= this.Height-2 )
+ if (e.X >= this.Width - 28 && e.X <= this.Width - 2 && e.Y >= this.Height - 14 && e.Y <= this.Height - 2)
{
- if( e.X <= this.Width-16 )
+ if (e.X <= this.Width - 16)
rotation -= 90;
- else if( e.X >= this.Width-14 )
+ else if (e.X >= this.Width - 14)
rotation += 90;
- if( rotation < 0 )
+ if (rotation < 0)
rotation += 360;
- rotation = rotation%360;
- dbx=-10;
- dby=-10;
+ rotation = rotation % 360;
+ dbx = -10;
+ dby = -10;
}
else
{
@@ -188,16 +188,16 @@ protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
{
- if( e.Button == MouseButtons.Left )
+ if (e.Button == MouseButtons.Left)
{
UpdateAngle(e.X, e.Y);
overButton = -1;
}
- else if( e.X >= this.Width-28 && e.X <= this.Width-16 && e.Y >= this.Height-14 && e.Y <= this.Height-2 )
+ else if (e.X >= this.Width - 28 && e.X <= this.Width - 16 && e.Y >= this.Height - 14 && e.Y <= this.Height - 2)
{
overButton = 1;
}
- else if( e.X >= this.Width-14 && e.X <= this.Width-2 && e.Y >= this.Height-14 && e.Y <= this.Height-2 )
+ else if (e.X >= this.Width - 14 && e.X <= this.Width - 2 && e.Y >= this.Height - 14 && e.Y <= this.Height - 2)
{
overButton = 2;
}
@@ -216,17 +216,17 @@ private void UpdateAngle(int mx, int my)
dby = my;
// Translate y coordinate input to GetAngle function to correct for ellipsoid distortion.
- double widthToHeightRatio = (double)this.Width/(double)this.Height;
+ double widthToHeightRatio = (double)this.Width / (double)this.Height;
int tmy;
- if( my == 0 )
+ if (my == 0)
tmy = my;
- else if( my < this.Height/2 )
- tmy = (this.Height/2)-(int)(((this.Height/2)-my)*widthToHeightRatio);
+ else if (my < this.Height / 2)
+ tmy = (this.Height / 2) - (int)(((this.Height / 2) - my) * widthToHeightRatio);
else
- tmy = (this.Height/2)+(int)((double)(my-(this.Height/2))*widthToHeightRatio);
+ tmy = (this.Height / 2) + (int)((double)(my - (this.Height / 2)) * widthToHeightRatio);
// Retrieve updated angle based on rise over run.
- angle = (GetAngle(this.Width/2, this.Height/2, mx, tmy)-rotation)%360;
+ angle = (GetAngle(this.Width / 2, this.Height / 2, mx, tmy) - rotation) % 360;
}
private double GetAngle(int x1, int y1, int x2, int y2)
@@ -234,9 +234,9 @@ private double GetAngle(int x1, int y1, int x2, int y2)
double degrees;
// Avoid divide by zero run values.
- if( x2-x1 == 0 )
+ if (x2 - x1 == 0)
{
- if( y2 > y1 )
+ if (y2 > y1)
degrees = 90;
else
degrees = 270;
@@ -244,16 +244,16 @@ private double GetAngle(int x1, int y1, int x2, int y2)
else
{
// Calculate angle from offset.
- double riseoverrun = (double)(y2-y1)/(double)(x2-x1);
- double radians = Math.Atan( riseoverrun );
- degrees = radians * ((double)180/Math.PI);
+ double riseoverrun = (double)(y2 - y1) / (double)(x2 - x1);
+ double radians = Math.Atan(riseoverrun);
+ degrees = radians * ((double)180 / Math.PI);
// Handle quadrant specific transformations.
- if( (x2-x1) < 0 || (y2-y1) < 0 )
+ if ((x2 - x1) < 0 || (y2 - y1) < 0)
degrees += 180;
- if( (x2-x1) > 0 && (y2-y1) < 0 )
+ if ((x2 - x1) > 0 && (y2 - y1) < 0)
degrees -= 180;
- if( degrees < 0 )
+ if (degrees < 0)
degrees += 360;
}
return degrees;
@@ -279,20 +279,20 @@ public AngleEditorTestControl()
{
int_angle = 90;
this.Size = new Size(190, 42);
- this.BackColor = Color.Beige;
+ this.BackColor = Color.Beige;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
- if( this.DesignMode )
+ if (this.DesignMode)
{
- e.Graphics.DrawString("Use the Properties Window to access", new Font("Arial", 8), new SolidBrush(Color.Black), 3,2);
- e.Graphics.DrawString("the AngleEditor UITypeEditor by", new Font("Arial", 8), new SolidBrush(Color.Black), 3,14);
- e.Graphics.DrawString("configuring the \"Angle\" property.", new Font("Arial", 8), new SolidBrush(Color.Black), 3,26);
+ e.Graphics.DrawString("Use the Properties Window to access", new Font("Arial", 8), new SolidBrush(Color.Black), 3, 2);
+ e.Graphics.DrawString("the AngleEditor UITypeEditor by", new Font("Arial", 8), new SolidBrush(Color.Black), 3, 14);
+ e.Graphics.DrawString("configuring the \"Angle\" property.", new Font("Arial", 8), new SolidBrush(Color.Black), 3, 26);
}
else
{
- e.Graphics.DrawString("This example requires design mode.", new Font("Arial", 8), new SolidBrush(Color.Black), 3,2);
+ e.Graphics.DrawString("This example requires design mode.", new Font("Arial", 8), new SolidBrush(Color.Black), 3, 2);
}
}
}
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/imarqueewidget.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/imarqueewidget.cs
index c31bbfcb2ce..3c249f759c8 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/imarqueewidget.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/imarqueewidget.cs
@@ -10,13 +10,13 @@ namespace MarqueeControlLibrary
public interface IMarqueeWidget
{
//
- // This method starts the animation. If the control can
+ // This method starts the animation. If the control can
// contain other classes that implement IMarqueeWidget as
// children, the control should call StartMarquee on all
// its IMarqueeWidget child controls.
void StartMarquee();
- // This method stops the animation. If the control can
+ // This method stops the animation. If the control can
// contain other classes that implement IMarqueeWidget as
// children, the control should call StopMarquee on all
// its IMarqueeWidget child controls.
@@ -32,4 +32,4 @@ int UpdatePeriod
}
//
}
-//
\ No newline at end of file
+//
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/lightshapeselectioncontrol.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/lightshapeselectioncontrol.cs
index 4a4792041e0..05be03d4cfc 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/lightshapeselectioncontrol.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/lightshapeselectioncontrol.cs
@@ -14,196 +14,193 @@ namespace MarqueeControlLibrary
// This control provides the custom UI for the LightShape property
// of the MarqueeBorder. It is used by the LightShapeEditor.
public class LightShapeSelectionControl : System.Windows.Forms.UserControl
- {
+ {
//
private MarqueeLightShape lightShapeValue = MarqueeLightShape.Square;
//
private IWindowsFormsEditorService editorService = null;
private System.Windows.Forms.Panel squarePanel;
- private System.Windows.Forms.Panel circlePanel;
-
- // Required designer variable.
- private System.ComponentModel.Container components = null;
+ private System.Windows.Forms.Panel circlePanel;
+
+ // Required designer variable.
+ private System.ComponentModel.Container components = null;
//
// This constructor takes a MarqueeLightShape value from the
// design-time environment, which will be used to display
// the initial state.
- public LightShapeSelectionControl(
+ public LightShapeSelectionControl(
MarqueeLightShape lightShape,
- IWindowsFormsEditorService editorService )
- {
- // This call is required by the designer.
- InitializeComponent();
+ IWindowsFormsEditorService editorService)
+ {
+ // This call is required by the designer.
+ InitializeComponent();
- // Cache the light shape value provided by the
+ // Cache the light shape value provided by the
// design-time environment.
- this.lightShapeValue = lightShape;
+ this.lightShapeValue = lightShape;
// Cache the reference to the editor service.
this.editorService = editorService;
- // Handle the Click event for the two panels.
- this.squarePanel.Click += new EventHandler(squarePanel_Click);
- this.circlePanel.Click += new EventHandler(circlePanel_Click);
- }
+ // Handle the Click event for the two panels.
+ this.squarePanel.Click += new EventHandler(squarePanel_Click);
+ this.circlePanel.Click += new EventHandler(circlePanel_Click);
+ }
//
//
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
// Be sure to unhook event handlers
// to prevent "lapsed listener" leaks.
- this.squarePanel.Click -=
+ this.squarePanel.Click -=
new EventHandler(squarePanel_Click);
- this.circlePanel.Click -=
+ this.circlePanel.Click -=
new EventHandler(circlePanel_Click);
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
+ components?.Dispose();
+ }
+ base.Dispose(disposing);
+ }
//
//
// LightShape is the property for which this control provides
// a custom user interface in the Properties window.
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
- public MarqueeLightShape LightShape
- {
- get
- {
- return this.lightShapeValue;
- }
-
- set
- {
- if( this.lightShapeValue != value )
- {
- this.lightShapeValue = value;
- }
- }
- }
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
+ public MarqueeLightShape LightShape
+ {
+ get
+ {
+ return this.lightShapeValue;
+ }
+
+ set
+ {
+ if (this.lightShapeValue != value)
+ {
+ this.lightShapeValue = value;
+ }
+ }
+ }
//
//
protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint (e);
+ {
+ base.OnPaint(e);
- using(
- Graphics gSquare = this.squarePanel.CreateGraphics(),
- gCircle = this.circlePanel.CreateGraphics() )
- {
+ using (
+ Graphics gSquare = this.squarePanel.CreateGraphics(),
+ gCircle = this.circlePanel.CreateGraphics())
+ {
// Draw a filled square in the client area of
// the squarePanel control.
- gSquare.FillRectangle(
- Brushes.Red,
+ gSquare.FillRectangle(
+ Brushes.Red,
0,
0,
this.squarePanel.Width,
this.squarePanel.Height
);
- // If the Square option has been selected, draw a
+ // If the Square option has been selected, draw a
// border inside the squarePanel.
- if( this.lightShapeValue == MarqueeLightShape.Square )
- {
- gSquare.DrawRectangle(
- Pens.Black,
- 0,
- 0,
- this.squarePanel.Width-1,
- this.squarePanel.Height-1);
- }
+ if (this.lightShapeValue == MarqueeLightShape.Square)
+ {
+ gSquare.DrawRectangle(
+ Pens.Black,
+ 0,
+ 0,
+ this.squarePanel.Width - 1,
+ this.squarePanel.Height - 1);
+ }
// Draw a filled circle in the client area of
// the circlePanel control.
- gCircle.Clear( this.circlePanel.BackColor );
- gCircle.FillEllipse(
- Brushes.Blue,
+ gCircle.Clear(this.circlePanel.BackColor);
+ gCircle.FillEllipse(
+ Brushes.Blue,
0,
0,
- this.circlePanel.Width,
+ this.circlePanel.Width,
this.circlePanel.Height
);
- // If the Circle option has been selected, draw a
+ // If the Circle option has been selected, draw a
// border inside the circlePanel.
- if( this.lightShapeValue == MarqueeLightShape.Circle )
- {
- gCircle.DrawRectangle(
- Pens.Black,
- 0,
- 0,
- this.circlePanel.Width-1,
- this.circlePanel.Height-1);
- }
- }
- }
+ if (this.lightShapeValue == MarqueeLightShape.Circle)
+ {
+ gCircle.DrawRectangle(
+ Pens.Black,
+ 0,
+ 0,
+ this.circlePanel.Width - 1,
+ this.circlePanel.Height - 1);
+ }
+ }
+ }
//
//
private void squarePanel_Click(object sender, EventArgs e)
- {
- this.lightShapeValue = MarqueeLightShape.Square;
-
- this.Invalidate( false );
-
+ {
+ this.lightShapeValue = MarqueeLightShape.Square;
+
+ this.Invalidate(false);
+
this.editorService.CloseDropDown();
- }
+ }
- private void circlePanel_Click(object sender, EventArgs e)
- {
+ private void circlePanel_Click(object sender, EventArgs e)
+ {
this.lightShapeValue = MarqueeLightShape.Circle;
- this.Invalidate( false );
+ this.Invalidate(false);
this.editorService.CloseDropDown();
- }
+ }
//
- #region Component Designer generated code
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
+ #region Component Designer generated code
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
this.squarePanel = new System.Windows.Forms.Panel();
this.circlePanel = new System.Windows.Forms.Panel();
this.SuspendLayout();
-//
-// squarePanel
-//
+ //
+ // squarePanel.
+ //
this.squarePanel.Location = new System.Drawing.Point(8, 10);
this.squarePanel.Name = "squarePanel";
this.squarePanel.Size = new System.Drawing.Size(60, 60);
this.squarePanel.TabIndex = 2;
-//
-// circlePanel
-//
+ //
+ // circlePanel.
+ //
this.circlePanel.Location = new System.Drawing.Point(80, 10);
this.circlePanel.Name = "circlePanel";
this.circlePanel.Size = new System.Drawing.Size(60, 60);
this.circlePanel.TabIndex = 3;
-//
-// LightShapeSelectionControl
-//
+ //
+ // LightShapeSelectionControl.
+ //
this.Controls.Add(this.squarePanel);
this.Controls.Add(this.circlePanel);
this.Name = "LightShapeSelectionControl";
this.Size = new System.Drawing.Size(150, 80);
this.ResumeLayout(false);
}
- #endregion
+ #endregion
- }
+ }
//
}
-//
\ No newline at end of file
+//
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborder.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborder.cs
index 1bdc39c3618..109b40954af 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborder.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborder.cs
@@ -34,7 +34,7 @@ public enum MarqueeLightShape
//
//
- [Designer(typeof(MarqueeControlLibrary.Design.MarqueeBorderDesigner ))]
+ [Designer(typeof(MarqueeControlLibrary.Design.MarqueeBorderDesigner))]
[ToolboxItemFilter("MarqueeControlLibrary.MarqueeBorder", ToolboxItemFilterType.Require)]
public partial class MarqueeBorder : Panel, IMarqueeWidget
{
@@ -70,7 +70,7 @@ public MarqueeBorder()
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
- // Initialize light and dark colors
+ // Initialize light and dark colors
// to the control's default values.
this.lightColorValue = this.ForeColor;
this.darkColorValue = this.BackColor;
@@ -93,7 +93,7 @@ public MarqueeBorder()
//
public virtual void StartMarquee()
{
- // The MarqueeBorder control may contain any number of
+ // The MarqueeBorder control cocanntain any number of
// controls that implement IMarqueeWidget, so find
// each IMarqueeWidget child and call its StartMarquee
// method.
@@ -112,7 +112,7 @@ public virtual void StartMarquee()
public virtual void StopMarquee()
{
- // The MarqueeBorder control may contain any number of
+ // The MarqueeBorder control cocanntain any number of
// controls that implement IMarqueeWidget, so find
// each IMarqueeWidget child and call its StopMarquee
// method.
@@ -219,8 +219,8 @@ public Color LightColor
set
{
- // The LightColor property is only changed if the
- // client provides a different value. Comparing values
+ // The LightColor property is only changed if the
+ // client provides a different value. Comparing values
// from the ToArgb method is the recommended test for
// equality between Color structs.
if (this.lightColorValue.ToArgb() != value.ToArgb())
@@ -243,8 +243,8 @@ public Color DarkColor
set
{
- // The DarkColor property is only changed if the
- // client provides a different value. Comparing values
+ // The DarkColor property is only changed if the
+ // client provides a different value. Comparing values
// from the ToArgb method is the recommended test for
// equality between Color structs.
if (this.darkColorValue.ToArgb() != value.ToArgb())
@@ -280,7 +280,7 @@ public int LightSpacing
[Category("Marquee")]
[Browsable(true)]
- [EditorAttribute(typeof(LightShapeEditor),
+ [EditorAttribute(typeof(LightShapeEditor),
typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public MarqueeLightShape LightShape
@@ -328,7 +328,7 @@ protected override void OnLayout(LayoutEventArgs levent)
this.Refresh();
}
- // This method paints the lights around the border of the
+ // This method paints the lights around the border of the
// control. It paints the top row first, followed by the
// right side, the bottom row, and the left side. The color
// of each light is determined by the IsLit method and
@@ -345,7 +345,7 @@ protected override void OnPaint(PaintEventArgs e)
if (this.Width > MaxLightSize &&
this.Height > MaxLightSize)
{
- // The position of the next light will be incremented
+ // The position of the next light will be incremented
// by this value, which is equal to the sum of the
// light size and the space between two lights.
int increment =
@@ -428,10 +428,10 @@ protected override void OnPaint(PaintEventArgs e)
// This method determines if the marquee light at lightIndex
// should be lit. The currentOffset field specifies where
// the "first" light is located, and the "position" of the
- // light given by lightIndex is computed relative to this
+ // light given by lightIndex is computed relative to this
// offset. If this position modulo lightPeriodValue is zero,
// the light is considered to be on, and it will be painted
- // with the control's lightBrush.
+ // with the control's lightBrush.
protected virtual bool IsLit(int lightIndex)
{
int directionFactor =
@@ -470,13 +470,13 @@ protected virtual void DrawLight(
//
//
- // This method is called in the worker thread's context,
+ // This method is called in the worker thread's context,
// so it must not make any calls into the MarqueeBorder
- // control. Instead, it communicates to the control using
+ // control. Instead, it communicates to the control using
// the ProgressChanged event.
//
// The only work done in this event handler is
- // to sleep for the number of milliseconds specified
+ // to sleep for the number of milliseconds specified
// by UpdatePeriod, then raise the ProgressChanged event.
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
@@ -487,13 +487,13 @@ private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWor
while (!worker.CancellationPending)
{
// The Argument property of the DoWorkEventArgs
- // object holds the value of UpdatePeriod, which
+ // object holds the value of UpdatePeriod, which
// was passed as the argument to the RunWorkerAsync
- // method.
+ // method.
Thread.Sleep((int)e.Argument);
// The DoWork eventhandler does not actually report
- // progress; the ReportProgress event is used to
+ // progress; the ReportProgress event is used to
// periodically alert the control to update its state.
worker.ReportProgress(0);
}
@@ -514,7 +514,7 @@ private void backgroundWorker1_ProgressChanged(
//
//
- // This class demonstrates the use of a custom UITypeEditor.
+ // This class demonstrates the use of a custom UITypeEditor.
// It allows the MarqueeBorder control's LightShape property
// to be changed at design time using a customized UI element
// that is invoked by the Properties window. The UI is provided
@@ -552,7 +552,7 @@ public override object EditValue(
if (editorService != null)
{
LightShapeSelectionControl selectionControl =
- new LightShapeSelectionControl(
+ new(
(MarqueeLightShape)value,
editorService);
@@ -571,14 +571,14 @@ public override object EditValue(
// LightShape entry in the PropertyGrid.
public override bool GetPaintValueSupported(
ITypeDescriptorContext context)
- {
+ {
return true;
}
- // This method paints a graphical representation of the
+ // This method paints a graphical representation of the
// selected value of the LightShpae property.
public override void PaintValue(PaintValueEventArgs e)
- {
+ {
MarqueeLightShape shape = (MarqueeLightShape)e.Value;
using (Pen p = Pens.Black)
{
@@ -590,7 +590,7 @@ public override void PaintValue(PaintValueEventArgs e)
{
e.Graphics.DrawEllipse(p, e.Bounds);
}
- }
+ }
}
//
}
@@ -598,13 +598,14 @@ public override void PaintValue(PaintValueEventArgs e)
private void InitializeComponent()
{
- this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
-
-//
-// backgroundWorker1
-//
- this.backgroundWorker1.WorkerReportsProgress = true;
- this.backgroundWorker1.WorkerSupportsCancellation = true;
+ this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker
+ {
+ //
+ // backgroundWorker1.
+ //
+ WorkerReportsProgress = true,
+ WorkerSupportsCancellation = true
+ };
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
}
@@ -612,4 +613,4 @@ private void InitializeComponent()
#endregion
}
}
-//
\ No newline at end of file
+//
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborderdesigner.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborderdesigner.cs
index 17eccd7e7c4..2822e069995 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborderdesigner.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueeborderdesigner.cs
@@ -51,7 +51,7 @@ public bool Enabled
protected override void PreFilterProperties(IDictionary properties)
{
base.PreFilterProperties(properties);
-
+
if (properties.Contains("Padding"))
{
properties.Remove("Padding");
@@ -60,12 +60,12 @@ protected override void PreFilterProperties(IDictionary properties)
properties["Visible"] = TypeDescriptor.CreateProperty(
typeof(MarqueeBorderDesigner),
(PropertyDescriptor)properties["Visible"],
- new Attribute[0]);
+ []);
properties["Enabled"] = TypeDescriptor.CreateProperty(
typeof(MarqueeBorderDesigner),
(PropertyDescriptor)properties["Enabled"],
- new Attribute[0]);
+ []);
}
//
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrol.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrol.cs
index 5329bc844d0..d00c92e408e 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrol.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrol.cs
@@ -12,12 +12,12 @@
namespace MarqueeControlLibrary
{
//
- [Designer( typeof( MarqueeControlLibrary.Design.MarqueeControlRootDesigner ), typeof( IRootDesigner ) )]
+ [Designer(typeof(MarqueeControlLibrary.Design.MarqueeControlRootDesigner), typeof(IRootDesigner))]
public class MarqueeControl : UserControl
{
- //
+ //
- // Required designer variable.
+ // Required designer variable.
private System.ComponentModel.Container components = null;
//
@@ -26,37 +26,34 @@ public MarqueeControl()
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
- // Minimize flickering during animation by enabling
+ // Minimize flickering during animation by enabling
// double buffering.
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
//
- ///
+ ///
/// 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);
}
//
public void Start()
{
- // The MarqueeControl may contain any number of
- // controls that implement IMarqueeWidget, so
+ // The MarqueeControl may contain any number of
+ // controls that implement IMarqueeWidget, so
// find each IMarqueeWidget child and call its
// StartMarquee method.
- foreach( Control cntrl in this.Controls )
+ foreach (Control cntrl in this.Controls)
{
- if( cntrl is IMarqueeWidget )
+ if (cntrl is IMarqueeWidget)
{
IMarqueeWidget widget = cntrl as IMarqueeWidget;
widget.StartMarquee();
@@ -66,13 +63,13 @@ public void Start()
public void Stop()
{
- // The MarqueeControl may contain any number of
+ // The MarqueeControl may contain any number of
// controls that implement IMarqueeWidget, so find
// each IMarqueeWidget child and call its StopMarquee
// method.
- foreach( Control cntrl in this.Controls )
+ foreach (Control cntrl in this.Controls)
{
- if( cntrl is IMarqueeWidget )
+ if (cntrl is IMarqueeWidget)
{
IMarqueeWidget widget = cntrl as IMarqueeWidget;
widget.StopMarquee();
@@ -84,15 +81,15 @@ public void Stop()
//
protected override void OnLayout(LayoutEventArgs levent)
{
- base.OnLayout (levent);
+ base.OnLayout(levent);
- // Repaint all IMarqueeWidget children if the layout
+ // Repaint all IMarqueeWidget children if the layout
// has changed.
- foreach( Control cntrl in this.Controls )
+ foreach (Control cntrl in this.Controls)
{
- if( cntrl is IMarqueeWidget )
+ if (cntrl is IMarqueeWidget)
{
- Control control = cntrl as Control;
+ Control control = cntrl as Control;
control.PerformLayout();
}
@@ -101,8 +98,8 @@ protected override void OnLayout(LayoutEventArgs levent)
//
#region Component Designer generated code
- ///
- /// Required method for Designer support - do not modify
+ ///
+ /// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
@@ -112,4 +109,4 @@ private void InitializeComponent()
#endregion
}
}
-//
\ No newline at end of file
+//
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrolrootdesigner.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrolrootdesigner.cs
index 6cc08f20523..0e0fd59ce60 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrolrootdesigner.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueecontrolrootdesigner.cs
@@ -33,14 +33,11 @@ public override void Initialize(IComponent component)
base.Initialize(component);
IComponentChangeService cs =
- GetService(typeof(IComponentChangeService))
+ GetService(typeof(IComponentChangeService))
as IComponentChangeService;
- if (cs != null)
- {
- cs.ComponentChanged +=
+ cs?.ComponentChanged +=
new ComponentChangedEventHandler(OnComponentChanged);
- }
//
//
diff --git a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueetext.cs b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueetext.cs
index b6123907834..195f2ddbeae 100644
--- a/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueetext.cs
+++ b/snippets/csharp/System.Drawing.Design/UITypeEditorEditStyle/Overview/marqueetext.cs
@@ -43,7 +43,7 @@ public MarqueeText()
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
- // Initialize light and dark colors
+ // Initialize light and dark colors
// to the control's default values.
this.lightColorValue = this.ForeColor;
this.darkColorValue = this.BackColor;
@@ -109,8 +109,8 @@ public Color LightColor
}
set
{
- // The LightColor property is only changed if the
- // client provides a different value. Comparing values
+ // The LightColor property is only changed if the
+ // client provides a different value. Comparing values
// from the ToArgb method is the recommended test for
// equality between Color structs.
if (this.lightColorValue.ToArgb() != value.ToArgb())
@@ -132,8 +132,8 @@ public Color DarkColor
}
set
{
- // The DarkColor property is only changed if the
- // client provides a different value. Comparing values
+ // The DarkColor property is only changed if the
+ // client provides a different value. Comparing values
// from the ToArgb method is the recommended test for
// equality between Color structs.
if (this.darkColorValue.ToArgb() != value.ToArgb())
@@ -163,13 +163,13 @@ protected override void OnPaint(PaintEventArgs e)
//
//
- // This method is called in the worker thread's context,
+ // This method is called in the worker thread's context,
// so it must not make any calls into the MarqueeText control.
- // Instead, it communicates to the control using the
+ // Instead, it communicates to the control using the
// ProgressChanged event.
//
// The only work done in this event handler is
- // to sleep for the number of milliseconds specified
+ // to sleep for the number of milliseconds specified
// by UpdatePeriod, then raise the ProgressChanged event.
private void backgroundWorker1_DoWork(
object sender,
@@ -182,13 +182,13 @@ private void backgroundWorker1_DoWork(
while (!worker.CancellationPending)
{
// The Argument property of the DoWorkEventArgs
- // object holds the value of UpdatePeriod, which
+ // object holds the value of UpdatePeriod, which
// was passed as the argument to the RunWorkerAsync
- // method.
+ // method.
Thread.Sleep((int)e.Argument);
// The DoWork eventhandler does not actually report
- // progress; the ReportProgress event is used to
+ // progress; the ReportProgress event is used to
// periodically alert the control to update its state.
worker.ReportProgress(0);
}
@@ -197,7 +197,7 @@ private void backgroundWorker1_DoWork(
// The ProgressChanged event is raised by the DoWork method.
// This event handler does work that is internal to the
// control. In this case, the text is toggled between its
- // light and dark state, and the control is told to
+ // light and dark state, and the control is told to
// repaint itself.
private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
@@ -209,13 +209,14 @@ private void backgroundWorker1_ProgressChanged(object sender, System.ComponentMo
private void InitializeComponent()
{
- this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
-
-//
-// backgroundWorker1
-//
- this.backgroundWorker1.WorkerReportsProgress = true;
- this.backgroundWorker1.WorkerSupportsCancellation = true;
+ this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker
+ {
+ //
+ // backgroundWorker1.
+ //
+ WorkerReportsProgress = true,
+ WorkerSupportsCancellation = true
+ };
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
}
@@ -223,4 +224,4 @@ private void InitializeComponent()
#endregion
}
}
-//
\ No newline at end of file
+//
diff --git a/snippets/csharp/System.Drawing.Drawing2D/AdjustableArrowCap/.ctor/form1.cs b/snippets/csharp/System.Drawing.Drawing2D/AdjustableArrowCap/.ctor/form1.cs
index 98dfa934b49..596b422d994 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/AdjustableArrowCap/.ctor/form1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/AdjustableArrowCap/.ctor/form1.cs
@@ -1,9 +1,9 @@
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.Drawing2D.ClassicMiscCS
{
@@ -20,12 +20,12 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
//
- // TODO: Add any constructor code after InitializeComponent call
+ // TODO: Add any constructor code after InitializeComponent call.
//
}
@@ -36,10 +36,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if (components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -59,11 +56,13 @@ private void InitializeComponent()
// Snippet for: M:System.Drawing.Drawing2D.AdjustableArrowCap.#ctor(System.Single,System.Single)
//
public void ConstructAdjArrowCap1(PaintEventArgs e)
- {
+ {
AdjustableArrowCap myArrow = new AdjustableArrowCap(6, 6);
- Pen capPen = new Pen(Color.Black);
- capPen.CustomStartCap = myArrow;
- capPen.CustomEndCap = myArrow;
+ Pen capPen = new(Color.Black)
+ {
+ CustomStartCap = myArrow,
+ CustomEndCap = myArrow
+ };
e.Graphics.DrawLine(capPen, 50, 50, 200, 50);
}
//
@@ -71,11 +70,13 @@ public void ConstructAdjArrowCap1(PaintEventArgs e)
// Snippet for: M:System.Drawing.Drawing2D.AdjustableArrowCap.#ctor(System.Single,System.Single,System.Boolean)
//
public void ConstructAdjArrowCap2(PaintEventArgs e)
- {
+ {
AdjustableArrowCap myArrow = new AdjustableArrowCap(6, 6, false);
- Pen capPen = new Pen(Color.Black);
- capPen.CustomStartCap = myArrow;
- capPen.CustomEndCap = myArrow;
+ Pen capPen = new(Color.Black)
+ {
+ CustomStartCap = myArrow,
+ CustomEndCap = myArrow
+ };
e.Graphics.DrawLine(capPen, 50, 50, 200, 50);
}
//
@@ -84,24 +85,28 @@ public void ConstructAdjArrowCap2(PaintEventArgs e)
//
public void BlendConstExample(PaintEventArgs e)
{
-
+
//Draw ellipse using Blend.
- Point startPoint2 = new Point(20, 110);
- Point endPoint2 = new Point(140, 110);
- float[] myFactors = {.2f,.4f,.8f,.8f,.4f,.2f};
- float[] myPositions = {0.0f,.2f,.4f,.6f,.8f,1.0f};
- Blend myBlend = new Blend();
- myBlend.Factors = myFactors;
- myBlend.Positions = myPositions;
- LinearGradientBrush lgBrush2 = new LinearGradientBrush(
+ Point startPoint2 = new(20, 110);
+ Point endPoint2 = new(140, 110);
+ float[] myFactors = [.2f,.4f,.8f,.8f,.4f,.2f];
+ float[] myPositions = [0.0f,.2f,.4f,.6f,.8f,1.0f];
+ Blend myBlend = new Blend()
+ {
+ Factors = myFactors,
+ Positions = myPositions
+ };
+ LinearGradientBrush lgBrush2 = new(
startPoint2,
endPoint2,
Color.Blue,
- Color.Red);
- lgBrush2.Blend = myBlend;
- Rectangle ellipseRect2 = new Rectangle(20, 110, 120, 80);
+ Color.Red)
+ {
+ Blend = myBlend
+ };
+ Rectangle ellipseRect2 = new(20, 110, 120, 80);
e.Graphics.FillEllipse(lgBrush2, ellipseRect2);
-
+
// End example.
}
//
@@ -110,26 +115,30 @@ public void BlendConstExample(PaintEventArgs e)
//
protected override void OnPaint(PaintEventArgs e)
{
-
+
//Draw ellipse using ColorBlend.
- Point startPoint2 = new Point(20, 110);
- Point endPoint2 = new Point(140, 110);
- Color[] myColors = {Color.Green,
+ Point startPoint2 = new(20, 110);
+ Point endPoint2 = new(140, 110);
+ Color[] myColors = [Color.Green,
Color.Yellow,
Color.Yellow,
Color.Blue,
Color.Red,
- Color.Red};
- float[] myPositions = {0.0f,.20f,.40f,.60f,.80f,1.0f};
- ColorBlend myBlend = new ColorBlend();
- myBlend.Colors = myColors;
- myBlend.Positions = myPositions;
- LinearGradientBrush lgBrush2 = new LinearGradientBrush(startPoint2,
+ Color.Red];
+ float[] myPositions = [0.0f,.20f,.40f,.60f,.80f,1.0f];
+ ColorBlend myBlend = new ColorBlend()
+ {
+ Colors = myColors,
+ Positions = myPositions
+ };
+ LinearGradientBrush lgBrush2 = new(startPoint2,
endPoint2,
Color.Green,
- Color.Red);
- lgBrush2.InterpolationColors = myBlend;
- Rectangle ellipseRect2 = new Rectangle(20, 110, 120, 80);
+ Color.Red)
+ {
+ InterpolationColors = myBlend
+ };
+ Rectangle ellipseRect2 = new(20, 110, 120, 80);
e.Graphics.FillEllipse(lgBrush2, ellipseRect2);
}
//
@@ -138,7 +147,7 @@ protected override void OnPaint(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.Drawing2D/FillMode/Overview/Class1.cs b/snippets/csharp/System.Drawing.Drawing2D/FillMode/Overview/Class1.cs
index f24ea097023..7f931db6860 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/FillMode/Overview/Class1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/FillMode/Overview/Class1.cs
@@ -1,20 +1,20 @@
using System;
-using System.Windows.Forms;
-using System.Drawing;
using System.Collections;
-using System.Xml;
+using System.Drawing;
using System.Drawing.Drawing2D;
+using System.Windows.Forms;
+using System.Xml;
public class SystemDrawingConstructingDrawingPaths
{
// 5a36b0e4-f1f4-46c0-a85a-22ae98491950
- // How to: Fill Open Figures
+ // How to: Fill Open Figures.
private void Method11(PaintEventArgs e)
{
//
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
// Add an open figure.
path.AddArc(0, 0, 150, 120, 30, 120);
@@ -22,8 +22,8 @@ private void Method11(PaintEventArgs e)
// Add an intrinsically closed figure.
path.AddEllipse(50, 50, 50, 100);
- Pen pen = new Pen(Color.FromArgb(128, 0, 0, 255), 5);
- SolidBrush brush = new SolidBrush(Color.Red);
+ Pen pen = new(Color.FromArgb(128, 0, 0, 255), 5);
+ SolidBrush brush = new(Color.Red);
// The fill mode is FillMode.Alternate by default.
e.Graphics.FillPath(brush, path);
@@ -31,12 +31,12 @@ private void Method11(PaintEventArgs e)
//
}
// 82fd56c7-b443-4765-9b7c-62ce030656ec
- // How to: Create Figures from Lines, Curves, and Shapes
+ // How to: Create Figures from Lines, Curves, and Shapes.
private void Method21(PaintEventArgs e)
{
//
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.AddArc(175, 50, 50, 50, 0, -180);
e.Graphics.DrawPath(new Pen(Color.FromArgb(128, 255, 0, 0), 4), path);
//
@@ -45,12 +45,12 @@ private void Method22(PaintEventArgs e)
{
//
// Create an array of points for the curve in the second figure.
- Point[] points = {
+ Point[] points = [
new Point(40, 60),
new Point(50, 70),
- new Point(30, 90)};
+ new Point(30, 90)];
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.StartFigure(); // Start the first figure.
path.AddArc(175, 50, 50, 50, 0, -180);
diff --git a/snippets/csharp/System.Drawing.Drawing2D/GraphicsPath/AddArc/form1.cs b/snippets/csharp/System.Drawing.Drawing2D/GraphicsPath/AddArc/form1.cs
index 2f4febd3a10..cd0eafd4ce6 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/GraphicsPath/AddArc/form1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/GraphicsPath/AddArc/form1.cs
@@ -1,9 +1,9 @@
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.Drawing2D.ClassicGraphicsPathExamplesCS
{
@@ -20,12 +20,12 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
//
- // TODO: Add any constructor code after InitializeComponent call
+ // TODO: Add any constructor code after InitializeComponent call.
//
}
@@ -36,10 +36,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if (components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -61,16 +58,16 @@ private void InitializeComponent()
//
private void AddArcExample(PaintEventArgs e)
{
-
+
// Create a GraphicsPath object.
- GraphicsPath myPath = new GraphicsPath();
-
+ GraphicsPath myPath = new();
+
// Set up and call AddArc, and close the figure.
- Rectangle rect = new Rectangle(20, 20, 50, 100);
+ Rectangle rect = new(20, 20, 50, 100);
myPath.StartFigure();
myPath.AddArc(rect, 0, 180);
myPath.CloseFigure();
-
+
// Draw the path to screen.
e.Graphics.DrawPath(new Pen(Color.Red, 3), myPath);
}
@@ -80,17 +77,17 @@ private void AddArcExample(PaintEventArgs e)
//
private void AddBezierExample(PaintEventArgs e)
{
-
+
// Create a new Path.
- GraphicsPath myPath = new GraphicsPath();
-
+ GraphicsPath myPath = new();
+
// Call AddBezier.
myPath.StartFigure();
myPath.AddBezier(50, 50, 70, 0, 100, 120, 150, 50);
-
+
// Close the curve.
myPath.CloseFigure();
-
+
// Draw the path to screen.
e.Graphics.DrawPath(new Pen(Color.Red, 2), myPath);
}
@@ -100,10 +97,10 @@ private void AddBezierExample(PaintEventArgs e)
//
private void AddBeziersExample(PaintEventArgs e)
{
-
+
// Adds two Bezier curves.
Point[] myArray =
- {
+ [
new Point(20, 100),
new Point(40, 75),
new Point(60, 125),
@@ -111,14 +108,14 @@ private void AddBeziersExample(PaintEventArgs e)
new Point(100, 50),
new Point(120, 150),
new Point(140, 100)
- };
-
+ ];
+
// Create the path and add the curves.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddBeziers(myArray);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -127,23 +124,23 @@ private void AddBeziersExample(PaintEventArgs e)
//
private void AddClosedCurveExample(PaintEventArgs e)
{
-
+
// Creates a symmetrical, closed curve.
Point[] myArray =
- {
+ [
new Point(20,100),
new Point(40,150),
new Point(60,125),
new Point(40,100),
new Point(60,75),
new Point(40,50)
- };
-
+ ];
+
// Create a new path and add curve.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddClosedCurve(myArray,.5f);
- Pen myPen = new Pen(Color.Black, 2);
-
+ Pen myPen = new(Color.Black, 2);
+
// Draw the path to screen.
e.Graphics.DrawPath(myPen, myPath);
}
@@ -153,22 +150,22 @@ private void AddClosedCurveExample(PaintEventArgs e)
//
private void AddCurveExample(PaintEventArgs e)
{
-
+
// Create some points.
- Point point1 = new Point(20, 20);
- Point point2 = new Point(40, 0);
- Point point3 = new Point(60, 40);
- Point point4 = new Point(80, 20);
-
+ Point point1 = new(20, 20);
+ Point point2 = new(40, 0);
+ Point point3 = new(60, 40);
+ Point point4 = new(80, 20);
+
// Create an array of the points.
- Point[] curvePoints = {point1, point2, point3, point4};
-
+ Point[] curvePoints = [point1, point2, point3, point4];
+
// Create a GraphicsPath object and add a curve.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddCurve(curvePoints, 0, 3, 0.8f);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -177,14 +174,14 @@ private void AddCurveExample(PaintEventArgs e)
//
private void AddEllipseExample(PaintEventArgs e)
{
-
+
// Create a path and add an ellipse.
- Rectangle myEllipse = new Rectangle(20, 20, 100, 50);
- GraphicsPath myPath = new GraphicsPath();
+ Rectangle myEllipse = new(20, 20, 100, 50);
+ GraphicsPath myPath = new();
myPath.AddEllipse(myEllipse);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -193,15 +190,15 @@ private void AddEllipseExample(PaintEventArgs e)
//
private void AddLineExample(PaintEventArgs e)
{
-
+
//Create a path and add a symmetrical triangle using AddLine.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddLine(30, 30, 60, 60);
myPath.AddLine(60, 60, 0, 60);
myPath.AddLine(0, 60, 30, 30);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -210,22 +207,22 @@ private void AddLineExample(PaintEventArgs e)
//
private void AddLinesExample(PaintEventArgs e)
{
-
+
// Create a symmetrical triangle using an array of points.
Point[] myArray =
- {
+ [
new Point(30,30),
new Point(60,60),
new Point(0,60),
new Point(30,30)
- };
-
+ ];
+
//Create a path and add lines.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddLines(myArray);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -234,34 +231,34 @@ private void AddLinesExample(PaintEventArgs e)
//
private void AddPathExample(PaintEventArgs e)
{
-
+
// Create the first pathright side up triangle.
Point[] myArray =
- {
+ [
new Point(30,30),
new Point(60,60),
new Point(0,60),
new Point(30,30)
- };
- GraphicsPath myPath = new GraphicsPath();
+ ];
+ GraphicsPath myPath = new();
myPath.AddLines(myArray);
-
+
// Create the second pathinverted triangle.
Point[] myArray2 =
- {
+ [
new Point(30,30),
new Point(0,0),
new Point(60,0),
new Point(30,30)
- };
- GraphicsPath myPath2 = new GraphicsPath();
+ ];
+ GraphicsPath myPath2 = new();
myPath2.AddLines(myArray2);
-
+
// Add the second path to the first path.
myPath.AddPath(myPath2,true);
-
+
// Draw the combined path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -270,13 +267,13 @@ private void AddPathExample(PaintEventArgs e)
//
private void AddPieExample(PaintEventArgs e)
{
-
+
// Create a pie slice of a circle using the AddPie method.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddPie(20, 20, 70, 70, -45, 90);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -285,23 +282,23 @@ private void AddPieExample(PaintEventArgs e)
//
private void AddPolygonExample(PaintEventArgs e)
{
-
+
// Create an array of points.
Point[] myArray =
- {
+ [
new Point(23, 20),
new Point(40, 10),
new Point(57, 20),
new Point(50, 40),
new Point(30, 40)
- };
-
+ ];
+
// Create a GraphicsPath object and add a polygon.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddPolygon(myArray);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -310,14 +307,14 @@ private void AddPolygonExample(PaintEventArgs e)
//
private void AddRectangleExample(PaintEventArgs e)
{
-
+
// Create a GraphicsPath object and add a rectangle to it.
- GraphicsPath myPath = new GraphicsPath();
- Rectangle pathRect = new Rectangle(20, 20, 100, 200);
+ GraphicsPath myPath = new();
+ Rectangle pathRect = new(20, 20, 100, 200);
myPath.AddRectangle(pathRect);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -326,19 +323,19 @@ private void AddRectangleExample(PaintEventArgs e)
//
private void AddRectanglesExample(PaintEventArgs e)
{
-
+
// Adds a pattern of rectangles to a GraphicsPath object.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
Rectangle[] pathRects =
- {
+ [
new Rectangle(20,20,100,200),
new Rectangle(40,40,120,220),
new Rectangle(60,60,240,140)
- };
+ ];
myPath.AddRectangles(pathRects);
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -347,18 +344,18 @@ private void AddRectanglesExample(PaintEventArgs e)
//
private void AddStringExample(PaintEventArgs e)
{
-
+
// Create a GraphicsPath object.
- GraphicsPath myPath = new GraphicsPath();
-
+ GraphicsPath myPath = new();
+
// Set up all the string parameters.
string stringText = "Sample Text";
- FontFamily family = new FontFamily("Arial");
+ FontFamily family = new("Arial");
int fontStyle = (int)FontStyle.Italic;
int emSize = 26;
- Point origin = new Point(20, 20);
+ Point origin = new(20, 20);
StringFormat format = StringFormat.GenericDefault;
-
+
// Add the string to the path.
myPath.AddString(stringText,
family,
@@ -366,7 +363,7 @@ private void AddStringExample(PaintEventArgs e)
emSize,
origin,
format);
-
+
//Draw the path to the screen.
e.Graphics.FillPath(Brushes.Black, myPath);
}
@@ -376,23 +373,23 @@ private void AddStringExample(PaintEventArgs e)
//
private void ClearMarkersExample(PaintEventArgs e)
{
-
+
// Set several markers in a path.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddEllipse(0, 0, 100, 200);
myPath.SetMarkers();
myPath.AddLine(new Point(100, 100), new Point(200, 100));
- Rectangle rect = new Rectangle(200, 0, 100, 200);
+ Rectangle rect = new(200, 0, 100, 200);
myPath.AddRectangle(rect);
myPath.SetMarkers();
myPath.AddLine(new Point(250, 200), new Point(250, 300));
myPath.SetMarkers();
-
+
// Clear the markers.
myPath.ClearMarkers();
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
}
//
@@ -401,24 +398,24 @@ private void ClearMarkersExample(PaintEventArgs e)
//
private void CloneExample(PaintEventArgs e)
{
-
+
// Set several markers in a path.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddEllipse(0, 0, 100, 200);
myPath.AddLine(new Point(100, 100), new Point(200, 100));
- Rectangle rect = new Rectangle(200, 0, 100, 200);
+ Rectangle rect = new(200, 0, 100, 200);
myPath.AddRectangle(rect);
myPath.AddLine(new Point(250, 200), new Point(250, 300));
-
+
// Draw the path to the screen.
- Pen myPen = new Pen(Color.Black, 2);
+ Pen myPen = new(Color.Black, 2);
e.Graphics.DrawPath(myPen, myPath);
-
+
// Clone a copy of myPath.
GraphicsPath myPath2 = (GraphicsPath)myPath.Clone();
-
+
// Draw the path to the screen.
- Pen myPen2 = new Pen(Color.Red, 4);
+ Pen myPen2 = new(Color.Red, 4);
e.Graphics.DrawPath(myPen2, myPath2);
}
//
@@ -427,25 +424,25 @@ private void CloneExample(PaintEventArgs e)
//
private void CloseAllFiguresExample(PaintEventArgs e)
{
-
+
// Create a path containing several open-ended figures.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.StartFigure();
myPath.AddLine(new Point(10, 10), new Point(150, 10));
myPath.AddLine(new Point(150, 10), new Point(10, 150));
myPath.StartFigure();
myPath.AddArc(200, 200, 100, 100, 0, 90);
myPath.StartFigure();
- Point point1 = new Point(300, 300);
- Point point2 = new Point(400, 325);
- Point point3 = new Point(400, 375);
- Point point4 = new Point(300, 400);
- Point[] points = {point1, point2, point3, point4};
+ Point point1 = new(300, 300);
+ Point point2 = new(400, 325);
+ Point point3 = new(400, 375);
+ Point point4 = new(300, 400);
+ Point[] points = [point1, point2, point3, point4];
myPath.AddCurve(points);
-
+
// Close all the figures.
myPath.CloseAllFigures();
-
+
// Draw the path to the screen.
e.Graphics.DrawPath(new Pen(Color.Black, 3), myPath);
}
@@ -455,16 +452,16 @@ private void CloseAllFiguresExample(PaintEventArgs e)
//
private void CloseFigureExample(PaintEventArgs e)
{
-
- // Create a path consisting of two, open-ended lines and close
-
+
+ // Create a path consisting of two, open-ended lines and close.
+
// the lines using CloseFigure.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.StartFigure();
myPath.AddLine(new Point(10, 10), new Point(200, 10));
myPath.AddLine(new Point(200, 10), new Point(200, 200));
myPath.CloseFigure();
-
+
// Draw the path to the screen.
e.Graphics.DrawPath(Pens.Black, myPath);
}
@@ -474,14 +471,14 @@ private void CloseFigureExample(PaintEventArgs e)
//
private void FlattenExample(PaintEventArgs e)
{
- GraphicsPath myPath = new GraphicsPath();
- Matrix translateMatrix = new Matrix();
+ GraphicsPath myPath = new();
+ Matrix translateMatrix = new();
translateMatrix.Translate(0, 10);
- Point point1 = new Point(20, 100);
- Point point2 = new Point(70, 10);
- Point point3 = new Point(130, 200);
- Point point4 = new Point(180, 100);
- Point[] points = {point1, point2, point3, point4};
+ Point point1 = new(20, 100);
+ Point point2 = new(70, 10);
+ Point point3 = new(130, 200);
+ Point point4 = new(180, 100);
+ Point[] points = [point1, point2, point3, point4];
myPath.AddCurve(points);
e.Graphics.DrawPath(new Pen(Color.Black, 2), myPath);
myPath.Flatten(translateMatrix, 10f);
@@ -493,17 +490,17 @@ private void FlattenExample(PaintEventArgs e)
//
public void GetBoundsExample(PaintEventArgs e)
{
-
+
// Create path number 1 and a Pen for drawing.
- GraphicsPath myPath = new GraphicsPath();
- Pen pathPen = new Pen(Color.Black, 1);
-
- // Add an Ellipse to the path and Draw it (circle in start
-
+ GraphicsPath myPath = new();
+ Pen pathPen = new(Color.Black, 1);
+
+ // Add an Ellipse to the path and Draw it (circle in start.
+
// position).
myPath.AddEllipse(20, 20, 100, 100);
e.Graphics.DrawPath(pathPen, myPath);
-
+
// Get the path bounds for Path number 1 and draw them.
RectangleF boundRect = myPath.GetBounds();
e.Graphics.DrawRectangle(new Pen(Color.Red, 1),
@@ -511,26 +508,26 @@ public void GetBoundsExample(PaintEventArgs e)
boundRect.Y,
boundRect.Height,
boundRect.Width);
-
+
// Create a second graphics path and a wider Pen.
- GraphicsPath myPath2 = new GraphicsPath();
- Pen pathPen2 = new Pen(Color.Black, 10);
-
+ GraphicsPath myPath2 = new();
+ Pen pathPen2 = new(Color.Black, 10);
+
// Create a new ellipse with a width of 10.
myPath2.AddEllipse(150, 20, 100, 100);
myPath2.Widen(pathPen2);
e.Graphics.FillPath(Brushes.Black, myPath2);
-
+
// Get the second path bounds.
RectangleF boundRect2 = myPath2.GetBounds();
-
+
// Draw the bounding rectangle.
e.Graphics.DrawRectangle(new Pen(Color.Red, 1),
boundRect2.X,
boundRect2.Y,
boundRect2.Height,
boundRect2.Width);
-
+
// Display the rectangle size.
MessageBox.Show(boundRect2.ToString());
}
@@ -540,7 +537,7 @@ public void GetBoundsExample(PaintEventArgs e)
//
private void GetLastPointExample(PaintEventArgs e)
{
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddLine(20, 20, 100, 20);
PointF lastPoint = myPath.GetLastPoint();
if(!lastPoint.IsEmpty)
@@ -560,10 +557,10 @@ private void GetLastPointExample(PaintEventArgs e)
//
public void IsOutlineVisibleExample(PaintEventArgs e)
{
- GraphicsPath myPath = new GraphicsPath();
- Rectangle rect = new Rectangle(20, 20, 100, 100);
+ GraphicsPath myPath = new();
+ Rectangle rect = new(20, 20, 100, 100);
myPath.AddRectangle(rect);
- Pen testPen = new Pen(Color.Black, 20);
+ Pen testPen = new(Color.Black, 20);
myPath.Widen(testPen);
e.Graphics.FillPath(Brushes.Black, myPath);
bool visible = myPath.IsOutlineVisible(100, 50, testPen,
@@ -576,14 +573,14 @@ public void IsOutlineVisibleExample(PaintEventArgs e)
//
private void IsVisibleExample(PaintEventArgs e)
{
-
+
// Create a path and add an ellipse.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddEllipse(0, 0, 100, 100);
-
+
// Test the visibility of point (50, 50).
bool visible = myPath.IsVisible(50, 50, e.Graphics);
-
+
// Show the result.
MessageBox.Show(visible.ToString());
}
@@ -593,45 +590,45 @@ private void IsVisibleExample(PaintEventArgs e)
//
public void GraphicsPathResetExample(PaintEventArgs e)
{
- Font myFont = new Font("Arial", 8);
-
+ Font myFont = new("Arial", 8);
+
// Create a path and add a line, an ellipse, and an arc.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddLine(new Point(0, 0), new Point(100, 100));
myPath.AddEllipse(100, 100, 200, 250);
myPath.AddArc(300, 250, 100, 100, 0, 90);
-
+
// Draw the pre-reset points array to the screen.
DrawPoints1(e, myPath.PathPoints, 20);
-
+
// Reset the path.
myPath.Reset();
-
+
// See if any points remain.
if(myPath.PointCount > 0)
{
-
+
// Draw the post-reset points array to the screen.
DrawPoints1(e, myPath.PathPoints, 150);
}
else
-
+
// If there are no points, say so.
e.Graphics.DrawString("No Points",
myFont,
Brushes.Black,
150,
20);
- }
- //End GraphicsPathResetExample
-
+ }
+ //End GraphicsPathResetExample.
+
// A helper function GraphicsPathResetExample uses to draw the points.
-
+
// to the screen.
public void DrawPoints1(PaintEventArgs e, PointF[] pathPoints, int xOffset)
{
int y = 20;
- Font myFont = new Font("Arial", 8);
+ Font myFont = new("Arial", 8);
for(int i=0;i < pathPoints.Length; i++)
{
e.Graphics.DrawString(pathPoints[i].X.ToString() + ", " +
@@ -642,39 +639,39 @@ public void DrawPoints1(PaintEventArgs e, PointF[] pathPoints, int xOffset)
y);
y += 20;
}
- }
- // End DrawPoints
+ }
+ // End DrawPoints.
//
// Snippet for: M:System.Drawing.Drawing2D.GraphicsPath.Reverse
//
public void GraphicsPathReverseExample(PaintEventArgs e)
{
-
+
// Create a path and add a line, ellipse, and arc.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddLine(new Point(0, 0), new Point(100, 100));
myPath.AddEllipse(100, 100, 200, 250);
myPath.AddArc(300, 250, 100, 100, 0, 90);
-
+
// Draw the first set of points to the screen.
DrawPoints2(e, myPath.PathPoints, 20);
-
+
// Call GraphicsPath.Reverse.
myPath.Reverse();
-
+
// Draw the reversed set of points to the screen.
DrawPoints2(e, myPath.PathPoints, 150);
}
//End GraphicsPathReverseExample.
-
- // A helper function GraphicsPathReverseExample is used to draw the
-
+
+ // A helper function GraphicsPathReverseExample is used to draw the.
+
// points to the screen.
public void DrawPoints2(PaintEventArgs e, PointF[] pathPoints, int xOffset)
{
int y = 20;
- Font myFont = new Font("Arial", 8);
+ Font myFont = new("Arial", 8);
for(int i=0;i < pathPoints.Length; i++)
{
e.Graphics.DrawString(pathPoints[i].X.ToString() + ", " +
@@ -685,24 +682,24 @@ public void DrawPoints2(PaintEventArgs e, PointF[] pathPoints, int xOffset)
y);
y += 20;
}
- }
- // End DrawPoints
+ }
+ // End DrawPoints.
//
// Snippet for: M:System.Drawing.Drawing2D.GraphicsPath.SetMarkers
//
private void SetMarkersExample(PaintEventArgs e)
{
-
+
// Create a path and set two markers.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddLine(new Point(0, 0), new Point(50, 50));
myPath.SetMarkers();
- Rectangle rect = new Rectangle(50, 50, 50, 50);
+ Rectangle rect = new(50, 50, 50, 50);
myPath.AddRectangle(rect);
myPath.SetMarkers();
myPath.AddEllipse(100, 100, 100, 50);
-
+
// Draw the path to screen.
e.Graphics.DrawPath(new Pen(Color.Black, 2), myPath);
}
@@ -712,10 +709,10 @@ private void SetMarkersExample(PaintEventArgs e)
//
public void StartFigureExample(PaintEventArgs e)
{
-
+
// Create a GraphicsPath object.
- GraphicsPath myPath = new GraphicsPath();
-
+ GraphicsPath myPath = new();
+
// First set of figures.
myPath.StartFigure();
myPath.AddArc(10, 10, 50, 50, 0, 270);
@@ -724,7 +721,7 @@ public void StartFigureExample(PaintEventArgs e)
myPath.CloseFigure();
myPath.StartFigure();
myPath.AddArc(100, 10, 50, 50, 0, 270);
-
+
// Second set of figures.
myPath.StartFigure();
myPath.AddArc(10, 200, 50, 50, 0, 270);
@@ -735,30 +732,30 @@ public void StartFigureExample(PaintEventArgs e)
myPath.CloseFigure();
myPath.StartFigure();
myPath.AddArc(100, 200, 50, 50, 0, 270);
-
+
// Draw the path to the screen.
e.Graphics.DrawPath(new Pen(Color.Black), myPath);
- }
- // End StartFigureExample
+ }
+ // End StartFigureExample.
//
// Snippet for: M:System.Drawing.Drawing2D.GraphicsPath.Transform(System.Drawing.Drawing2D.Matrix)
//
private void TransformExample(PaintEventArgs e)
{
-
+
// Create a path and add and ellipse.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddEllipse(0, 0, 100, 200);
-
+
// Draw the starting position to screen.
e.Graphics.DrawPath(Pens.Black, myPath);
-
+
// Move the ellipse 100 points to the right.
- Matrix translateMatrix = new Matrix();
+ Matrix translateMatrix = new();
translateMatrix.Translate(100, 0);
myPath.Transform(translateMatrix);
-
+
// Draw the transformed ellipse to the screen.
e.Graphics.DrawPath(new Pen(Color.Red, 2), myPath);
}
@@ -768,29 +765,29 @@ private void TransformExample(PaintEventArgs e)
//
private void WarpExample(PaintEventArgs e)
{
-
+
// Create a path and add a rectangle.
- GraphicsPath myPath = new GraphicsPath();
- RectangleF srcRect = new RectangleF(0, 0, 100, 200);
+ GraphicsPath myPath = new();
+ RectangleF srcRect = new(0, 0, 100, 200);
myPath.AddRectangle(srcRect);
-
+
// Draw the source path (rectangle)to the screen.
e.Graphics.DrawPath(Pens.Black, myPath);
-
+
// Create a destination for the warped rectangle.
- PointF point1 = new PointF(200, 200);
- PointF point2 = new PointF(400, 250);
- PointF point3 = new PointF(220, 400);
- PointF[] destPoints = {point1, point2, point3};
-
+ PointF point1 = new(200, 200);
+ PointF point2 = new(400, 250);
+ PointF point3 = new(220, 400);
+ PointF[] destPoints = [point1, point2, point3];
+
// Create a translation matrix.
- Matrix translateMatrix = new Matrix();
+ Matrix translateMatrix = new();
translateMatrix.Translate(100, 0);
-
+
// Warp the source path (rectangle).
myPath.Warp(destPoints, srcRect, translateMatrix,
WarpMode.Perspective, 0.5f);
-
+
// Draw the warped path (rectangle) to the screen.
e.Graphics.DrawPath(new Pen(Color.Red), myPath);
}
@@ -800,21 +797,21 @@ private void WarpExample(PaintEventArgs e)
//
private void WidenExample(PaintEventArgs e)
{
-
+
// Create a path and add two ellipses.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
myPath.AddEllipse(0, 0, 100, 100);
myPath.AddEllipse(100, 0, 100, 100);
-
+
// Draw the original ellipses to the screen in black.
e.Graphics.DrawPath(Pens.Black, myPath);
-
+
// Widen the path.
- Pen widenPen = new Pen(Color.Black, 10);
- Matrix widenMatrix = new Matrix();
+ Pen widenPen = new(Color.Black, 10);
+ Matrix widenMatrix = new();
widenMatrix.Translate(50, 50);
myPath.Widen(widenPen, widenMatrix, 1.0f);
-
+
// Draw the widened path to the screen in red.
e.Graphics.FillPath(new SolidBrush(Color.Red), myPath);
}
@@ -824,7 +821,7 @@ private void WidenExample(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.Drawing2D/GraphicsPathIterator/CopyData/form1.cs b/snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs
index 74ef1ba1202..7037f85dd02 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/GraphicsPathIterator/CopyData/form1.cs
@@ -1,150 +1,146 @@
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.Drawing2D.ClassicGraphicsPathIteratorCS
{
- ///
- /// 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
-
- ///
- /// The main entry point for the application.
- ///
- ///
+ ///
+ /// 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()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.Size = new System.Drawing.Size(300, 300);
+ this.Text = "Form1";
+ }
+ #endregion
+
+ ///
+ /// The main entry point for the application.
+ ///
+ ///
// Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.CopyData(System.Drawing.PointF[]@,System.Byte[]@,System.Int32,System.Int32)
//
public void CopyDataExample(PaintEventArgs e)
{
-
+
// Create a graphics path.
- GraphicsPath myPath = new GraphicsPath();
-
+ GraphicsPath myPath = new();
+
// Set up a points array.
Point[] myPoints =
- {
- new Point(20, 20),
- new Point(120, 120),
- new Point(20, 120),
- new Point(20, 20)
- };
-
+ [
+ new(20, 20),
+ new(120, 120),
+ new(20, 120),
+ new(20, 20)
+ ];
+
// Create a rectangle.
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
-
+ Rectangle myRect = new(120, 120, 100, 100);
+
// Add the points, rectangle, and an ellipse to the path.
myPath.AddLines(myPoints);
myPath.SetMarkers();
myPath.AddRectangle(myRect);
myPath.SetMarkers();
myPath.AddEllipse(220, 220, 100, 100);
-
+
// Get the total number of points for the path, and arrays of
// the points and types.
int myPathPointCount = myPath.PointCount;
PointF[] myPathPoints = myPath.PathPoints;
byte[] myPathTypes = myPath.PathTypes;
-
+
// Set up variables for listing the array of points on the left
// side of the screen.
int i;
float j = 20;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// List the set of points and types and types to the left side
// of the screen.
- for(i=0; i
@@ -164,32 +160,32 @@ public void CopyDataExample(PaintEventArgs e)
//
public void EnumerateExample(PaintEventArgs e)
{
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
Point[] myPoints =
- {
- new Point(20, 20),
- new Point(120, 120),
- new Point(20, 120),
- new Point(20, 20)
- };
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
+ [
+ new(20, 20),
+ new(120, 120),
+ new(20, 120),
+ new(20, 20)
+ ];
+ Rectangle myRect = new(120, 120, 100, 100);
myPath.AddLines(myPoints);
myPath.AddRectangle(myRect);
myPath.AddEllipse(220, 220, 100, 100);
-
+
// Get the total number of points for the path, and arrays of
// the points and types.
int myPathPointCount = myPath.PointCount;
PointF[] myPathPoints = myPath.PathPoints;
byte[] myPathTypes = myPath.PathTypes;
-
+
// Set up variables for listing the array of points on the left
// side of the screen.
int i;
float j = 20;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// List the set of points and types and types to the left side
// of the screen.
e.Graphics.DrawString("Original Data",
@@ -198,26 +194,26 @@ public void EnumerateExample(PaintEventArgs e)
20,
j);
j += 20;
- for(i=0; i
@@ -244,26 +240,25 @@ public void EnumerateExample(PaintEventArgs e)
//
private void HasCurveExample(PaintEventArgs e)
{
-
+
// Create a path and add three lines,
// a rectangle and an ellipse.
- GraphicsPath myPath = new GraphicsPath();
-
- Point[] myPoints = {new Point(20, 20), new Point(120, 120),
- new Point(20, 120),new Point(20, 20) };
+ GraphicsPath myPath = new();
+
+ Point[] myPoints = [new(20, 20), new(120, 120),
+ new(20, 120),new(20, 20) ];
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
+ Rectangle myRect = new(120, 120, 100, 100);
myPath.AddLines(myPoints);
myPath.AddRectangle(myRect);
myPath.AddEllipse(220, 220, 100, 100);
-
+
// Create a GraphicsPathIterator for myPath.
- GraphicsPathIterator myPathIterator = new
- GraphicsPathIterator(myPath);
-
+ GraphicsPathIterator myPathIterator = new(myPath);
+
// Test for a curve.
bool myHasCurve = myPathIterator.HasCurve();
-
+
// Show the test result.
MessageBox.Show(myHasCurve.ToString());
}
@@ -273,65 +268,63 @@ private void HasCurveExample(PaintEventArgs e)
//
public void NextMarkerExample2(PaintEventArgs e)
{
-
+
// Create a graphics path.
- GraphicsPath myPath = new GraphicsPath();
-
+ GraphicsPath myPath = new();
+
// Set up primitives to add to myPath.
- Point[] myPoints = {new Point(20, 20), new Point(120, 120),
- new Point(20, 120),new Point(20, 20) };
-
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
-
+ Point[] myPoints = [new(20, 20), new(120, 120),
+ new(20, 120),new(20, 20) ];
+
+ Rectangle myRect = new(120, 120, 100, 100);
+
// Add 3 lines, a rectangle, an ellipse, and 2 markers.
myPath.AddLines(myPoints);
myPath.SetMarkers();
myPath.AddRectangle(myRect);
myPath.SetMarkers();
myPath.AddEllipse(220, 220, 100, 100);
-
+
// Get the total number of points for the path,
// and the arrays of the points and types.
int myPathPointCount = myPath.PointCount;
PointF[] myPathPoints = myPath.PathPoints;
byte[] myPathTypes = myPath.PathTypes;
-
+
// Set up variables for listing all the values of the path's
// points to the screen.
int i;
float j = 20;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// List the values for all of path points and types to
// the left side of the screen.
- for(i=0; i < myPathPointCount; i++)
+ for (i = 0; i < myPathPointCount; i++)
{
- e.Graphics.DrawString(myPathPoints[i].X.ToString()+
+ e.Graphics.DrawString(myPathPoints[i].X.ToString() +
", " + myPathPoints[i].Y.ToString() + ", " +
- myPathTypes[i].ToString(), myFont, myBrush,
+ myPathTypes[i].ToString(), myFont, myBrush,
20, j);
-
- j+=20;
+
+ j += 20;
}
-
+
// Create a GraphicsPathIterator.
- GraphicsPathIterator myPathIterator = new
- GraphicsPathIterator(myPath);
-
+ GraphicsPathIterator myPathIterator = new(myPath);
+
// Rewind the iterator.
myPathIterator.Rewind();
-
+
// Create a GraphicsPath to receive a section of myPath.
- GraphicsPath myPathSection = new GraphicsPath();
-
+ GraphicsPath myPathSection = new();
+
// Retrieve and list the number of points contained in
-
// the first marker to the right side of the screen.
int markerPoints;
markerPoints = myPathIterator.NextMarker(myPathSection);
e.Graphics.DrawString("Marker: 1" + " Num Points: " +
- markerPoints.ToString(), myFont, myBrush, 200, 20);
+ markerPoints.ToString(), myFont, myBrush, 200, 20);
}
//
@@ -339,67 +332,63 @@ public void NextMarkerExample2(PaintEventArgs e)
//
private void NextMarkerExample(PaintEventArgs e)
{
-
// Create the GraphicsPath.
- GraphicsPath myPath = new GraphicsPath();
- Point[] myPoints = {new Point(20, 20), new Point(120, 120),
- new Point(20, 120),new Point(20, 20) };
+ GraphicsPath myPath = new();
+ Point[] myPoints = [new(20, 20), new(120, 120),
+ new(20, 120),new(20, 20) ];
+
+ Rectangle myRect = new(120, 120, 100, 100);
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
-
// Add 3 lines, a rectangle, an ellipse, and 2 markers.
myPath.AddLines(myPoints);
myPath.SetMarkers();
myPath.AddRectangle(myRect);
myPath.SetMarkers();
myPath.AddEllipse(220, 220, 100, 100);
-
+
// Get the total number of points for the path,
-
+
// and the arrays of the points and types.
int myPathPointCount = myPath.PointCount;
PointF[] myPathPoints = myPath.PathPoints;
byte[] myPathTypes = myPath.PathTypes;
-
+
// Set up variables for drawing the array
-
// of points to the screen.
int i;
float j = 20;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// Draw the set of path points and types to the screen.
- for(i=0; i
public void NextPathTypeExample(PaintEventArgs e)
{
-
// Create the GraphicsPath.
- GraphicsPath myPath = new GraphicsPath();
+ GraphicsPath myPath = new();
+
+ Point[] myPoints = [new(20, 20), new(120, 120),
+ new(20, 120),new(20, 20) ];
+ Rectangle myRect = new(120, 120, 100, 100);
- Point[] myPoints = {new Point(20, 20), new Point(120, 120),
- new Point(20, 120),new Point(20, 20) };
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
-
// Add 3 lines, a rectangle, and an ellipse.
myPath.AddLines(myPoints);
myPath.AddRectangle(myRect);
myPath.AddEllipse(220, 220, 100, 100);
-
+
// List all of the path points to the screen.
ListPathPoints(e, myPath, null, 20, 1);
-
+
// Create a GraphicsPathIterator.
- GraphicsPathIterator myPathIterator = new
- GraphicsPathIterator(myPath);
-
+ GraphicsPathIterator myPathIterator = new(myPath);
+
// Rewind the Iterator.
myPathIterator.Rewind();
-
- // Iterate the subpaths and types, and list the results to
-
- // the screen.
+
+ // Iterate the subpaths and types,
+ // and list the results.
int i, j = 20;
int mySubPaths, subPathStartIndex, subPathEndIndex;
- Boolean IsClosed;
+ bool isClosed;
byte subPathPointType;
- int pointTypeStartIndex, pointTypeEndIndex, numPointsFound;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
+ int pointTypeStartIndex, pointTypeEndIndex, numPointsFound;
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
j = 20;
- for(i = 0;i < 3; i++)
+
+ for (i = 0; i < 3; i++)
{
mySubPaths = myPathIterator.NextSubpath(
out subPathStartIndex,
out subPathEndIndex,
- out IsClosed);
+ out isClosed);
numPointsFound = myPathIterator.NextPathType(
out subPathPointType,
out pointTypeStartIndex,
@@ -476,13 +463,13 @@ public void NextPathTypeExample(PaintEventArgs e)
myBrush,
200,
j);
- j+=20;
+ j += 20;
}
-
+
// List the total number of path points to the screen.
ListPathPoints(e, myPath, myPathIterator, 200, 2);
}
-
+
//-------------------------------------------------------
//This function is a helper function used by
// NextPathTypeExample.
@@ -494,39 +481,36 @@ public void ListPathPoints(
int xOffset,
int listType)
{
-
// Get the total number of points for the path,
// and the arrays of the points and types.
int myPathPointCount = myPath.PointCount;
PointF[] myPathPoints = myPath.PathPoints;
byte[] myPathTypes = myPath.PathTypes;
-
+
// Set up variables for drawing the points to the screen.
int i;
float j = 20;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
- if (listType == 1)
- // List all the path points to the screen.
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+ if (listType == 1)
+ // List all the path points to the screen.
{
-
// Draw the set of path points and types to the screen.
- for(i=0; i
// Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextSubpath(System.Int32@,System.Int32@,System.Boolean@)
//
private void NextSubpathExample(PaintEventArgs e)
{
-
// Create the GraphicsPath.
- GraphicsPath myPath = new GraphicsPath();
- Point[] myPoints = {new Point(20, 20), new Point(120, 120),
- new Point(20, 120),new Point(20, 20) };
- Rectangle myRect = new Rectangle(120, 120, 100, 100);
-
+ GraphicsPath myPath = new();
+ Point[] myPoints = [new(20, 20), new(120, 120),
+ new(20, 120),new(20, 20) ];
+ Rectangle myRect = new(120, 120, 100, 100);
+
// Add 3 lines, a rectangle, an ellipse, and 2 markers.
myPath.AddLines(myPoints);
myPath.AddRectangle(myRect);
myPath.AddEllipse(220, 220, 100, 100);
-
+
// Get the total number of points for the path,
-
// and the arrays of the points and types.
int myPathPointCount = myPath.PointCount;
PointF[] myPathPoints = myPath.PathPoints;
byte[] myPathTypes = myPath.PathTypes;
-
+
// Set up variables for drawing the array of
-
// points to the screen.
int i;
float j = 20;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// Draw the set of path points and types to the screen.
- for(i=0; i < myPathPointCount; i++)
+ for (i = 0; i < myPathPointCount; i++)
{
- e.Graphics.DrawString(myPathPoints[i].X.ToString()+
+ e.Graphics.DrawString(myPathPoints[i].X.ToString() +
", " + myPathPoints[i].Y.ToString() + ", " +
myPathTypes[i].ToString(),
myFont,
myBrush,
20,
j);
- j+=20;
+ j += 20;
}
-
+
// Create a GraphicsPathIterator.
- GraphicsPathIterator myPathIterator = new
- GraphicsPathIterator(myPath);
+ GraphicsPathIterator myPathIterator = new(myPath);
int myStartIndex;
int myEndIndex;
bool myIsClosed;
-
+
// get the number of Subpaths.
int numSubpaths = myPathIterator.NextSubpath(myPath,
out myIsClosed);
numSubpaths -= 1;
-
+
// Rewind the Iterator.
myPathIterator.Rewind();
-
+
// List the Subpaths to the screen.
- j=20;
- for(i=0;i
}
// 6d407891-6e5c-4495-a546-3da5604e9fb8
- // How to: Tile a Shape with an Image
+ // How to: Tile a Shape with an Image.
public void Method31(PaintEventArgs e)
{
//
Image image = new Bitmap("HouseAndTree.gif");
- TextureBrush tBrush = new TextureBrush(image);
- Pen blackPen = new Pen(Color.Black);
+ TextureBrush tBrush = new(image);
+ Pen blackPen = new(Color.Black);
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
//
@@ -55,8 +57,8 @@ public void Method32(PaintEventArgs e)
{
//
Image image = new Bitmap("HouseAndTree.gif");
- TextureBrush tBrush = new TextureBrush(image);
- Pen blackPen = new Pen(Color.Black);
+ TextureBrush tBrush = new(image);
+ Pen blackPen = new(Color.Black);
tBrush.WrapMode = WrapMode.TileFlipX;
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
@@ -66,8 +68,8 @@ public void Method33(PaintEventArgs e)
{
//
Image image = new Bitmap("HouseAndTree.gif");
- TextureBrush tBrush = new TextureBrush(image);
- Pen blackPen = new Pen(Color.Black);
+ TextureBrush tBrush = new(image);
+ Pen blackPen = new(Color.Black);
tBrush.WrapMode = WrapMode.TileFlipY;
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
@@ -77,20 +79,20 @@ public void Method34(PaintEventArgs e)
{
//
Image image = new Bitmap("HouseAndTree.gif");
- TextureBrush tBrush = new TextureBrush(image);
- Pen blackPen = new Pen(Color.Black);
+ TextureBrush tBrush = new(image);
+ Pen blackPen = new(Color.Black);
tBrush.WrapMode = WrapMode.TileFlipXY;
e.Graphics.FillRectangle(tBrush, new Rectangle(0, 0, 200, 200));
e.Graphics.DrawRectangle(blackPen, new Rectangle(0, 0, 200, 200));
//
}
// 9c8300ff-187b-404f-af1f-ebd499f5b16f
- // How to: Fill a Shape with a Hatch Pattern
+ // How to: Fill a Shape with a Hatch Pattern.
public void Method41(PaintEventArgs e)
{
//
- HatchBrush hBrush = new HatchBrush(
+ HatchBrush hBrush = new(
HatchStyle.Horizontal,
Color.Red,
Color.FromArgb(255, 128, 255, 255));
diff --git a/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Clone/form1.cs b/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Clone/form1.cs
index 61b2c72a55c..68d5cb2e528 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Clone/form1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Clone/form1.cs
@@ -1,86 +1,83 @@
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.Drawing2D.ClassicLinearGradientBrushCS
{
- ///
- /// 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()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.Size = new System.Drawing.Size(300, 300);
+ this.Text = "Form1";
+ }
+ #endregion
// Snippet for: M:System.Drawing.Drawing2D.LinearGradientBrush.Clone
//
private void CloneExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- int x=20, y=20, h=100, w=200;
- Rectangle myRect = new Rectangle(x, y, w, h);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
+ int x = 20, y = 20, h = 100, w = 200;
+ Rectangle myRect = new(x, y, w, h);
+ LinearGradientBrush myLGBrush = new(
myRect, Color.Blue, Color.Aquamarine, 45.0f, true);
-
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, x, y, w, h);
-
+
// Clone the LinearGradientBrush.
LinearGradientBrush clonedLGBrush =
(LinearGradientBrush)myLGBrush.Clone();
-
+
// Justify the left edge of the gradient with the
// left edge of the ellipse.
clonedLGBrush.TranslateTransform(-100.0f, 0.0f);
-
+
// Draw a second ellipse to the screen using the cloned HBrush.
- y=150;
+ y = 150;
e.Graphics.FillEllipse(clonedLGBrush, x, y, w, h);
}
//
@@ -89,24 +86,24 @@ private void CloneExample(PaintEventArgs e)
//
private void MultiplyTransformExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, myRect);
-
+
// Transform the LinearGradientBrush.
- Point[] transformArray = { new Point(20, 150),
- new Point(400,150), new Point(20, 200) };
-
- Matrix myMatrix = new Matrix(myRect, transformArray);
+ Point[] transformArray = [ new Point(20, 150),
+ new Point(400,150), new Point(20, 200) ];
+
+ Matrix myMatrix = new(myRect, transformArray);
myLGBrush.MultiplyTransform(
myMatrix,
MatrixOrder.Prepend);
-
+
// Draw a second ellipse to the screen using
// the transformed brush.
e.Graphics.FillEllipse(myLGBrush, 20, 150, 380, 50);
@@ -117,29 +114,29 @@ private void MultiplyTransformExample(PaintEventArgs e)
//
private void ResetTransformExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, myRect);
-
+
// Transform the LinearGradientBrush.
- Point[] transformArray = { new Point(20, 150),
- new Point(400,150), new Point(20, 200) };
-
- Matrix myMatrix = new Matrix(myRect, transformArray);
- myLGBrush.MultiplyTransform( myMatrix, MatrixOrder.Prepend);
-
+ Point[] transformArray = [ new Point(20, 150),
+ new Point(400,150), new Point(20, 200) ];
+
+ Matrix myMatrix = new(myRect, transformArray);
+ myLGBrush.MultiplyTransform(myMatrix, MatrixOrder.Prepend);
+
// Draw a second ellipse to the screen
// using the transformed brush.
e.Graphics.FillEllipse(myLGBrush, 20, 150, 380, 50);
-
+
// Reset the brush transform.
myLGBrush.ResetTransform();
-
+
// Draw a third ellipse to the screen using the reset brush.
e.Graphics.FillEllipse(myLGBrush, 20, 250, 200, 100);
}
@@ -149,21 +146,21 @@ private void ResetTransformExample(PaintEventArgs e)
//
private void RotateTransformExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, myRect);
-
+
// Rotate the LinearGradientBrush.
myLGBrush.RotateTransform(45.0f, MatrixOrder.Prepend);
-
+
// Rejustify the brush to start at the left edge of the ellipse.
myLGBrush.TranslateTransform(-100.0f, 0.0f);
-
+
// Draw a second ellipse to the screen using
// the transformed brush.
e.Graphics.FillEllipse(myLGBrush, 20, 150, 200, 100);
@@ -174,21 +171,21 @@ private void RotateTransformExample(PaintEventArgs e)
//
private void ScaleTransformExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, myRect);
-
+
// Scale the LinearGradientBrush.
myLGBrush.ScaleTransform(2.0f, 1.0f, MatrixOrder.Prepend);
-
+
// Rejustify the brush to start at the left edge of the ellipse.
myLGBrush.TranslateTransform(-20.0f, 0.0f);
-
+
// Draw a second ellipse to the screen using
// the transformed brush.
e.Graphics.FillEllipse(myLGBrush, 20, 150, 200, 100);
@@ -199,19 +196,19 @@ private void ScaleTransformExample(PaintEventArgs e)
//
private void SetBlendTriangularShapeExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, myRect);
-
+
// Create a triangular shaped brush with the peak at the center
// of the drawing area.
myLGBrush.SetBlendTriangularShape(.5f, 1.0f);
-
+
// Use the triangular brush to draw a second ellipse.
myRect.Y = 150;
e.Graphics.FillEllipse(myLGBrush, myRect);
@@ -222,22 +219,19 @@ private void SetBlendTriangularShapeExample(PaintEventArgs e)
//
private void SetSigmaBellShapeExample(PaintEventArgs e)
{
-
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw an ellipse to the screen using the LinearGradientBrush.
e.Graphics.FillEllipse(myLGBrush, myRect);
-
+
// Create a bell-shaped brush with the peak at the
-
// center of the drawing area.
myLGBrush.SetSigmaBellShape(.5f, 1.0f);
-
- // Use the bell- shaped brush to draw a second
- // ellipse.
+
+ // Use the bell-shaped brush to draw a second ellipse.
myRect.Y = 150;
e.Graphics.FillEllipse(myLGBrush, myRect);
}
@@ -247,41 +241,41 @@ private void SetSigmaBellShapeExample(PaintEventArgs e)
//
private void TranslateTransformExample(PaintEventArgs e)
{
-
+
// Create a LinearGradientBrush.
- Rectangle myRect = new Rectangle(20, 20, 200, 100);
- LinearGradientBrush myLGBrush = new LinearGradientBrush(
- myRect, Color.Blue, Color.Red, 0.0f, true);
-
+ Rectangle myRect = new(20, 20, 200, 100);
+ LinearGradientBrush myLGBrush = new(
+ myRect, Color.Blue, Color.Red, 0.0f, true);
+
// Draw a rectangle to the screen using the LinearGradientBrush.
e.Graphics.FillRectangle(myLGBrush, myRect);
-
+
// Rotate the LinearGradientBrush.
myLGBrush.RotateTransform(90.0f);
-
+
// Scale the gradient for the height of the rectangle.
myLGBrush.ScaleTransform(0.5f, 1.0f);
-
+
// Draw to the screen, the rotated and scaled gradient.
e.Graphics.FillRectangle(myLGBrush, 20, 150, 200, 100);
-
+
// Rejustify the brush to start at the top edge of the
// rectangle.
myLGBrush.TranslateTransform(-20.0f, 0.0f);
-
- // Draw a third rectangle to the screen using the translated
- // brush.
+
+ // Draw a third rectangle to the screen
+ // using the translated brush.
e.Graphics.FillRectangle(myLGBrush, 20, 300, 200, 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.Drawing2D/LinearGradientBrush/Overview/Class1.cs b/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Overview/Class1.cs
index ef381b75775..bfaa60711a6 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Overview/Class1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/LinearGradientBrush/Overview/Class1.cs
@@ -1,32 +1,29 @@
using System;
-using System.Windows.Forms;
-using System.Drawing;
using System.Collections;
-using System.Xml;
+using System.Drawing;
using System.Drawing.Drawing2D;
+using System.Windows.Forms;
+using System.Xml;
public class class1
{
-
- // 1948e834-e104-481c-b71d-d8aa9e4d106e
- // How to: Create a Path Gradient
-
//
public void FillEllipseWithPathGradient(PaintEventArgs e)
{
// Create a path that consists of a single ellipse.
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.AddEllipse(0, 0, 140, 70);
// Use the path to construct a brush.
- PathGradientBrush pthGrBrush = new PathGradientBrush(path);
+ PathGradientBrush pthGrBrush = new(path)
+ {
+ // Set the color at the center of the path to blue.
+ CenterColor = Color.FromArgb(255, 0, 0, 255)
+ };
- // Set the color at the center of the path to blue.
- pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);
-
- // Set the color along the entire boundary
+ // Set the color along the entire boundary
// of the path to aqua.
- Color[] colors = { Color.FromArgb(255, 0, 255, 255) };
+ Color[] colors = [Color.FromArgb(255, 0, 255, 255)];
pthGrBrush.SurroundColors = colors;
e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
@@ -37,40 +34,41 @@ public void FillEllipseWithPathGradient(PaintEventArgs e)
public void ConstructBrushFromStarShapedPath(PaintEventArgs e)
{
// Put the points of a polygon in an array.
- Point[] points = {
- new Point(75, 0),
- new Point(100, 50),
- new Point(150, 50),
- new Point(112, 75),
- new Point(150, 150),
- new Point(75, 100),
- new Point(0, 150),
- new Point(37, 75),
- new Point(0, 50),
- new Point(50, 50)};
+ Point[] points = [
+ new(75, 0),
+ new(100, 50),
+ new(150, 50),
+ new(112, 75),
+ new(150, 150),
+ new(75, 100),
+ new(0, 150),
+ new(37, 75),
+ new(0, 50),
+ new(50, 50)];
// Use the array of points to construct a path.
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.AddLines(points);
// Use the path to construct a path gradient brush.
- PathGradientBrush pthGrBrush = new PathGradientBrush(path);
-
- // Set the color at the center of the path to red.
- pthGrBrush.CenterColor = Color.FromArgb(255, 255, 0, 0);
+ PathGradientBrush pthGrBrush = new(path)
+ {
+ // Set the color at the center of the path to red.
+ CenterColor = Color.FromArgb(255, 255, 0, 0)
+ };
// Set the colors of the points in the array.
- Color[] colors = {
+ Color[] colors = [
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
- Color.FromArgb(255, 0, 0, 255),
+ Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 255, 255, 255),
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 255, 255, 255),
- Color.FromArgb(255, 0, 0, 0),
- Color.FromArgb(255, 0, 255, 0)};
+ Color.FromArgb(255, 0, 0, 0),
+ Color.FromArgb(255, 0, 255, 0)];
pthGrBrush.SurroundColors = colors;
@@ -83,23 +81,23 @@ public void ConstructBrushFromStarShapedPath(PaintEventArgs e)
public void DrawPathGradentWthoutGraphicsPath(PaintEventArgs e)
{
// Construct a path gradient brush based on an array of points.
- PointF[] ptsF = {
- new PointF(0, 0),
- new PointF(160, 0),
- new PointF(160, 200),
- new PointF(80, 150),
- new PointF(0, 200)};
-
- PathGradientBrush pBrush = new PathGradientBrush(ptsF);
-
- // An array of five points was used to construct the path gradient
- // brush. Set the color of each point in that array.
- Color[] colors = {
- Color.FromArgb(255, 255, 0, 0), // (0, 0) red
- Color.FromArgb(255, 0, 255, 0), // (160, 0) green
- Color.FromArgb(255, 0, 255, 0), // (160, 200) green
- Color.FromArgb(255, 0, 0, 255), // (80, 150) blue
- Color.FromArgb(255, 255, 0, 0)}; // (0, 200) red
+ PointF[] ptsF = [
+ new(0, 0),
+ new(160, 0),
+ new(160, 200),
+ new(80, 150),
+ new(0, 200)];
+
+ PathGradientBrush pBrush = new(ptsF);
+
+ // An array of five points was used to construct the path gradient brush.
+ // Set the color of each point in that array.
+ Color[] colors = [
+ Color.FromArgb(255, 255, 0, 0), // (0, 0) red.
+ Color.FromArgb(255, 0, 255, 0), // (160, 0) green.
+ Color.FromArgb(255, 0, 255, 0), // (160, 200) green.
+ Color.FromArgb(255, 0, 0, 255), // (80, 150) blue.
+ Color.FromArgb(255, 255, 0, 0)]; // (0, 200) red.
pBrush.SurroundColors = colors;
@@ -115,20 +113,20 @@ public void DrawPathGradentWthoutGraphicsPath(PaintEventArgs e)
public void CustomizePathGradientBrush(PaintEventArgs e)
{
// Create a path that consists of a single ellipse.
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.AddEllipse(0, 0, 200, 100);
// Create a path gradient brush based on the elliptical path.
- PathGradientBrush pthGrBrush = new PathGradientBrush(path);
+ PathGradientBrush pthGrBrush = new(path);
// Set the color along the entire boundary to blue.
- Color[] color = { Color.Blue };
+ Color[] color = [Color.Blue];
pthGrBrush.SurroundColors = color;
// Set the center color to aqua.
pthGrBrush.CenterColor = Color.Aqua;
- // Use the path gradient brush to fill the ellipse.
+ // Use the path gradient brush to fill the ellipse.
e.Graphics.FillPath(pthGrBrush, path);
// Set the focus scales for the path gradient brush.
@@ -144,30 +142,31 @@ public void CustomizePathGradientBrush(PaintEventArgs e)
//
public void CustomizeWithInterpolation(PaintEventArgs e)
{
- // Vertices of the outer triangle
- Point[] points = {
- new Point(100, 0),
- new Point(200, 200),
- new Point(0, 200)};
+ // Vertices of the outer triangle.
+ Point[] points = [
+ new(100, 0),
+ new(200, 200),
+ new(0, 200)];
// No GraphicsPath object is created. The PathGradientBrush
// object is constructed directly from the array of points.
- PathGradientBrush pthGrBrush = new PathGradientBrush(points);
+ PathGradientBrush pthGrBrush = new(points);
- Color[] colors = {
- Color.FromArgb(255, 0, 128, 0), // dark green
- Color.FromArgb(255, 0, 255, 255), // aqua
- Color.FromArgb(255, 0, 0, 255)}; // blue
+ Color[] colors = [
+ Color.FromArgb(255, 0, 128, 0), // dark green.
+ Color.FromArgb(255, 0, 255, 255), // aqua.
+ Color.FromArgb(255, 0, 0, 255)]; // blue.
- float[] relativePositions = {
+ float[] relativePositions = [
0f, // Dark green is at the boundary of the triangle.
- 0.4f, // Aqua is 40 percent of the way from the boundary
- // to the center point.
- 1.0f}; // Blue is at the center point.
-
- ColorBlend colorBlend = new ColorBlend();
- colorBlend.Colors = colors;
- colorBlend.Positions = relativePositions;
+ 0.4f, // Aqua is 40 percent of the way from the boundary to the center point.
+ 1.0f]; // Blue is at the center point.
+
+ ColorBlend colorBlend = new()
+ {
+ Colors = colors,
+ Positions = relativePositions
+ };
pthGrBrush.InterpolationColors = colorBlend;
// Fill a rectangle that is larger than the triangle
@@ -181,48 +180,50 @@ public void CustomizeWithInterpolation(PaintEventArgs e)
public void SetCenterPoint(PaintEventArgs e)
{
// Create a path that consists of a single ellipse.
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.AddEllipse(0, 0, 140, 70);
// Use the path to construct a brush.
- PathGradientBrush pthGrBrush = new PathGradientBrush(path);
-
- // Set the center point to a location that is not
- // the centroid of the path.
- pthGrBrush.CenterPoint = new PointF(120, 40);
+ PathGradientBrush pthGrBrush = new(path)
+ {
+ // Set the center point to a location that is not
+ // the centroid of the path.
+ CenterPoint = new PointF(120, 40),
- // Set the color at the center of the path to blue.
- pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);
+ // Set the color at the center of the path to blue.
+ CenterColor = Color.FromArgb(255, 0, 0, 255)
+ };
- // Set the color along the entire boundary
+ // Set the color along the entire boundary
// of the path to aqua.
- Color[] colors = { Color.FromArgb(255, 0, 255, 255) };
+ Color[] colors = [Color.FromArgb(255, 0, 255, 255)];
pthGrBrush.SurroundColors = colors;
e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
}
//
-
+
//
public void SetCenterPointOutsidePath(PaintEventArgs e)
{
// Create a path that consists of a single ellipse.
- GraphicsPath path = new GraphicsPath();
+ GraphicsPath path = new();
path.AddEllipse(0, 0, 140, 70);
// Use the path to construct a brush.
- PathGradientBrush pthGrBrush = new PathGradientBrush(path);
-
- // Set the center point to a location that is not
- // the centroid of the path.
- pthGrBrush.CenterPoint = new PointF(145, 35);
+ PathGradientBrush pthGrBrush = new(path)
+ {
+ // Set the center point to a location that is not
+ // the centroid of the path.
+ CenterPoint = new PointF(145, 35),
- // Set the color at the center of the path to blue.
- pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);
+ // Set the color at the center of the path to blue.
+ CenterColor = Color.FromArgb(255, 0, 0, 255)
+ };
- // Set the color along the entire boundary
+ // Set the color along the entire boundary
// of the path to aqua.
- Color[] colors = { Color.FromArgb(255, 0, 255, 255) };
+ Color[] colors = [Color.FromArgb(255, 0, 255, 255)];
pthGrBrush.SurroundColors = colors;
e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);
@@ -230,18 +231,18 @@ public void SetCenterPointOutsidePath(PaintEventArgs e)
//
// 6c88e1cc-1217-4399-ac12-cb37592b9f01
- // How to: Create a Linear Gradient
+ // How to: Create a Linear Gradient.
//
public void UseHorizontalLinearGradients(PaintEventArgs e)
{
- LinearGradientBrush linGrBrush = new LinearGradientBrush(
+ LinearGradientBrush linGrBrush = new(
new Point(0, 10),
new Point(200, 10),
- Color.FromArgb(255, 255, 0, 0), // Opaque red
- Color.FromArgb(255, 0, 0, 255)); // Opaque blue
+ Color.FromArgb(255, 255, 0, 0), // Opaque red.
+ Color.FromArgb(255, 0, 0, 255)); // Opaque blue.
- Pen pen = new Pen(linGrBrush);
+ Pen pen = new(linGrBrush);
e.Graphics.DrawLine(pen, 0, 10, 200, 10);
e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);
@@ -252,19 +253,21 @@ public void UseHorizontalLinearGradients(PaintEventArgs e)
//
public void CustomizeLinearGradients(PaintEventArgs e)
{
- LinearGradientBrush linGrBrush = new LinearGradientBrush(
+ LinearGradientBrush linGrBrush = new(
new Point(0, 10),
new Point(200, 10),
- Color.FromArgb(255, 0, 0, 0), // Opaque black
- Color.FromArgb(255, 255, 0, 0)); // Opaque red
+ Color.FromArgb(255, 0, 0, 0), // Opaque black.
+ Color.FromArgb(255, 255, 0, 0)); // Opaque red.
- float[] relativeIntensities = { 0.0f, 0.5f, 1.0f };
- float[] relativePositions = { 0.0f, 0.2f, 1.0f };
+ float[] relativeIntensities = [0.0f, 0.5f, 1.0f];
+ float[] relativePositions = [0.0f, 0.2f, 1.0f];
//Create a Blend object and assign it to linGrBrush.
- Blend blend = new Blend();
- blend.Factors = relativeIntensities;
- blend.Positions = relativePositions;
+ Blend blend = new()
+ {
+ Factors = relativeIntensities,
+ Positions = relativePositions
+ };
linGrBrush.Blend = blend;
e.Graphics.FillEllipse(linGrBrush, 0, 30, 200, 100);
@@ -275,13 +278,13 @@ public void CustomizeLinearGradients(PaintEventArgs e)
//
public void CreateDiagonalLinearGradients(PaintEventArgs e)
{
- LinearGradientBrush linGrBrush = new LinearGradientBrush(
+ LinearGradientBrush linGrBrush = new(
new Point(0, 0),
new Point(200, 100),
- Color.FromArgb(255, 0, 0, 255), // opaque blue
- Color.FromArgb(255, 0, 255, 0)); // opaque green
+ Color.FromArgb(255, 0, 0, 255), // opaque blue.
+ Color.FromArgb(255, 0, 255, 0)); // opaque green.
- Pen pen = new Pen(linGrBrush, 10);
+ Pen pen = new(linGrBrush, 10);
e.Graphics.DrawLine(pen, 0, 0, 600, 300);
e.Graphics.FillEllipse(linGrBrush, 10, 100, 200, 100);
@@ -289,12 +292,12 @@ public void CreateDiagonalLinearGradients(PaintEventArgs e)
//
// da4690e7-5fac-4fd2-b3f0-5cb35c165b92
- // How to: Apply Gamma Correction to a Gradient
+ // How to: Apply Gamma Correction to a Gradient.
//
public void FillTwoRectangles(PaintEventArgs e)
{
- LinearGradientBrush linGrBrush = new LinearGradientBrush(
+ LinearGradientBrush linGrBrush = new(
new Point(0, 10),
new Point(200, 10),
Color.Red,
diff --git a/snippets/csharp/System.Drawing.Drawing2D/Matrix/Multiply/form1.cs b/snippets/csharp/System.Drawing.Drawing2D/Matrix/Multiply/form1.cs
index 5f3b62dbe45..79142da8d58 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/Matrix/Multiply/form1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/Matrix/Multiply/form1.cs
@@ -1,9 +1,9 @@
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.Drawing2D.ClassicMatrixExamplesCS
{
@@ -20,12 +20,12 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
//
- // TODO: Add any constructor code after InitializeComponent call
+ // TODO: Add any constructor code after InitializeComponent call.
//
}
@@ -36,10 +36,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if (components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -61,38 +58,37 @@ private void InitializeComponent()
//
public void MultiplyExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Set up the matrices.
- Matrix myMatrix1 = new Matrix(
- 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
-
- Matrix myMatrix2 = new Matrix(
- 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f);
-
- Matrix myMatrix3 = new Matrix(
- 1.0f, 0.0f, 0.0f, 1.0f, 250.0f, 50.0f);
+ Matrix myMatrix1 = new(
+ 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
+
+ Matrix myMatrix2 = new(
+ 0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f);
+
+ Matrix myMatrix3 = new(
+ 1.0f, 0.0f, 0.0f, 1.0f, 250.0f, 50.0f);
// Display the elements of the starting matrix.
ListMatrixElements(e, myMatrix1, "Beginning Matrix", 6, 40);
-
+
// Multiply Matrix1 by Matrix 2.
myMatrix1.Multiply(myMatrix2, MatrixOrder.Append);
-
+
// Display the result of the multiplication of Matrix1 and
-
// Matrix2.
ListMatrixElements(e,
myMatrix1,
"Matrix After 1st Multiplication",
6,
60);
-
+
// Multiply the result from the pervious multiplication by
// Matrix3.
myMatrix1.Multiply(myMatrix3, MatrixOrder.Append);
-
+
// Display the result of the previous multiplication
// multiplied by Matrix3.
ListMatrixElements1(e,
@@ -100,21 +96,21 @@ public void MultiplyExample(PaintEventArgs e)
"Matrix After 2nd Multiplication",
6,
80);
-
+
// Draw the rectangle prior to transformation.
e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100);
-
+
// Make the transformation.
e.Graphics.Transform = myMatrix1;
-
+
// Draw the rectangle after transformation.
e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100);
}
-
+
//-------------------------------------------------------
// The following function is a helper function to
// list the contents of a matrix.
- //-------------------------------------------------------
+ //-------------------------------------------------------.
public void ListMatrixElements1(
PaintEventArgs e,
Matrix matrix,
@@ -122,14 +118,14 @@ public void ListMatrixElements1(
int numElements,
int y)
{
-
+
// Set up variables for drawing the array
// of points to the screen.
int i;
float x = 20, X = 200;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// Draw the matrix name to the screen.
e.Graphics.DrawString(
matrixName + ": ",
@@ -137,7 +133,7 @@ public void ListMatrixElements1(
myBrush,
x,
y);
-
+
// Draw the set of path points and types to the screen.
for(i=0; i
public void ResetExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Create a matrix that scales by 5 in the x direction and
// by 3 in the y direction.
- Matrix myMatrix = new Matrix(
- 5.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f);
-
+ Matrix myMatrix = new(
+ 5.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f);
+
// List the matrix elements to the screen.
ListMatrixElements(e, myMatrix, "Beginning Matrix", 6, 20);
-
+
// Reset the matrix to identity.
myMatrix.Reset();
-
+
// Again list the matrix elements to the screen.
ListMatrixElements2(e, myMatrix, "Matrix After Reset", 6, 40);
-
+
// Translate the matrix by 50 points in the x-axis and 40 points
// in the y-axis.
- myMatrix.Translate(50.0f, 40.0f);
-
+ myMatrix.Translate(50.0f, 40.0f);
+
// List the matrix elements to the screen.
ListMatrixElements1(e, myMatrix, "Matrix After Translation", 6, 60);
-
+
// Draw a rectangle to the screen.
e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100);
-
+
// Apply the matrix transform to the Graphics.
e.Graphics.Transform = myMatrix;
-
- // Draw another rectangle to the screen that has the transform
- // applied.
+
+ // Draw another rectangle to the screen that has the transform applied.
e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100);
}
-
+
//-------------------------------------------------------
// This function is a helper function to
// list the contents of a matrix.
- //-------------------------------------------------------
+ //-------------------------------------------------------.
public void ListMatrixElements2(
PaintEventArgs e,
Matrix matrix,
@@ -202,14 +197,14 @@ public void ListMatrixElements2(
int numElements,
int y)
{
-
+
// Set up variables for drawing the array
// of points to the screen.
int i;
float x = 20, X = 200;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// Draw the matrix name to the screen.
e.Graphics.DrawString(
matrixName + ": ",
@@ -217,7 +212,7 @@ public void ListMatrixElements2(
myBrush,
x,
y);
-
+
// Draw the set of path points and types to the screen.
for(i=0; i < numElements; i++)
{
@@ -236,19 +231,17 @@ public void ListMatrixElements2(
//
public void RotateExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Draw the rectangle to the screen before applying the transform.
e.Graphics.DrawRectangle(myPen, 150, 50, 200, 100);
-
+
// Create a matrix and rotate it 45 degrees.
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Rotate(45, MatrixOrder.Append);
-
- // Draw the rectangle to the screen again after applying the
-
- // transform.
+
+ // Draw the rectangle to the screen again after applying the transform.
e.Graphics.Transform = myMatrix;
e.Graphics.DrawRectangle(myPen2, 150, 50, 200, 100);
}
@@ -258,18 +251,18 @@ public void RotateExample(PaintEventArgs e)
//
public void RotateAtExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
- PointF rotatePoint = new PointF(150.0f, 50.0f);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+ PointF rotatePoint = new(150.0f, 50.0f);
+
// Draw the rectangle to the screen before applying the
// transform.
e.Graphics.DrawRectangle(myPen, 150, 50, 200, 100);
-
+
// Create a matrix and rotate it 45 degrees.
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.RotateAt(45, rotatePoint, MatrixOrder.Append);
-
+
// Draw the rectangle to the screen again after applying the
// transform.
e.Graphics.Transform = myMatrix;
@@ -281,17 +274,17 @@ public void RotateAtExample(PaintEventArgs e)
//
public void ScaleExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Draw the rectangle to the screen before applying the
// transform.
e.Graphics.DrawRectangle(myPen, 50, 50, 100, 100);
-
+
// Create a matrix and scale it.
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Scale(3, 2, MatrixOrder.Append);
-
+
// Draw the rectangle to the screen again after applying the
// transform.
e.Graphics.Transform = myMatrix;
@@ -303,7 +296,7 @@ public void ScaleExample(PaintEventArgs e)
//
public void MatrixShearExample(PaintEventArgs e)
{
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Shear(2, 0);
e.Graphics.DrawRectangle(new Pen(Color.Green), 0, 0, 100, 50);
e.Graphics.MultiplyTransform(myMatrix);
@@ -316,28 +309,28 @@ public void MatrixShearExample(PaintEventArgs e)
//
public void TransformPointsExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Create an array of points.
Point[] myArray =
- {
- new Point(20, 20),
- new Point(120, 20),
- new Point(120, 120),
- new Point(20, 120),
- new Point(20,20)
- };
-
+ [
+ new(20, 20),
+ new(120, 20),
+ new(120, 120),
+ new(20, 120),
+ new(20,20)
+ ];
+
// Draw the Points to the screen before applying the
// transform.
e.Graphics.DrawLines(myPen, myArray);
-
+
// Create a matrix and scale it.
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Scale(3, 2, MatrixOrder.Append);
myMatrix.TransformPoints(myArray);
-
+
// Draw the Points to the screen again after applying the
// transform.
e.Graphics.DrawLines(myPen2, myArray);
@@ -348,47 +341,47 @@ public void TransformPointsExample(PaintEventArgs e)
//
public void TransformVectorsExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Create an array of points.
Point[] myArray =
- {
- new Point(20, 20),
- new Point(120, 20),
- new Point(120, 120),
- new Point(20, 120),
- new Point(20,20)
- };
-
+ [
+ new(20, 20),
+ new(120, 20),
+ new(120, 120),
+ new(20, 120),
+ new(20,20)
+ ];
+
// Draw the Points to the screen before applying the
// transform.
e.Graphics.DrawLines(myPen, myArray);
-
+
// Create a matrix, scale it, and translate it.
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Scale(3, 2, MatrixOrder.Append);
myMatrix.Translate(100, 100, MatrixOrder.Append);
-
+
// List the matrix elements to the screen.
ListMatrixElements(e,
myMatrix,
"Scaled and Translated Matrix",
6,
20);
-
+
// Apply the transform to the array.
myMatrix.TransformVectors(myArray);
-
+
// Draw the Points to the screen again after applying the
// transform.
e.Graphics.DrawLines(myPen2, myArray);
}
-
+
//-------------------------------------------------------
// This function is a helper function to
// list the contents of a matrix.
- //-------------------------------------------------------
+ //-------------------------------------------------------.
public void ListMatrixElements(
PaintEventArgs e,
Matrix matrix,
@@ -396,14 +389,14 @@ public void ListMatrixElements(
int numElements,
int y)
{
-
+
// Set up variables for drawing the array
// of points to the screen.
int i;
float x = 20, X = 200;
- Font myFont = new Font("Arial", 8);
- SolidBrush myBrush = new SolidBrush(Color.Black);
-
+ Font myFont = new("Arial", 8);
+ SolidBrush myBrush = new(Color.Black);
+
// Draw the matrix name to the screen.
e.Graphics.DrawString(
matrixName + ": ",
@@ -411,7 +404,7 @@ public void ListMatrixElements(
myBrush,
x,
y);
-
+
// Draw the set of path points and types to the screen.
for(i=0; i
public void TranslateExample(PaintEventArgs e)
{
- Pen myPen = new Pen(Color.Blue, 1);
- Pen myPen2 = new Pen(Color.Red, 1);
-
+ Pen myPen = new(Color.Blue, 1);
+ Pen myPen2 = new(Color.Red, 1);
+
// Draw a rectangle to the screen before applying the
// transform.
e.Graphics.DrawRectangle(myPen, 20, 20, 100, 50);
-
+
// Create a matrix and translate it.
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Translate(100, 100, MatrixOrder.Append);
-
+
// Draw the Points to the screen again after applying the
// transform.
e.Graphics.Transform = myMatrix;
@@ -452,7 +445,7 @@ public void TranslateExample(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.Drawing2D/Matrix/Overview/Class1.cs b/snippets/csharp/System.Drawing.Drawing2D/Matrix/Overview/Class1.cs
index 73e41ac56ab..34b914e5071 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/Matrix/Overview/Class1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/Matrix/Overview/Class1.cs
@@ -1,10 +1,10 @@
using System;
-using System.Windows.Forms;
-using System.Drawing;
using System.Collections;
-using System.Xml;
-using System.Drawing.Imaging;
+using System.Drawing;
using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
+using System.Windows.Forms;
+using System.Xml;
public class Form1 : Form
{
@@ -18,20 +18,20 @@ public static void Main()
Pen myPen = Pens.Red;
// 0659fe00-9e0c-41c4-9118-016f2404c905
- // Matrix Representation of Transformations
+ // Matrix Representation of Transformations.
public void Method11()
{
Graphics myGraphics = this.CreateGraphics();
//
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Rotate(30);
myMatrix.Scale(1, 2, MatrixOrder.Append);
myMatrix.Translate(5, 0, MatrixOrder.Append);
//
}
// b601d66d-d572-4f11-9d2e-92f0dc8893f3
- // Global and Local Transformations
+ // Global and Local Transformations.
public void Method21()
{
@@ -47,9 +47,9 @@ public void Method21()
public void Method22()
{
Graphics myGraphics = this.CreateGraphics();
- GraphicsPath myGraphicsPath = new GraphicsPath();
+ GraphicsPath myGraphicsPath = new();
//
- Matrix myMatrix = new Matrix();
+ Matrix myMatrix = new();
myMatrix.Rotate(45);
myGraphicsPath.Transform(myMatrix);
myGraphics.DrawRectangle(myPen, 10, 10, 100, 50);
@@ -60,7 +60,7 @@ public void Method23()
{
Graphics myGraphics = this.CreateGraphics();
//
- Matrix myMatrix = new Matrix(1, 0, 0, -1, 0, 0);
+ Matrix myMatrix = new(1, 0, 0, -1, 0, 0);
myGraphics.Transform = myMatrix;
myGraphics.TranslateTransform(200, 150, MatrixOrder.Append);
//
@@ -68,20 +68,20 @@ public void Method23()
public void Method24()
{
Graphics myGraphics = this.CreateGraphics();
- SolidBrush mySolidBrush1 = new SolidBrush(Color.Red);
- SolidBrush mySolidBrush2 = new SolidBrush(Color.Black);
+ SolidBrush mySolidBrush1 = new(Color.Red);
+ SolidBrush mySolidBrush2 = new(Color.Black);
//
// Create the path.
- GraphicsPath myGraphicsPath = new GraphicsPath();
- Rectangle myRectangle = new Rectangle(0, 0, 60, 60);
+ GraphicsPath myGraphicsPath = new();
+ Rectangle myRectangle = new(0, 0, 60, 60);
myGraphicsPath.AddRectangle(myRectangle);
// Fill the path on the new coordinate system.
- // No local transformation
+ // No local transformation.
myGraphics.FillPath(mySolidBrush1, myGraphicsPath);
// Set the local transformation of the GraphicsPath object.
- Matrix myPathMatrix = new Matrix();
+ Matrix myPathMatrix = new();
myPathMatrix.Scale(2, 1);
myPathMatrix.Rotate(30, MatrixOrder.Append);
myGraphicsPath.Transform(myPathMatrix);
@@ -91,7 +91,7 @@ public void Method24()
//
}
// c61ff50a-eb1d-4e6c-83cd-f7e9764cfa9f
- // Types of Coordinate Systems
+ // Types of Coordinate Systems.
public void Method31()
{
@@ -113,7 +113,7 @@ public void Method33()
{
Graphics myGraphics = this.CreateGraphics();
//
- Pen myPen = new Pen(Color.Black, 1 / myGraphics.DpiX);
+ Pen myPen = new(Color.Black, 1 / myGraphics.DpiX);
//
}
public void Method34()
diff --git a/snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs b/snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs
index 973fc9ba351..765aab300da 100644
--- a/snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs
+++ b/snippets/csharp/System.Drawing.Drawing2D/PathGradientBrush/MultiplyTransform/form1.cs
@@ -1,9 +1,9 @@
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.Drawing2D.ClassicPathGradientBrushCS
{
@@ -20,12 +20,12 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
//
- // TODO: Add any constructor code after InitializeComponent call
+ // TODO: Add any constructor code after InitializeComponent call.
//
}
@@ -36,10 +36,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if (components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -61,34 +58,34 @@ private void InitializeComponent()
//
public void MultiplyTransformExample(PaintEventArgs e)
{
-
+
// Create a graphics path and add an rectangle.
- GraphicsPath myPath = new GraphicsPath();
- Rectangle rect = new Rectangle(20, 20, 100, 50);
+ GraphicsPath myPath = new();
+ Rectangle rect = new(20, 20, 100, 50);
myPath.AddRectangle(rect);
-
+
// Get the path's array of points.
PointF[] myPathPointArray = myPath.PathPoints;
-
+
// Create a path gradient brush.
- PathGradientBrush myPGBrush = new
- PathGradientBrush(myPathPointArray);
-
- // Set the color span.
- myPGBrush.CenterColor = Color.Red;
- Color[] mySurroundColor = {Color.Blue};
+ PathGradientBrush myPGBrush = new(myPathPointArray)
+ {
+ // Set the color span.
+ CenterColor = Color.Red
+ };
+ Color[] mySurroundColor = [Color.Blue];
myPGBrush.SurroundColors = mySurroundColor;
-
+
// Draw the brush to the screen prior to transformation.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
-
+
// Create a new matrix that rotates by 90 degrees, and
// translates by 100 in each direction.
- Matrix myMatrix = new Matrix(0, 1, -1, 0, 100, 100);
-
+ Matrix myMatrix = new(0, 1, -1, 0, 100, 100);
+
// Apply the transform to the brush.
myPGBrush.MultiplyTransform(myMatrix, MatrixOrder.Append);
-
+
// Draw the brush to the screen again after applying the
// transform.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300);
@@ -99,30 +96,30 @@ public void MultiplyTransformExample(PaintEventArgs e)
//
public void RotateTransformExample(PaintEventArgs e)
{
-
+
// Create a graphics path and add an ellipse.
- GraphicsPath myPath = new GraphicsPath();
- Rectangle rect = new Rectangle(100, 20, 100, 50);
+ GraphicsPath myPath = new();
+ Rectangle rect = new(100, 20, 100, 50);
myPath.AddRectangle(rect);
-
+
// Get the path's array of points.
PointF[] myPathPointArray = myPath.PathPoints;
-
+
// Create a path gradient brush.
- PathGradientBrush myPGBrush = new
- PathGradientBrush(myPathPointArray);
-
- // Set the color span.
- myPGBrush.CenterColor = Color.Red;
- Color[] mySurroundColor = {Color.Blue};
+ PathGradientBrush myPGBrush = new(myPathPointArray)
+ {
+ // Set the color span.
+ CenterColor = Color.Red
+ };
+ Color[] mySurroundColor = [Color.Blue];
myPGBrush.SurroundColors = mySurroundColor;
-
+
// Draw the brush to the screen prior to transformation.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
-
+
// Apply the rotate transform to the brush.
myPGBrush.RotateTransform(45, MatrixOrder.Append);
-
+
// Draw the brush to the screen again after applying the
// transform.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 300);
@@ -133,35 +130,35 @@ public void RotateTransformExample(PaintEventArgs e)
//
public void ScaleTransformExample(PaintEventArgs e)
{
-
+
// Create a graphics path and add a rectangle.
- GraphicsPath myPath = new GraphicsPath();
- Rectangle rect = new Rectangle(100, 20, 100, 50);
+ GraphicsPath myPath = new();
+ Rectangle rect = new(100, 20, 100, 50);
myPath.AddRectangle(rect);
-
+
// Get the path's array of points.
PointF[] myPathPointArray = myPath.PathPoints;
-
+
// Create a path gradient brush.
- PathGradientBrush myPGBrush = new
- PathGradientBrush(myPathPointArray);
-
- // Set the color span.
- myPGBrush.CenterColor = Color.Red;
- Color[] mySurroundColor = {Color.Blue};
+ PathGradientBrush myPGBrush = new(myPathPointArray)
+ {
+ // Set the color span.
+ CenterColor = Color.Red
+ };
+ Color[] mySurroundColor = [Color.Blue];
myPGBrush.SurroundColors = mySurroundColor;
-
+
// Draw the brush to the screen prior to transformation.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
-
+
// Scale by a factor of 2 in the x-axis by applying the scale
// transform to the brush.
myPGBrush.ScaleTransform(2, 1, MatrixOrder.Append);
-
+
// Move the brush down by 100 by Applying the translate
// transform to the brush.
myPGBrush.TranslateTransform(-100, 100, MatrixOrder.Append);
-
+
// Draw the brush to the screen again after applying the
// transforms.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
@@ -172,34 +169,34 @@ public void ScaleTransformExample(PaintEventArgs e)
//
public void SetBlendTriangularShapeExample(PaintEventArgs e)
{
-
+
// Create a graphics path and add a rectangle.
- GraphicsPath myPath = new GraphicsPath();
- Rectangle rect = new Rectangle(100, 20, 100, 50);
+ GraphicsPath myPath = new();
+ Rectangle rect = new(100, 20, 100, 50);
myPath.AddRectangle(rect);
-
+
// Get the path's array of points.
PointF[] myPathPointArray = myPath.PathPoints;
-
+
// Create a path gradient brush.
- PathGradientBrush myPGBrush = new
- PathGradientBrush(myPathPointArray);
-
- // Set the color span.
- myPGBrush.CenterColor = Color.Red;
- Color[] mySurroundColor = {Color.Blue};
+ PathGradientBrush myPGBrush = new(myPathPointArray)
+ {
+ // Set the color span.
+ CenterColor = Color.Red
+ };
+ Color[] mySurroundColor = [Color.Blue];
myPGBrush.SurroundColors = mySurroundColor;
-
+
// Draw the brush to the screen prior to the blend.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
-
+
// Set the Blend factors.
myPGBrush.SetBlendTriangularShape(0.5f, 1.0f);
-
+
// Move the brush down by 100 by Applying the translate
// transform to the brush.
myPGBrush.TranslateTransform(0, 100, MatrixOrder.Append);
-
+
// Draw the brush to the screen again after applying the
// transforms.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
@@ -210,34 +207,34 @@ public void SetBlendTriangularShapeExample(PaintEventArgs e)
//
public void SetSigmaBellShapeExample(PaintEventArgs e)
{
-
+
// Create a graphics path and add a rectangle.
- GraphicsPath myPath = new GraphicsPath();
- Rectangle rect = new Rectangle(100, 20, 100, 50);
+ GraphicsPath myPath = new();
+ Rectangle rect = new(100, 20, 100, 50);
myPath.AddRectangle(rect);
-
+
// Get the path's array of points.
PointF[] myPathPointArray = myPath.PathPoints;
-
+
// Create a path gradient brush.
- PathGradientBrush myPGBrush = new
- PathGradientBrush(myPathPointArray);
-
- // Set the color span.
- myPGBrush.CenterColor = Color.Red;
- Color[] mySurroundColor = {Color.Blue};
+ PathGradientBrush myPGBrush = new(myPathPointArray)
+ {
+ // Set the color span.
+ CenterColor = Color.Red
+ };
+ Color[] mySurroundColor = [Color.Blue];
myPGBrush.SurroundColors = mySurroundColor;
-
+
// Draw the brush to the screen prior to blend.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 200, 200);
-
+
// Set the Blend factors and transform the brush.
myPGBrush.SetSigmaBellShape(0.5f, 1.0f);
-
+
// Move the brush down by 100 by applying the translate
// transform to the brush.
myPGBrush.TranslateTransform(0, 100, MatrixOrder.Append);
-
+
// Draw the brush to the screen again after setting the
// blend and applying the transform.
e.Graphics.FillRectangle(myPGBrush, 10, 10, 300, 300);
@@ -248,7 +245,7 @@ public void SetSigmaBellShapeExample(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.Imaging/ColorMatrix/.ctor/Form1.cs b/snippets/csharp/System.Drawing.Imaging/ColorMatrix/.ctor/Form1.cs
index ab52bd121c1..2a70a8cd1ec 100644
--- a/snippets/csharp/System.Drawing.Imaging/ColorMatrix/.ctor/Form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/ColorMatrix/.ctor/Form1.cs
@@ -5,8 +5,8 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
-using System.Windows.Forms;
using System.Drawing.Imaging;
+using System.Windows.Forms;
#endregion
@@ -33,19 +33,19 @@ void Form1_Paint(object sender, PaintEventArgs e)
//
private void RotateColors(PaintEventArgs e)
{
- Bitmap image = new Bitmap("RotationInput.bmp");
- ImageAttributes imageAttributes = new ImageAttributes();
+ Bitmap image = new("RotationInput.bmp");
+ ImageAttributes imageAttributes = new();
int width = image.Width;
int height = image.Height;
float degrees = 60f;
- double r = degrees * System.Math.PI / 180; // degrees to radians
+ double r = degrees * System.Math.PI / 180; // degrees to radians.
- float[][] colorMatrixElements = {
- new float[] {(float)System.Math.Cos(r), (float)System.Math.Sin(r), 0, 0, 0},
- new float[] {(float)-System.Math.Sin(r), (float)-System.Math.Cos(r), 0, 0, 0},
- new float[] {0, 0, 2, 0, 0},
- new float[] {0, 0, 0, 1, 0},
- new float[] {0, 0, 0, 0, 1}};
+ float[][] colorMatrixElements = [
+ [(float)System.Math.Cos(r), (float)System.Math.Sin(r), 0, 0, 0],
+ [(float)-System.Math.Sin(r), (float)-System.Math.Cos(r), 0, 0, 0],
+ [0, 0, 2, 0, 0],
+ [0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 1]];
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
@@ -58,13 +58,13 @@ private void RotateColors(PaintEventArgs e)
e.Graphics.DrawImage(
image,
- new Rectangle(150, 10, width, height), // destination rectangle
- 0, 0, // upper-left corner of source rectangle
- width, // width of source rectangle
- height, // height of source rectangle
+ new Rectangle(150, 10, width, height), // destination rectangle.
+ 0, 0, // upper-left corner of source rectangle.
+ width, // width of source rectangle.
+ height, // height of source rectangle.
GraphicsUnit.Pixel,
imageAttributes);
}
//
}
-}
\ No newline at end of file
+}
diff --git a/snippets/csharp/System.Drawing.Imaging/ColorMatrix/Overview/Class1.cs b/snippets/csharp/System.Drawing.Imaging/ColorMatrix/Overview/Class1.cs
index 9287f7244a4..7352bff66d3 100644
--- a/snippets/csharp/System.Drawing.Imaging/ColorMatrix/Overview/Class1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/ColorMatrix/Overview/Class1.cs
@@ -1,32 +1,32 @@
using System;
-using System.Windows.Forms;
-using System.Drawing;
using System.Collections;
-using System.Xml;
+using System.Drawing;
using System.Drawing.Imaging;
+using System.Windows.Forms;
+using System.Xml;
public class SystemDrawingRecoloringImages
{
// 2106fb9a-4d60-4dcf-9220-9f189a6c4d19
- // How to: Translate Image Colors
+ // How to: Translate Image Colors.
private void Method11(PaintEventArgs e)
{
//
Image image = new Bitmap("ColorBars.bmp");
- ImageAttributes imageAttributes = new ImageAttributes();
+ ImageAttributes imageAttributes = new();
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, 0, 1, 0, 0},
- new float[] {0, 0, 0, 1, 0},
- new float[] {.75f, 0, 0, 0, 1}};
+ float[][] colorMatrixElements = [
+ [1, 0, 0, 0, 0],
+ [0, 1, 0, 0, 0],
+ [0, 0, 1, 0, 0],
+ [0, 0, 0, 1, 0],
+ [.75f, 0, 0, 0, 1]];
- ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
+ ColorMatrix colorMatrix = new(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
@@ -37,33 +37,33 @@ private void Method11(PaintEventArgs e)
e.Graphics.DrawImage(
image,
- new Rectangle(150, 10, width, height), // destination rectangle
- 0, 0, // upper-left corner of source rectangle
- width, // width of source rectangle
- height, // height of source rectangle
+ new Rectangle(150, 10, width, height), // destination rectangle.
+ 0, 0, // upper-left corner of source rectangle.
+ width, // width of source rectangle.
+ height, // height of source rectangle.
GraphicsUnit.Pixel,
imageAttributes);
//
}
// 44df4556-a433-49c0-ac0f-9a12063a5860
- // How to: Use a Color Matrix to Transform a Single Color
+ // How to: Use a Color Matrix to Transform a Single Color.
private void Method21(PaintEventArgs e)
{
//
Image image = new Bitmap("InputColor.bmp");
- ImageAttributes imageAttributes = new ImageAttributes();
+ ImageAttributes imageAttributes = new();
int width = image.Width;
int height = image.Height;
- float[][] colorMatrixElements = {
- new float[] {2, 0, 0, 0, 0}, // red scaling factor of 2
- new float[] {0, 1, 0, 0, 0}, // green scaling factor of 1
- new float[] {0, 0, 1, 0, 0}, // blue scaling factor of 1
- new float[] {0, 0, 0, 1, 0}, // alpha scaling factor of 1
- new float[] {.2f, .2f, .2f, 0, 1}}; // three translations of 0.2
+ float[][] colorMatrixElements = [
+ [2, 0, 0, 0, 0], // red scaling factor of 2.
+ [0, 1, 0, 0, 0], // green scaling factor of 1.
+ [0, 0, 1, 0, 0], // blue scaling factor of 1.
+ [0, 0, 0, 1, 0], // alpha scaling factor of 1.
+ [.2f, .2f, .2f, 0, 1]]; // three translations of 0.2.
- ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
+ ColorMatrix colorMatrix = new(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
@@ -74,30 +74,31 @@ private void Method21(PaintEventArgs e)
e.Graphics.DrawImage(
image,
- new Rectangle(120, 10, width, height), // destination rectangle
- 0, 0, // upper-left corner of source rectangle
- width, // width of source rectangle
- height, // height of source rectangle
+ new Rectangle(120, 10, width, height), // destination rectangle.
+ 0, 0, // upper-left corner of source rectangle.
+ width, // width of source rectangle.
+ height, // height of source rectangle.
GraphicsUnit.Pixel,
imageAttributes);
//
}
// 977df1ce-8665-42d4-9fb1-ef7f0ff63419
- // How to: Use a Color Remap Table
+ // How to: Use a Color Remap Table.
private void Method31(PaintEventArgs e)
{
//
Image image = new Bitmap("RemapInput.bmp");
- ImageAttributes imageAttributes = new ImageAttributes();
+ ImageAttributes imageAttributes = new();
int width = image.Width;
int height = image.Height;
- ColorMap colorMap = new ColorMap();
-
- colorMap.OldColor = Color.FromArgb(255, 255, 0, 0); // opaque red
- colorMap.NewColor = Color.FromArgb(255, 0, 0, 255); // opaque blue
+ ColorMap colorMap = new()
+ {
+ OldColor = Color.FromArgb(255, 255, 0, 0), // opaque red.
+ NewColor = Color.FromArgb(255, 0, 0, 255) // opaque blue.
+ };
- ColorMap[] remapTable = { colorMap };
+ ColorMap[] remapTable = [colorMap];
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
@@ -105,10 +106,10 @@ private void Method31(PaintEventArgs e)
e.Graphics.DrawImage(
image,
- new Rectangle(150, 10, width, height), // destination rectangle
- 0, 0, // upper-left corner of source rectangle
- width, // width of source rectangle
- height, // height of source rectangle
+ new Rectangle(150, 10, width, height), // destination rectangle.
+ 0, 0, // upper-left corner of source rectangle.
+ width, // width of source rectangle.
+ height, // height of source rectangle.
GraphicsUnit.Pixel,
imageAttributes);
//
@@ -120,18 +121,18 @@ private void Method41(PaintEventArgs e)
{
//
Image image = new Bitmap("ColorBars2.bmp");
- ImageAttributes imageAttributes = new ImageAttributes();
+ ImageAttributes imageAttributes = new();
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, 0, 2, 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, 0, 2, 0, 0],
+ [0, 0, 0, 1, 0],
+ [0, 0, 0, 0, 1]];
- ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
+ ColorMatrix colorMatrix = new(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
@@ -142,10 +143,10 @@ private void Method41(PaintEventArgs e)
e.Graphics.DrawImage(
image,
- new Rectangle(150, 10, width, height), // destination rectangle
- 0, 0, // upper-left corner of source rectangle
- width, // width of source rectangle
- height, // height of source rectangle
+ new Rectangle(150, 10, width, height), // destination rectangle.
+ 0, 0, // upper-left corner of source rectangle.
+ width, // width of source rectangle.
+ height, // height of source rectangle.
GraphicsUnit.Pixel,
imageAttributes);
//
@@ -154,18 +155,18 @@ private void Method42(PaintEventArgs e)
{
//
Image image = new Bitmap("ColorBars.bmp");
- ImageAttributes imageAttributes = new ImageAttributes();
+ ImageAttributes imageAttributes = new();
int width = image.Width;
int height = image.Height;
- float[][] colorMatrixElements = {
- new float[] {.75F, 0, 0, 0, 0},
- new float[] {0, .65F, 0, 0, 0},
- new float[] {0, 0, .5F, 0, 0},
- new float[] {0, 0, 0, 1F, 0},
- new float[] {0, 0, 0, 0, 1F}};
+ float[][] colorMatrixElements = [
+ [.75F, 0, 0, 0, 0],
+ [0, .65F, 0, 0, 0],
+ [0, 0, .5F, 0, 0],
+ [0, 0, 0, 1F, 0],
+ [0, 0, 0, 0, 1F]];
- ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
+ ColorMatrix colorMatrix = new(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
@@ -176,10 +177,10 @@ private void Method42(PaintEventArgs e)
e.Graphics.DrawImage(
image,
- new Rectangle(150, 10, width, height), // destination rectangle
- 0, 0, // upper-left corner of source rectangle
- width, // width of source rectangle
- height, // height of source rectangle
+ new Rectangle(150, 10, width, height), // destination rectangle.
+ 0, 0, // upper-left corner of source rectangle.
+ width, // width of source rectangle.
+ height, // height of source rectangle.
GraphicsUnit.Pixel,
imageAttributes);
//
diff --git a/snippets/csharp/System.Drawing.Imaging/Encoder/ColorDepth/form1.cs b/snippets/csharp/System.Drawing.Imaging/Encoder/ColorDepth/form1.cs
index 9c2994fd414..878aab981d1 100644
--- a/snippets/csharp/System.Drawing.Imaging/Encoder/ColorDepth/form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/Encoder/ColorDepth/form1.cs
@@ -1,54 +1,49 @@
- // Snippet for: F:System.Drawing.Imaging.Encoder.ColorDepth
- // Snippet for: F:System.Drawing.Imaging.Encoder.Compression
- // Snippet for: F:System.Drawing.Imaging.Encoder.Quality
- //
+// Snippet for: F:System.Drawing.Imaging.Encoder.ColorDepth
+// Snippet for: F:System.Drawing.Imaging.Encoder.Compression
+// Snippet for: F:System.Drawing.Imaging.Encoder.Quality
+//
using System;
using System.Drawing;
using System.Drawing.Imaging;
+
class Example_SetColorDepth
{
public static void Main()
{
- Bitmap myBitmap;
- ImageCodecInfo myImageCodecInfo;
- Encoder myEncoder;
- EncoderParameter myEncoderParameter;
- EncoderParameters myEncoderParameters;
-
// Create a Bitmap object based on a BMP file.
- myBitmap = new Bitmap(@"C:\Documents and Settings\All Users\Documents\My Music\music.bmp");
-
+ using Bitmap myBitmap = new(@"C:\Documents and Settings\All Users\Documents\My Music\music.bmp");
+
// Get an ImageCodecInfo object that represents the TIFF codec.
- myImageCodecInfo = GetEncoderInfo("image/tiff");
-
+ ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
+
// Create an Encoder object based on the GUID
// for the ColorDepth parameter category.
- myEncoder = Encoder.ColorDepth;
-
+ Encoder myEncoder = Encoder.ColorDepth;
+
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
- // objects. In this case, there is only one
+ // objects. In this case, there is only one.
// EncoderParameter object in the array.
- myEncoderParameters = new EncoderParameters(1);
-
+ using EncoderParameters myEncoderParameters = new(1);
+
// Save the image with a color depth of 24 bits per pixel.
- myEncoderParameter =
- new EncoderParameter(myEncoder, 24L);
+ using EncoderParameter myEncoderParameter = new(myEncoder, 24L);
myEncoderParameters.Param[0] = myEncoderParameter;
myBitmap.Save("Shapes24bpp.tiff", 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)
+ ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
+ for (int 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.Imaging/Encoder/Compression/form1.cs b/snippets/csharp/System.Drawing.Imaging/Encoder/Compression/form1.cs
index ac2aa2bdb4e..87cda7d5b1a 100644
--- a/snippets/csharp/System.Drawing.Imaging/Encoder/Compression/form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/Encoder/Compression/form1.cs
@@ -3,49 +3,46 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
+
class Example_SetTIFFCompression
{
public static void Main()
{
- Bitmap myBitmap;
- ImageCodecInfo myImageCodecInfo;
- Encoder myEncoder;
- EncoderParameter myEncoderParameter;
- EncoderParameters myEncoderParameters;
-
// Create a Bitmap object based on a BMP file.
- myBitmap = new Bitmap("Shapes.bmp");
-
+ using Bitmap myBitmap = new("Shapes.bmp");
+
// Get an ImageCodecInfo object that represents the TIFF codec.
- myImageCodecInfo = GetEncoderInfo("image/tiff");
-
+ ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
+
// Create an Encoder object based on the GUID
// for the Compression parameter category.
- myEncoder = Encoder.Compression;
-
+ Encoder myEncoder = Encoder.Compression;
+
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
- // objects. In this case, there is only one
+ // objects. In this case, there is only one.
// EncoderParameter object in the array.
- myEncoderParameters = new EncoderParameters(1);
-
+ using EncoderParameters myEncoderParameters = new(1);
+
// Save the bitmap as a TIFF file with LZW compression.
- myEncoderParameter = new EncoderParameter(
+ using EncoderParameter myEncoderParameter = new(
myEncoder,
(long)EncoderValue.CompressionLZW);
myEncoderParameters.Param[0] = myEncoderParameter;
myBitmap.Save("ShapesLZW.tif", 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)
+ ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
+ for (int 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.Imaging/Encoder/SaveFlag/form1.cs b/snippets/csharp/System.Drawing.Imaging/Encoder/SaveFlag/form1.cs
index 924f1eb8144..1ff5b5af5e7 100644
--- a/snippets/csharp/System.Drawing.Imaging/Encoder/SaveFlag/form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/Encoder/SaveFlag/form1.cs
@@ -1,77 +1,76 @@
// Snippet for: F:System.Drawing.Imaging.Encoder.SaveFlag
- //
+//
using System;
using System.Drawing;
using System.Drawing.Imaging;
+
class Example_MultiFrame
{
public static void Main()
{
- Bitmap multi;
- Bitmap page2;
- Bitmap page3;
- ImageCodecInfo myImageCodecInfo;
- Encoder myEncoder;
- EncoderParameter myEncoderParameter;
- EncoderParameters myEncoderParameters;
-
// Create three Bitmap objects.
- multi = new Bitmap("Shapes.bmp");
- page2 = new Bitmap("Iron.jpg");
- page3 = new Bitmap("House.png");
-
+ using Bitmap multi = new("Shapes.bmp");
+ using Bitmap page2 = new("Iron.jpg");
+ using Bitmap page3 = new("House.png");
+
// Get an ImageCodecInfo object that represents the TIFF codec.
- myImageCodecInfo = GetEncoderInfo("image/tiff");
-
+ ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/tiff");
+
// Create an Encoder object based on the GUID
// for the SaveFlag parameter category.
- myEncoder = Encoder.SaveFlag;
-
+ Encoder myEncoder = Encoder.SaveFlag;
+
// 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);
-
+ using EncoderParameters myEncoderParameters = new(1);
+
// Save the first page (frame).
- myEncoderParameter = new EncoderParameter(
+ EncoderParameter myEncoderParameter = new(
myEncoder,
(long)EncoderValue.MultiFrame);
myEncoderParameters.Param[0] = myEncoderParameter;
multi.Save("Multiframe.tiff", myImageCodecInfo, myEncoderParameters);
-
+
// Save the second page (frame).
+ myEncoderParameter.Dispose();
myEncoderParameter = new EncoderParameter(
myEncoder,
(long)EncoderValue.FrameDimensionPage);
myEncoderParameters.Param[0] = myEncoderParameter;
multi.SaveAdd(page2, myEncoderParameters);
-
+
// Save the third page (frame).
+ myEncoderParameter.Dispose();
myEncoderParameter = new EncoderParameter(
myEncoder,
(long)EncoderValue.FrameDimensionPage);
myEncoderParameters.Param[0] = myEncoderParameter;
multi.SaveAdd(page3, myEncoderParameters);
-
+
// Close the multiple-frame file.
+ myEncoderParameter.Dispose();
myEncoderParameter = new EncoderParameter(
myEncoder,
(long)EncoderValue.Flush);
myEncoderParameters.Param[0] = myEncoderParameter;
multi.SaveAdd(myEncoderParameters);
+ myEncoderParameter.Dispose();
}
- 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)
+ ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
+ for (int 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.Imaging/Encoder/Transformation/form1.cs b/snippets/csharp/System.Drawing.Imaging/Encoder/Transformation/form1.cs
index 9498921d4fd..53c4570bdfd 100644
--- a/snippets/csharp/System.Drawing.Imaging/Encoder/Transformation/form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/Encoder/Transformation/form1.cs
@@ -1,52 +1,49 @@
- // Snippet for: F:System.Drawing.Imaging.Encoder.Transformation
- //
+// Snippet for: F:System.Drawing.Imaging.Encoder.Transformation
+//
using System;
using System.Drawing;
using System.Drawing.Imaging;
+
class Example_RotateJPEG
{
public static void Main()
{
- Bitmap myBitmap;
- ImageCodecInfo myImageCodecInfo;
- Encoder myEncoder;
- EncoderParameter myEncoderParameter;
- EncoderParameters myEncoderParameters;
-
// Create a Bitmap object based on a JPEG file.
- myBitmap = new Bitmap("Shapes.jpg");
-
+ using Bitmap myBitmap = new("Shapes.jpg");
+
// Get an ImageCodecInfo object that represents the JPEG codec.
- myImageCodecInfo = GetEncoderInfo("image/jpeg");
-
+ ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/jpeg");
+
// Create an Encoder object based on the GUID
// for the Transformation parameter category.
- myEncoder = Encoder.Transformation;
-
+ Encoder myEncoder = Encoder.Transformation;
+
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
- // objects. In this case, there is only one
+ // objects. In this case, there is only one.
// EncoderParameter object in the array.
- myEncoderParameters = new EncoderParameters(1);
-
+ using EncoderParameters myEncoderParameters = new(1);
+
// Rotate the image 90 degrees, and save it as a separate JPEG file.
- myEncoderParameter = new EncoderParameter(
+ using EncoderParameter myEncoderParameter = new(
myEncoder,
(long)EncoderValue.TransformRotate90);
myEncoderParameters.Param[0] = myEncoderParameter;
myBitmap.Save("ShapesR90.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)
+ ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
+ for (int j = 0; j < encoders.Length; ++j)
{
- if(encoders[j].MimeType == mimeType)
+ if (encoders[j].MimeType == mimeType)
+ {
return encoders[j];
+ }
}
+
return null;
}
}
- //
\ No newline at end of file
+//
diff --git a/snippets/csharp/System.Drawing.Imaging/EncoderParameter/Overview/Form1.cs b/snippets/csharp/System.Drawing.Imaging/EncoderParameter/Overview/Form1.cs
index 87cf1ed20f6..d2bfb6f401f 100644
--- a/snippets/csharp/System.Drawing.Imaging/EncoderParameter/Overview/Form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/EncoderParameter/Overview/Form1.cs
@@ -4,9 +4,9 @@
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
-using System.Drawing.Imaging;
namespace GDIPlusPort
{
@@ -34,7 +34,7 @@ private void GetImageEncodersExample(PaintEventArgs e)
// Set up display variables.
Color foreColor = Color.Black;
- Font font = new Font("Arial", 8);
+ Font font = new("Arial", 8);
int i = 0;
// Check to determine whether any codecs were found.
@@ -99,7 +99,7 @@ private void GetImageDecodersExample(PaintEventArgs e)
// Set up display variables.
Color foreColor = Color.Black;
- Font font = new Font("Arial", 8);
+ Font font = new("Arial", 8);
int i = 0;
// Check to determine whether any codecs were found.
@@ -156,11 +156,11 @@ private void GetImageDecodersExample(PaintEventArgs e)
//
private void GetSupportedParameters(PaintEventArgs e)
{
- Bitmap bitmap1 = new Bitmap(1, 1);
+ Bitmap bitmap1 = new(1, 1);
ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
EncoderParameters paramList = bitmap1.GetEncoderParameterList(jpgEncoder.Clsid);
EncoderParameter[] encParams = paramList.Param;
- StringBuilder paramInfo = new StringBuilder();
+ StringBuilder paramInfo = new();
for (int i = 0; i < encParams.Length; i++)
{
@@ -170,7 +170,7 @@ private void GetSupportedParameters(PaintEventArgs e)
}
e.Graphics.DrawString(paramInfo.ToString(), this.Font, Brushes.Red, 10.0F, 10.0F);
}
-
+
//
private ImageCodecInfo GetEncoder(ImageFormat format)
{
@@ -183,7 +183,7 @@ private ImageCodecInfo GetEncoder(ImageFormat format)
return codec;
}
}
-
+
return null;
}
//
@@ -192,7 +192,7 @@ private ImageCodecInfo GetEncoder(ImageFormat format)
//
private void SaveBmpAsPNG()
{
- Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");
+ Bitmap bmp1 = new(typeof(Button), "Button.bmp");
bmp1.Save(@"c:\button.png", ImageFormat.Png);
}
//
@@ -201,7 +201,7 @@ private void SaveBmpAsPNG()
private void VaryQualityLevel()
{
// Get a bitmap.
- Bitmap bmp1 = new Bitmap(@"c:\TestPhoto.jpg");
+ Bitmap bmp1 = new(@"c:\TestPhoto.jpg");
ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
@@ -213,9 +213,9 @@ private void VaryQualityLevel()
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
- EncoderParameters myEncoderParameters = new EncoderParameters(1);
+ EncoderParameters myEncoderParameters = new(1);
- EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
+ EncoderParameter myEncoderParameter = new(myEncoder, 50L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"c:\TestPhotoQualityFifty.jpg", jpgEncoder, myEncoderParameters);
@@ -229,13 +229,13 @@ private void VaryQualityLevel()
bmp1.Save(@"c:\TestPhotoQualityZero.jpg", jpgEncoder, myEncoderParameters);
}
//
-
+
private void Form1_Load(object sender, EventArgs e)
{
//SaveBmpAsPng();
}
- private void Form1_Paint(object sender, PaintEventArgs e)
+ private void Form1_Paint(object sender, PaintEventArgs e)
{
GetSupportedParameters(e);
SaveBmpAsPNG();
diff --git a/snippets/csharp/System.Drawing.Imaging/ImageAttributes/SetBrushRemapTable/form1.cs b/snippets/csharp/System.Drawing.Imaging/ImageAttributes/SetBrushRemapTable/form1.cs
index ba30d1554f2..f8f8e29685e 100644
--- a/snippets/csharp/System.Drawing.Imaging/ImageAttributes/SetBrushRemapTable/form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/ImageAttributes/SetBrushRemapTable/form1.cs
@@ -1,8 +1,8 @@
using System;
-using System.Drawing;
-using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
+using System.Drawing;
+using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace System.Drawing.Imaging.ClassicImageAttributesCS
@@ -20,12 +20,12 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
//
- // TODO: Add any constructor code after InitializeComponent call
+ // TODO: Add any constructor code after InitializeComponent call.
//
}
@@ -36,10 +36,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if(components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -48,17 +45,14 @@ protected override void Dispose( bool disposing )
//
public void SetBrushRemapTableExample(PaintEventArgs e)
{
-
+
// Create a color map.
- ColorMap[] myColorMap = new ColorMap[1];
- myColorMap[0] = new ColorMap();
+ ColorMap[] myColorMap = [new ColorMap()];
myColorMap[0].OldColor = Color.Red;
myColorMap[0].NewColor = Color.Green;
-
- // Create an ImageAttributes object, passing it to the myColorMap
-
- // array.
- ImageAttributes imageAttr = new ImageAttributes();
+
+ // Create an ImageAttributes object, passing it to the myColorMap array.
+ ImageAttributes imageAttr = new();
imageAttr.SetBrushRemapTable(myColorMap);
}
//
@@ -67,23 +61,23 @@ public void SetBrushRemapTableExample(PaintEventArgs e)
//
private void SetColorKeyExample(PaintEventArgs e)
{
-
+
// Open an Image file and draw it to the screen.
Image myImage = Image.FromFile("Circle.bmp");
e.Graphics.DrawImage(myImage, 20, 20);
-
+
// Create an ImageAttributes object and set the color key.
Color lowerColor = Color.FromArgb(245,0,0);
Color upperColor = Color.FromArgb(255,0,0);
- ImageAttributes imageAttr = new ImageAttributes();
+ ImageAttributes imageAttr = new();
imageAttr.SetColorKey(lowerColor,
upperColor,
ColorAdjustType.Default);
-
+
// Draw the image with the color key set.
- Rectangle rect = new Rectangle(150, 20, 100, 100);
- e.Graphics.DrawImage(myImage, rect, 0, 0, 100, 100,
- GraphicsUnit.Pixel, imageAttr);
+ Rectangle rect = new(150, 20, 100, 100);
+ e.Graphics.DrawImage(myImage, rect, 0, 0, 100, 100,
+ GraphicsUnit.Pixel, imageAttr);
}
//
@@ -91,46 +85,45 @@ private void SetColorKeyExample(PaintEventArgs e)
//
private void SetColorMatrixExample(PaintEventArgs e)
{
-
- // Create a rectangle image with all colors set to 128 (medium
-
- // gray).
- Bitmap myBitmap = new Bitmap(50, 50, PixelFormat.Format32bppArgb);
+
+ // Create a rectangle image with all colors set to 128 (medium gray).
+ Bitmap myBitmap = new(50, 50, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(myBitmap);
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 128, 128, 128)),
new Rectangle(0, 0, 50, 50));
myBitmap.Save("Rectangle1.jpg");
-
+
// Open an Image file and draw it to the screen.
Image myImage = Image.FromFile("Rectangle1.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
-
+
// Initialize the color matrix.
- ColorMatrix myColorMatrix = new ColorMatrix();
-
- // Red
- myColorMatrix.Matrix00 = 1.75f;
-
- // Green
- myColorMatrix.Matrix11 = 1.00f;
-
- // Blue
- myColorMatrix.Matrix22 = 1.00f;
-
- // alpha
- myColorMatrix.Matrix33 = 1.00f;
-
- // w
- myColorMatrix.Matrix44 = 1.00f;
+ ColorMatrix myColorMatrix = new()
+ {
+ // Red.
+ Matrix00 = 1.75f,
+
+ // Green.
+ Matrix11 = 1.00f,
+
+ // Blue.
+ Matrix22 = 1.00f,
+
+ // alpha.
+ Matrix33 = 1.00f,
+
+ // w.
+ Matrix44 = 1.00f
+ };
// Create an ImageAttributes object and set the color matrix.
- ImageAttributes imageAttr = new ImageAttributes();
+ ImageAttributes imageAttr = new();
imageAttr.SetColorMatrix(myColorMatrix);
-
+
// Draw the image using the color matrix.
- Rectangle rect = new Rectangle(100, 20, 200, 200);
- e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
- GraphicsUnit.Pixel, imageAttr);
+ Rectangle rect = new(100, 20, 200, 200);
+ e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
+ GraphicsUnit.Pixel, imageAttr);
}
//
@@ -138,21 +131,21 @@ private void SetColorMatrixExample(PaintEventArgs e)
//
private void SetGammaExample(PaintEventArgs e)
{
-
+
// Create an Image object from the file Camera.jpg, and draw it to
// the screen.
Image myImage = Image.FromFile("Camera.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
-
+
// Create an ImageAttributes object and set the gamma to 2.2.
- System.Drawing.Imaging.ImageAttributes imageAttr =
- new System.Drawing.Imaging.ImageAttributes();
+ System.Drawing.Imaging.ImageAttributes imageAttr =
+ new();
imageAttr.SetGamma(2.2f);
-
+
// Draw the image with gamma set to 2.2.
- Rectangle rect = new Rectangle(250, 20, 200, 200);
- e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
- GraphicsUnit.Pixel, imageAttr);
+ Rectangle rect = new(250, 20, 200, 200);
+ e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
+ GraphicsUnit.Pixel, imageAttr);
}
//
@@ -160,27 +153,27 @@ private void SetGammaExample(PaintEventArgs e)
//
private void SetNoOpExample(PaintEventArgs e)
{
-
+
// Create an Image object from the file Camera.jpg.
Image myImage = Image.FromFile("Camera.jpg");
-
+
// Create an ImageAttributes object, and set the gamma to 0.25.
- ImageAttributes imageAttr = new ImageAttributes();
+ ImageAttributes imageAttr = new();
imageAttr.SetGamma(0.25f);
-
+
// Draw the image with gamma set to 0.25.
- Rectangle rect1 = new Rectangle(20, 20, 200, 200);
- e.Graphics.DrawImage(myImage, rect1, 0, 0, 200, 200,
- GraphicsUnit.Pixel, imageAttr);
-
+ Rectangle rect1 = new(20, 20, 200, 200);
+ e.Graphics.DrawImage(myImage, rect1, 0, 0, 200, 200,
+ GraphicsUnit.Pixel, imageAttr);
+
// Call the ImageAttributes NoOp method.
imageAttr.SetNoOp();
-
+
// Draw the image after NoOp is set, so the default gamma value
// of 1.0 will be used.
- Rectangle rect2 = new Rectangle(250, 20, 200, 200);
- e.Graphics.DrawImage(myImage, rect2, 0, 0, 200, 200,
- GraphicsUnit.Pixel, imageAttr);
+ Rectangle rect2 = new(250, 20, 200, 200);
+ e.Graphics.DrawImage(myImage, rect2, 0, 0, 200, 200,
+ GraphicsUnit.Pixel, imageAttr);
}
//
@@ -188,36 +181,34 @@ private void SetNoOpExample(PaintEventArgs e)
//
private void SetRemapTableExample(PaintEventArgs e)
{
-
+
// Create a filled, red image, and save it to Circle2.jpg.
- Bitmap myBitmap = new Bitmap(50, 50);
+ Bitmap myBitmap = new(50, 50);
Graphics g = Graphics.FromImage(myBitmap);
g.Clear(Color.White);
g.FillEllipse(new SolidBrush(Color.Red),
new Rectangle(0, 0, 50, 50));
myBitmap.Save("Circle2.jpg");
-
- // Create an Image object from the Circle2.jpg file, and draw it to
-
- // the screen.
+
+ // Create an Image object from the Circle2.jpg file,
+ // and draw it to the screen.
Image myImage = Image.FromFile("Circle2.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
-
+
// Create a color map.
- ColorMap[] myColorMap = new ColorMap[1];
- myColorMap[0] = new ColorMap();
+ ColorMap[] myColorMap = [new ColorMap()];
myColorMap[0].OldColor = Color.Red;
myColorMap[0].NewColor = Color.Green;
-
+
// Create an ImageAttributes object, and then pass the
// myColorMap object to the SetRemapTable method.
- ImageAttributes imageAttr = new ImageAttributes();
+ ImageAttributes imageAttr = new();
imageAttr.SetRemapTable(myColorMap);
-
+
// Draw the image with the remap table set.
- Rectangle rect = new Rectangle(150, 20, 50, 50);
- e.Graphics.DrawImage(myImage, rect, 0, 0, 50, 50,
- GraphicsUnit.Pixel, imageAttr);
+ Rectangle rect = new(150, 20, 50, 50);
+ e.Graphics.DrawImage(myImage, rect, 0, 0, 50, 50,
+ GraphicsUnit.Pixel, imageAttr);
}
//
@@ -225,19 +216,19 @@ private void SetRemapTableExample(PaintEventArgs e)
//
private void SetThresholdExample(PaintEventArgs e)
{
-
+
// Open an Image file, and draw it to the screen.
Image myImage = Image.FromFile("Camera.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
-
+
// Create an ImageAttributes object, and set its color threshold.
- ImageAttributes imageAttr = new ImageAttributes();
+ ImageAttributes imageAttr = new();
imageAttr.SetThreshold(0.7f);
-
+
// Draw the image with the colors bifurcated.
- Rectangle rect = new Rectangle(300, 20, 200, 200);
- e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
- GraphicsUnit.Pixel, imageAttr);
+ Rectangle rect = new(300, 20, 200, 200);
+ e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200,
+ GraphicsUnit.Pixel, imageAttr);
}
//
@@ -245,28 +236,28 @@ private void SetThresholdExample(PaintEventArgs e)
//
private void SetWrapModeExample(PaintEventArgs e)
{
-
+
// Create a filled, red circle, and save it to Circle3.jpg.
- Bitmap myBitmap = new Bitmap(50, 50);
+ Bitmap myBitmap = new(50, 50);
Graphics g = Graphics.FromImage(myBitmap);
g.Clear(Color.White);
g.FillEllipse(new SolidBrush(Color.Red),
new Rectangle(0, 0, 25, 25));
myBitmap.Save("Circle3.jpg");
-
+
// Create an Image object from the Circle3.jpg file, and draw it
// to the screen.
Image myImage = Image.FromFile("Circle3.jpg");
e.Graphics.DrawImage(myImage, 20, 20);
-
+
// Set the wrap mode.
- ImageAttributes imageAttr = new ImageAttributes();
+ ImageAttributes imageAttr = new();
imageAttr.SetWrapMode(WrapMode.Tile);
-
+
// Create a TextureBrush.
- Rectangle brushRect = new Rectangle(0,0,25,25);
- TextureBrush myTBrush = new TextureBrush(myImage, brushRect, imageAttr);
-
+ Rectangle brushRect = new(0,0,25,25);
+ TextureBrush myTBrush = new(myImage, brushRect, imageAttr);
+
// Draw to the screen a rectangle filled with red circles.
e.Graphics.FillRectangle(myTBrush, 100, 20, 200, 200);
}
diff --git a/snippets/csharp/System.Drawing.Imaging/ImageCodecInfo/GetImageEncoders/form1.cs b/snippets/csharp/System.Drawing.Imaging/ImageCodecInfo/GetImageEncoders/form1.cs
index c5d83e47487..09b05ccd43b 100644
--- a/snippets/csharp/System.Drawing.Imaging/ImageCodecInfo/GetImageEncoders/form1.cs
+++ b/snippets/csharp/System.Drawing.Imaging/ImageCodecInfo/GetImageEncoders/form1.cs
@@ -1,9 +1,9 @@
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.Imaging.ClassicImageCodecInfoCS
{
@@ -20,12 +20,12 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
//
- // TODO: Add any constructor code after InitializeComponent call
+ // TODO: Add any constructor code after InitializeComponent call.
//
}
@@ -36,10 +36,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if (components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -61,30 +58,29 @@ private void InitializeComponent()
//
private void GetImageEncodersExample(PaintEventArgs e)
{
-
+
// Get an array of available codecs.
ImageCodecInfo[] myCodecs;
myCodecs = ImageCodecInfo.GetImageEncoders();
int numCodecs = myCodecs.GetLength(0);
-
+
//numCodecs = 1;
-
+
// Set up display variables.
Color foreColor = Color.Black;
- Font font = new Font("Arial", 8);
+ Font font = new("Arial", 8);
int i = 0;
-
+
// Check to determine whether any codecs were found.
if(numCodecs > 0)
{
-
- // Set up an array to hold codec information. There are 9
-
- // information elements plus 1 space for each codec, so 10 times
-
+ // Set up an array to hold codec information.
+ // There are 9 information elements plus 1 space
+ // for each codec, so 10 times.
+
// the number of codecs found is allocated.
string[] myCodecInfo = new string[numCodecs*10];
-
+
// Write all the codec information to the array.
for(i=0;i
[STAThread]
- static void Main()
+ static void Main()
{
Application.Run(new Form1());
}
diff --git a/snippets/csharp/System.Drawing.Printing/Margins/Bottom/source.cs b/snippets/csharp/System.Drawing.Printing/Margins/Bottom/source.cs
index e80e10fec3a..7019c769e67 100644
--- a/snippets/csharp/System.Drawing.Printing/Margins/Bottom/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/Margins/Bottom/source.cs
@@ -1,7 +1,7 @@
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
public class Sample : Form {
@@ -14,42 +14,42 @@ public class Sample : Form {
//
public void Printing()
{
- try
+ try
{
/* This assumes that a variable of type string, named filePath,
has been set to the path of the file to print. */
streamToPrint = new StreamReader (filePath);
- try
+ try
{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
/* This assumes that a method, named pd_PrintPage, has been
defined. pd_PrintPage handles the PrintPage event. */
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
- /* This assumes that a variable of type string, named
+ /* This assumes that a variable of type string, named
printer, has been set to the printer's name. */
pd.PrinterSettings.PrinterName = printer;
-
+
// Set the left and right margins to 1 inch.
pd.DefaultPageSettings.Margins.Left = 100;
pd.DefaultPageSettings.Margins.Right = 100;
// Set the top and bottom margins to 1.5 inches.
pd.DefaultPageSettings.Margins.Top = 150;
pd.DefaultPageSettings.Margins.Bottom = 150;
-
+
pd.Print();
- }
- finally
+ }
+ finally
{
streamToPrint.Close() ;
}
- }
- catch(Exception ex)
- {
+ }
+ catch(Exception ex)
+ {
MessageBox.Show("An error occurred printing the file - " + ex.Message);
}
}
-
+
//
private void pd_PrintPage(object sender, PrintPageEventArgs e) {
diff --git a/snippets/csharp/System.Drawing.Printing/Margins/Overview/source.cs b/snippets/csharp/System.Drawing.Printing/Margins/Overview/source.cs
index 86f3b766001..08347feae3f 100644
--- a/snippets/csharp/System.Drawing.Printing/Margins/Overview/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/Margins/Overview/source.cs
@@ -1,7 +1,7 @@
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
public class Sample : Form {
@@ -14,37 +14,37 @@ public class Sample : Form {
//
public void Printing()
{
- try
+ try
{
/* This assumes that a variable of type string, named filePath,
has been set to the path of the file to print. */
streamToPrint = new StreamReader (filePath);
- try
+ try
{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
/* This assumes that a method, named pd_PrintPage, has been
defined. pd_PrintPage handles the PrintPage event. */
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
- /* This assumes that a variable of type string, named
+ /* This assumes that a variable of type string, named
printer, has been set to the printer's name. */
pd.PrinterSettings.PrinterName = printer;
// Create a new instance of Margins with one inch margins.
- Margins margins = new Margins(100,100,100,100);
+ Margins margins = new(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
- }
- finally
+ }
+ finally
{
streamToPrint.Close() ;
}
- }
- catch(Exception ex)
- {
+ }
+ catch(Exception ex)
+ {
MessageBox.Show("An error occurred printing the file - " + ex.Message);
}
}
-
+
//
private void pd_PrintPage(object sender, PrintPageEventArgs e) {
diff --git a/snippets/csharp/System.Drawing.Printing/PageSettings/Color/source.cs b/snippets/csharp/System.Drawing.Printing/PageSettings/Color/source.cs
index 1b207d9cc96..97141703297 100644
--- a/snippets/csharp/System.Drawing.Printing/PageSettings/Color/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PageSettings/Color/source.cs
@@ -1,11 +1,11 @@
using System;
-using System.IO;
-using System.Drawing;
-using System.Drawing.Printing;
using System.Collections;
using System.ComponentModel;
-using System.Windows.Forms;
using System.Data;
+using System.Drawing;
+using System.Drawing.Printing;
+using System.IO;
+using System.Windows.Forms;
namespace WindowsApplication3
{
@@ -14,8 +14,8 @@ namespace WindowsApplication3
///
public class Form1 : System.Windows.Forms.Form
{
- // my vars
- PrintDocument printDoc = new PrintDocument();
+ // my vars.
+ PrintDocument printDoc = new();
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
@@ -31,11 +31,11 @@ public class Form1 : System.Windows.Forms.Form
public Form1()
{
//
- // Required for Windows Form Designer support
+ // Required for Windows Form Designer support.
//
InitializeComponent();
- // Setup the event handlers
+ // Setup the event handlers.
printDoc.QueryPageSettings += new QueryPageSettingsEventHandler(this.MyPrintQueryPageSettingsEvent);
printDoc.PrintPage += new PrintPageEventHandler(this.MyPrintPageEvent);
@@ -45,13 +45,13 @@ public Form1()
pkCustomSize2.PaperName = "Other custom size";
pkCustomSize2.Width = 100;
pkCustomSize2.Height = 200;
-
+
comboPaperSize.Items.Add(pkCustomSize2);
*/
//
- // Add list of supported paper sizes found on the printer.
+ // Add list of supported paper sizes found on the printer.
// The DisplayMember property is used to identify the property that will provide the display string.
comboPaperSize.DisplayMember = "PaperName";
@@ -62,7 +62,7 @@ public Form1()
}
// Create a PaperSize and specify the custom paper size through the constructor and add to combobox.
- PaperSize pkCustomSize1 = new PaperSize("First custom size", 100, 200);
+ PaperSize pkCustomSize1 = new("First custom size", 100, 200);
comboPaperSize.Items.Add(pkCustomSize1);
@@ -99,7 +99,7 @@ private void PopulateInstalledPrintersCombo()
{
// Add list of installed printers found to the combo box.
// The pkInstalledPrinters string will be used to provide the display string.
- String pkInstalledPrinters;
+ string pkInstalledPrinters;
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++){
pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
comboInstalledPrinters.Items.Add(pkInstalledPrinters);
@@ -111,7 +111,7 @@ private void comboInstalledPrinters_SelectionChanged(object sender, System.Event
// Set the printer to a printer in the combo box when the selection changes.
- if (comboInstalledPrinters.SelectedIndex != -1)
+ if (comboInstalledPrinters.SelectedIndex != -1)
{
// The combo box's Text property returns the selected item's text, which is the printer name.
printDoc.PrinterSettings.PrinterName= comboInstalledPrinters.Text;
@@ -126,10 +126,7 @@ protected override void Dispose( bool disposing )
{
if( disposing )
{
- if (components != null)
- {
- components.Dispose();
- }
+ components?.Dispose();
}
base.Dispose( disposing );
}
@@ -151,84 +148,84 @@ private void InitializeComponent()
this.label2 = new System.Windows.Forms.Label();
this.MyButtonPrint = new System.Windows.Forms.Button();
this.SuspendLayout();
- //
- // comboPrintResolution
- //
+ //
+ // comboPrintResolution.
+ //
this.comboPrintResolution.DropDownWidth = 121;
this.comboPrintResolution.Location = new System.Drawing.Point(104, 72);
this.comboPrintResolution.Name = "comboPrintResolution";
this.comboPrintResolution.Size = new System.Drawing.Size(121, 21);
this.comboPrintResolution.TabIndex = 3;
- //
- // label4
- //
+ //
+ // label4.
+ //
this.label4.Location = new System.Drawing.Point(8, 104);
this.label4.Name = "label4";
this.label4.TabIndex = 4;
this.label4.Text = "Installed Printers";
- //
- // comboInstalledPrinters
- //
+ //
+ // comboInstalledPrinters.
+ //
this.comboInstalledPrinters.DropDownWidth = 120;
this.comboInstalledPrinters.Location = new System.Drawing.Point(104, 104);
this.comboInstalledPrinters.Name = "comboInstalledPrinters";
this.comboInstalledPrinters.Size = new System.Drawing.Size(120, 21);
this.comboInstalledPrinters.TabIndex = 5;
this.comboInstalledPrinters.SelectedIndexChanged += new System.EventHandler(this.comboInstalledPrinters_SelectionChanged);
- //
- // label1
- //
+ //
+ // label1.
+ //
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label1.Location = new System.Drawing.Point(8, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Paper Sizes";
- //
- // label3
- //
+ //
+ // label3.
+ //
this.label3.Location = new System.Drawing.Point(8, 72);
this.label3.Name = "label3";
this.label3.TabIndex = 4;
this.label3.Text = "Printer Resolution";
- //
- // comboPaperSize
- //
+ //
+ // comboPaperSize.
+ //
this.comboPaperSize.DropDownWidth = 121;
this.comboPaperSize.Location = new System.Drawing.Point(80, 8);
this.comboPaperSize.Name = "comboPaperSize";
this.comboPaperSize.Size = new System.Drawing.Size(121, 21);
this.comboPaperSize.TabIndex = 0;
- //
- // comboPaperSource
- //
+ //
+ // comboPaperSource.
+ //
this.comboPaperSource.DropDownWidth = 121;
this.comboPaperSource.Location = new System.Drawing.Point(80, 40);
this.comboPaperSource.Name = "comboPaperSource";
this.comboPaperSource.Size = new System.Drawing.Size(121, 21);
this.comboPaperSource.TabIndex = 0;
- //
- // label2
- //
+ //
+ // label2.
+ //
this.label2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.label2.Location = new System.Drawing.Point(8, 45);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Paper Source";
- //
- // MyButtonPrint
- //
+ //
+ // MyButtonPrint.
+ //
this.MyButtonPrint.Location = new System.Drawing.Point(208, 8);
this.MyButtonPrint.Name = "MyButtonPrint";
this.MyButtonPrint.TabIndex = 2;
this.MyButtonPrint.Text = "Print";
this.MyButtonPrint.Click += new System.EventHandler(this.MyButtonPrint_Click);
- //
- // Form1
- //
+ //
+ // Form1.
+ //
this.ClientSize = new System.Drawing.Size(292, 133);
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
+ this.Controls.AddRange([
this.comboInstalledPrinters,
this.comboPrintResolution,
this.label3,
@@ -237,7 +234,7 @@ private void InitializeComponent()
this.label1,
this.comboPaperSize,
this.label2,
- this.label4});
+ this.label4]);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
@@ -248,7 +245,7 @@ private void InitializeComponent()
/// The main entry point for the application.
///
[STAThread]
- static void Main()
+ static void Main()
{
Application.Run(new Form1());
}
@@ -258,20 +255,20 @@ private void MyButtonPrint_Click(object sender, System.EventArgs e)
{
// Set the paper size based upon the selection in the combo box.
if (comboPaperSize.SelectedIndex != -1) {
- printDoc.DefaultPageSettings.PaperSize =
+ printDoc.DefaultPageSettings.PaperSize =
printDoc.PrinterSettings.PaperSizes[comboPaperSize.SelectedIndex];
}
// Set the paper source based upon the selection in the combo box.
if (comboPaperSource.SelectedIndex != -1) {
- printDoc.DefaultPageSettings.PaperSource =
+ printDoc.DefaultPageSettings.PaperSource =
printDoc.PrinterSettings.PaperSources[comboPaperSource.SelectedIndex];
}
-
+
// Set the printer resolution based upon the selection in the combo box.
- if (comboPrintResolution.SelectedIndex != -1)
+ if (comboPrintResolution.SelectedIndex != -1)
{
- printDoc.DefaultPageSettings.PrinterResolution=
+ printDoc.DefaultPageSettings.PrinterResolution=
printDoc.PrinterSettings.PrinterResolutions[comboPrintResolution.SelectedIndex];
}
@@ -285,12 +282,12 @@ private void MyButtonPrint_Click(object sender, System.EventArgs e)
private void MyButtonPrint_OnClick(object sender, System.EventArgs e)
{
-
+
// Set the printer name and ensure it is valid. If not, provide a message to the user.
printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter";
if (printDoc.PrinterSettings.IsValid) {
-
+
// If the printer supports printing in color, then override the printer's default behavior.
if (printDoc.PrinterSettings.SupportsColor) {
@@ -318,7 +315,7 @@ private void MyPrintQueryPageSettingsEvent(object sender, QueryPageSettingsEvent
e.PageSettings.Color = true;
}
- }
+ }
}
//
diff --git a/snippets/csharp/System.Drawing.Printing/PageSettings/Landscape/source.cs b/snippets/csharp/System.Drawing.Printing/PageSettings/Landscape/source.cs
index 3aba3dd6db1..170a4da3a1c 100644
--- a/snippets/csharp/System.Drawing.Printing/PageSettings/Landscape/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PageSettings/Landscape/source.cs
@@ -17,25 +17,25 @@ public void Printing() {
streamToPrint = new StreamReader (filePath);
try {
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printer;
// Set the page orientation to landscape.
pd.DefaultPageSettings.Landscape = true;
pd.Print();
- }
+ }
finally {
streamToPrint.Close() ;
}
- }
- catch(Exception ex) {
+ }
+ catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
-
+
//
- // Method added so sample will compile
+ // Method added so sample will compile.
private void pd_PrintPage(object sender,
PrintPageEventArgs e) {
}
diff --git a/snippets/csharp/System.Drawing.Printing/PageSettings/Margins/source.cs b/snippets/csharp/System.Drawing.Printing/PageSettings/Margins/source.cs
index c509cf87667..e2a2d6a0a8f 100644
--- a/snippets/csharp/System.Drawing.Printing/PageSettings/Margins/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PageSettings/Margins/source.cs
@@ -17,26 +17,26 @@ public void Printing(){
streamToPrint = new StreamReader (filePath);
try{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printer;
// Create a new instance of Margins with 1-inch margins.
- Margins margins = new Margins(100,100,100,100);
+ Margins margins = new(100,100,100,100);
pd.DefaultPageSettings.Margins = margins;
pd.Print();
- }
+ }
finally{
streamToPrint.Close() ;
}
- }
- catch(Exception ex){
+ }
+ catch(Exception ex){
MessageBox.Show(ex.Message);
}
}
-
+
//
- // Method added so sample will compile
+ // Method added so sample will compile.
private void pd_PrintPage(object sender,
PrintPageEventArgs e) {
}
diff --git a/snippets/csharp/System.Drawing.Printing/PageSettings/Overview/Form1.cs b/snippets/csharp/System.Drawing.Printing/PageSettings/Overview/Form1.cs
index 8af999e2d6a..46f572dbb08 100644
--- a/snippets/csharp/System.Drawing.Printing/PageSettings/Overview/Form1.cs
+++ b/snippets/csharp/System.Drawing.Printing/PageSettings/Overview/Form1.cs
@@ -12,11 +12,11 @@ public class Form1 : Form
private Button button1;
private ImageList imageList1;
private IContainer components;
-
+
public Form1()
{
InitializeComponent();
-
+
button1.Click += new EventHandler(button1_Click);
InitializeRadioButtons();
@@ -37,10 +37,12 @@ static void Main()
private NumericUpDown numericUpDown1;
private void InitializeAcceleratedUpDown()
{
- numericUpDown1 = new NumericUpDown();
- numericUpDown1.Location = new Point(40, 40);
- numericUpDown1.Maximum = 40000;
- numericUpDown1.Minimum = -40000;
+ numericUpDown1 = new NumericUpDown
+ {
+ Location = new Point(40, 40),
+ Maximum = 40000,
+ Minimum = -40000
+ };
// Add some accelerations to the control.
numericUpDown1.Accelerations.Add(new NumericUpDownAcceleration(2,100));
@@ -116,28 +118,30 @@ void getSelectedRB_Click(object sender, EventArgs e)
{
MessageBox.Show(selectedrb.Text);
}
-
+
//
- private System.Drawing.Printing.PrintDocument printDocument1;
- //
+ private readonly System.Drawing.Printing.PrintDocument _printDocument = new();
+ //
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
- if (e.PageSettings.Color && !printDocument1.PrinterSettings.SupportsColor)
+ if (e.PageSettings.Color && !_printDocument.PrinterSettings.SupportsColor)
+ {
MessageBox.Show("Color printing not supported on selected printer.", "Printer Warning", MessageBoxButtons.OKCancel);
+ }
}
//
- //Per VSWhidbey 370432 Demonstrates the ImageListCollection.AddStrip method.
-//
+ // Per VSWhidbey 370432, demonstrates the ImageListCollection.AddStrip method.
+ //
public void AddStripToCollection()
{
// Add the image strip.
- Bitmap bitmaps = new Bitmap(typeof(PrintPreviewDialog), "PrintPreviewStrip.bmp");
+ Bitmap bitmaps = new(typeof(PrintPreviewDialog), "PrintPreviewStrip.bmp");
imageList1.Images.AddStrip(bitmaps);
-
+
// Iterate through the images and display them on the form.
for (int i = 0; i < imageList1.Images.Count; i++) {
-
+
imageList1.Draw(this.CreateGraphics(), new Point(10,10), i);
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
@@ -151,16 +155,16 @@ private void InitializeComponent()
this.button1 = new System.Windows.Forms.Button();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
- //
- // button1
- //
+ //
+ // button1.
+ //
this.button1.Location = new System.Drawing.Point(148, 25);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
- //
- // Form1
- //
+ //
+ // Form1.
+ //
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
@@ -168,4 +172,4 @@ private void InitializeComponent()
this.ResumeLayout(false);
}
}
-}
\ No newline at end of file
+}
diff --git a/snippets/csharp/System.Drawing.Printing/PrintDocument/DefaultPageSettings/source.cs b/snippets/csharp/System.Drawing.Printing/PrintDocument/DefaultPageSettings/source.cs
index 2d564c50f74..15757a66cb9 100644
--- a/snippets/csharp/System.Drawing.Printing/PrintDocument/DefaultPageSettings/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrintDocument/DefaultPageSettings/source.cs
@@ -1,7 +1,7 @@
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
public class Form1: Form
@@ -11,7 +11,7 @@ public class Form1: Form
private Font printFont;
private StreamReader streamToPrint;
protected string filePath;
-
+
//
public void Printing()
{
@@ -21,54 +21,54 @@ public void Printing()
try
{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printer;
// Set the page orientation to landscape.
pd.DefaultPageSettings.Landscape = true;
pd.Print();
- }
+ }
finally
{
streamToPrint.Close() ;
}
- }
+ }
catch(Exception ex)
- {
+ {
MessageBox.Show(ex.Message);
}
}
-
+
//
-
+
// The PrintPage event is raised for each page to be printed.
- private void pd_PrintPage(object sender, PrintPageEventArgs ev)
+ private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
- String line=null;
-
+ string line = null;
+
// Calculate the number of lines per page.
- linesPerPage = ev.MarginBounds.Height /
+ linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
-
+
// Iterate over the file, printing each line.
- while (count < linesPerPage &&
- ((line=streamToPrint.ReadLine()) != null))
+ while (count < linesPerPage &&
+ ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
- ev.Graphics.DrawString (line, printFont, Brushes.Black,
+ ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
-
+
// If more lines exist, print another page.
- if (line != null)
+ if (line != null)
ev.HasMorePages = true;
- else
+ else
ev.HasMorePages = false;
}
}
diff --git a/snippets/csharp/System.Drawing.Printing/PrintDocument/Overview/source.cs b/snippets/csharp/System.Drawing.Printing/PrintDocument/Overview/source.cs
index 6f51430a285..9e1830b9bdd 100644
--- a/snippets/csharp/System.Drawing.Printing/PrintDocument/Overview/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrintDocument/Overview/source.cs
@@ -1,8 +1,8 @@
//
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
public partial class Form1 : System.Windows.Forms.Form
@@ -28,7 +28,7 @@ private void printButton_Click(object sender, EventArgs e)
try
{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
pd.Print();
diff --git a/snippets/csharp/System.Drawing.Printing/PrintDocument/Print/source.cs b/snippets/csharp/System.Drawing.Printing/PrintDocument/Print/source.cs
index 8f3181f089a..9d8e6b8b4be 100644
--- a/snippets/csharp/System.Drawing.Printing/PrintDocument/Print/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrintDocument/Print/source.cs
@@ -1,79 +1,79 @@
//
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
- public class PrintingExample
+ public class PrintingExample
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
- public PrintingExample()
+ public PrintingExample()
{
Printing();
}
-
+
// The PrintPage event is raised for each page to be printed.
- private void pd_PrintPage(object sender, PrintPageEventArgs ev)
+ private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
- String line=null;
-
+ string line = null;
+
// Calculate the number of lines per page.
- linesPerPage = ev.MarginBounds.Height /
+ linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
-
+
// Iterate over the file, printing each line.
- while (count < linesPerPage &&
- ((line=streamToPrint.ReadLine()) != null))
+ while (count < linesPerPage &&
+ ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
- ev.Graphics.DrawString (line, printFont, Brushes.Black,
+ ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
-
+
// If more lines exist, print another page.
- if (line != null)
+ if (line != null)
ev.HasMorePages = true;
- else
+ else
ev.HasMorePages = false;
}
-
+
// Print the file.
public void Printing()
{
- try
+ try
{
streamToPrint = new StreamReader (filePath);
- try
+ try
{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
- }
- finally
+ }
+ finally
{
streamToPrint.Close() ;
}
- }
- catch(Exception ex)
- {
+ }
+ catch(Exception ex)
+ {
MessageBox.Show(ex.Message);
}
}
-
+
// This is the main entry point for the application.
- public static void Main(string[] args)
+ public static void Main(string[] args)
{
string sampleName = Environment.GetCommandLineArgs()[0];
if(args.Length != 1)
@@ -85,5 +85,5 @@ public static void Main(string[] args)
new PrintingExample();
}
}
-
+
//
diff --git a/snippets/csharp/System.Drawing.Printing/PrintDocument/PrintController/source.cs b/snippets/csharp/System.Drawing.Printing/PrintDocument/PrintController/source.cs
index d009108c168..c97b48636ea 100644
--- a/snippets/csharp/System.Drawing.Printing/PrintDocument/PrintController/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrintDocument/PrintController/source.cs
@@ -1,7 +1,7 @@
using System;
+using System.ComponentModel;
using System.Data;
using System.Drawing.Printing;
-using System.ComponentModel;
using System.Windows.Forms;
public class Form1: Form
@@ -9,24 +9,24 @@ public class Form1: Form
protected bool useMyPrintController;
protected bool wantsStatusDialog;
protected PrintDocument myPrintDocument;
-
+
//
public void myPrint()
{
if (useMyPrintController)
{
- myPrintDocument.PrintController =
- new myControllerImplementation();
+ myPrintDocument.PrintController =
+ new myControllerImplementation();
if (wantsStatusDialog)
{
- myPrintDocument.PrintController =
+ myPrintDocument.PrintController =
new PrintControllerWithStatusDialog
(myPrintDocument.PrintController);
}
}
myPrintDocument.Print();
}
-
+
//
}
diff --git a/snippets/csharp/System.Drawing.Printing/PrintDocument/PrinterSettings/source.cs b/snippets/csharp/System.Drawing.Printing/PrintDocument/PrinterSettings/source.cs
index c79f2f59946..7192e99dea2 100644
--- a/snippets/csharp/System.Drawing.Printing/PrintDocument/PrinterSettings/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrintDocument/PrinterSettings/source.cs
@@ -1,7 +1,7 @@
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
public class Form1: Form
@@ -11,7 +11,7 @@ public class Form1: Form
private Font printFont;
private StreamReader streamToPrint;
protected static string filePath;
-
+
//
public void Printing()
{
@@ -21,53 +21,53 @@ public void Printing()
try
{
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Specify the printer to use.
pd.PrinterSettings.PrinterName = printer;
pd.Print();
- }
+ }
finally
{
streamToPrint.Close();
}
- }
+ }
catch(Exception ex)
- {
+ {
MessageBox.Show(ex.Message);
}
}
-
+
//
-
+
// The PrintPage event is raised for each page to be printed.
- private void pd_PrintPage(object sender, PrintPageEventArgs ev)
+ private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
- String line=null;
-
+ string line = null;
+
// Calculate the number of lines per page.
- linesPerPage = ev.MarginBounds.Height /
+ linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
-
+
// Iterate over the file, printing each line.
- while (count < linesPerPage &&
- ((line=streamToPrint.ReadLine()) != null))
+ while (count < linesPerPage &&
+ ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
- ev.Graphics.DrawString (line, printFont, Brushes.Black,
+ ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
-
+
// If more lines exist, print another page.
- if (line != null)
+ if (line != null)
ev.HasMorePages = true;
- else
+ else
ev.HasMorePages = false;
}
}
diff --git a/snippets/csharp/System.Drawing.Printing/PrintPageEventArgs/Overview/source.cs b/snippets/csharp/System.Drawing.Printing/PrintPageEventArgs/Overview/source.cs
index 50ae9fef35f..36d0bfe23e7 100644
--- a/snippets/csharp/System.Drawing.Printing/PrintPageEventArgs/Overview/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrintPageEventArgs/Overview/source.cs
@@ -3,42 +3,43 @@
using System.Drawing.Printing;
using System.Windows.Forms;
-public class Form1: Form
+public class Form1 : Form
{
- protected TextBox textBox1;
+ protected TextBox textBox1;
- public Form1()
+ public Form1()
{
}
-PrintDocument pd = new PrintDocument();
-//
-
-// Specifies what happens when the user clicks the Button.
- private void printButton_Click(object sender, EventArgs e)
- {
- try
- {
- // Assumes the default printer.
- pd.Print();
- }
- catch(Exception ex)
- {
- MessageBox.Show("An error occurred while printing", ex.ToString());
- }
- }
-
- // Specifies what happens when the PrintPage event is raised.
- private void pd_PrintPage(object sender, PrintPageEventArgs ev)
- {
- // Draw a picture.
- ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
-
- // Indicate that this is the last page to print.
- ev.HasMorePages = false;
- }
-
-//
+ private readonly PrintDocument _printDocument = new();
+ //
+
+ // Specifies what happens when the user clicks the Button.
+ private void printButton_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ // Assumes the default printer.
+ _printDocument.Print();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("An error occurred while printing", ex.ToString());
+ }
+ }
+
+ // Specifies what happens when the PrintPage event is raised.
+ private void pd_PrintPage(object sender, PrintPageEventArgs ev)
+ {
+ // Draw a picture.
+ using Image image = Image.FromFile(@"C:\My Folder\MyFile.bmp");
+ ev.Graphics.DrawImage(image, ev.Graphics.VisibleClipBounds);
+
+ // Indicate that this is the last page to print.
+ ev.HasMorePages = false;
+ }
+
+ //
[STAThread]
public static void Main()
diff --git a/snippets/csharp/System.Drawing.Printing/PrinterSettings/IsDefaultPrinter/Form1.cs b/snippets/csharp/System.Drawing.Printing/PrinterSettings/IsDefaultPrinter/Form1.cs
index 85ad6714dcb..63b5761a407 100644
--- a/snippets/csharp/System.Drawing.Printing/PrinterSettings/IsDefaultPrinter/Form1.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrinterSettings/IsDefaultPrinter/Form1.cs
@@ -1,48 +1,42 @@
-using System.Drawing.Printing;
-using System;
-using System.Windows.Forms;
+using System;
using System.Drawing;
+using System.Drawing.Printing;
+using System.Windows.Forms;
-public class Form1 :
- System.Windows.Forms.Form
+public class Form1 : Form
{
public static void Main()
{
Application.Run(new Form1());
}
+
public Form1()
{
- this.Load +=new EventHandler(Form1_Load);
+ Load += Form1_Load;
}
-//
- private ComboBox comboInstalledPrinters = new ComboBox();
- private PrintDocument printDoc = new PrintDocument();
+ //
+ private readonly ComboBox _comboInstalledPrinters = new();
+ private readonly PrintDocument _printDoc = new();
private void PopulateInstalledPrintersCombo()
{
- comboInstalledPrinters.Dock = DockStyle.Top;
- Controls.Add(comboInstalledPrinters);
+ _comboInstalledPrinters.Dock = DockStyle.Top;
+ Controls.Add(_comboInstalledPrinters);
// Add list of installed printers found to the combo box.
// The pkInstalledPrinters string will be used to provide the display string.
- int i;
- string pkInstalledPrinters;
-
- for (i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
+ for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
{
- pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
- comboInstalledPrinters.Items.Add(pkInstalledPrinters);
- if (printDoc.PrinterSettings.IsDefaultPrinter)
+ string pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
+ _comboInstalledPrinters.Items.Add(pkInstalledPrinters);
+ if (_printDoc.PrinterSettings.IsDefaultPrinter)
{
- comboInstalledPrinters.Text = printDoc.PrinterSettings.PrinterName;
+ _comboInstalledPrinters.Text = _printDoc.PrinterSettings.PrinterName;
}
}
}
-//
+ //
- private void Form1_Load(object sender, System.EventArgs e)
- {
- PopulateInstalledPrintersCombo();
- }
+ private void Form1_Load(object sender, EventArgs e) => PopulateInstalledPrintersCombo();
}
diff --git a/snippets/csharp/System.Drawing.Printing/PrinterSettings/Overview/source.cs b/snippets/csharp/System.Drawing.Printing/PrinterSettings/Overview/source.cs
index dce30ee549f..4b8d12b268b 100644
--- a/snippets/csharp/System.Drawing.Printing/PrinterSettings/Overview/source.cs
+++ b/snippets/csharp/System.Drawing.Printing/PrinterSettings/Overview/source.cs
@@ -1,7 +1,7 @@
using System;
-using System.IO;
using System.Drawing;
using System.Drawing.Printing;
+using System.IO;
using System.Windows.Forms;
public class Form1: Form
@@ -9,64 +9,64 @@ public class Form1: Form
private Font printFont;
private StreamReader streamToPrint;
protected static string filePath;
-
+
//
public void Printing(string printer) {
try {
streamToPrint = new StreamReader (filePath);
try {
printFont = new Font("Arial", 10);
- PrintDocument pd = new PrintDocument();
+ PrintDocument pd = new();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Specify the printer to use.
pd.PrinterSettings.PrinterName = printer;
if (pd.PrinterSettings.IsValid) {
pd.Print();
- }
- else {
+ }
+ else {
MessageBox.Show("Printer is invalid.");
}
- }
+ }
finally {
streamToPrint.Close();
}
- }
+ }
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
-
+
//
-
+
// The PrintPage event is raised for each page to be printed.
- private void pd_PrintPage(object sender, PrintPageEventArgs ev)
+ private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
- String line=null;
-
+ string line = null;
+
// Calculate the number of lines per page.
- linesPerPage = ev.MarginBounds.Height /
+ linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
-
+
// Iterate over the file, printing each line.
- while (count < linesPerPage &&
- ((line=streamToPrint.ReadLine()) != null))
+ while (count < linesPerPage &&
+ ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
- ev.Graphics.DrawString (line, printFont, Brushes.Black,
+ ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
-
+
// If more lines exist, print another page.
- if (line != null)
+ if (line != null)
ev.HasMorePages = true;
- else
+ else
ev.HasMorePages = false;
}
}