diff --git a/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Program.cs b/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Program.cs index 3ce84b23eff..adacd68e03b 100644 --- a/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Program.cs +++ b/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Program.cs @@ -1,30 +1,13 @@ // -using System; -using System.Collections.Generic; -using System.Text; - namespace DSMSample { // - public class SampleObject + public class SampleObject2 { - private string stringValue = null; - private int intValue = int.MinValue; - - public string StringProperty - { - get { return this.stringValue; } - - set { this.stringValue = value; } - } - - public int IntProperty - { - get { return this.intValue; } + public string StringProperty { get; set; } - set{ this.intValue = value; } - } + public int IntProperty { get; set; } = int.MinValue; } // } -// \ No newline at end of file +// diff --git a/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Project.csproj b/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Project.csproj new file mode 100644 index 00000000000..a15a29bf12c --- /dev/null +++ b/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/Project.csproj @@ -0,0 +1,8 @@ + + + + Exe + net10.0 + + + diff --git a/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/SampleObject.cs b/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/SampleObject.cs index 4a51e86e13c..0beb95e6e16 100644 --- a/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/SampleObject.cs +++ b/snippets/csharp/System.ComponentModel.Design.Serialization/DesignerSerializationManager/Overview/SampleObject.cs @@ -1,37 +1,14 @@ // -using System; -using System.Collections.Generic; -using System.Text; - namespace DSMSample { // public class SampleObject { - private string stringValue = null; - private int intValue = int.MinValue; - private SampleObject childValue = null; - - public string StringProperty - { - get { return this.stringValue; } + public string StringProperty { get; set; } - set { this.stringValue = value; } - } - - public int IntProperty - { - get { return this.intValue; } + public int IntProperty { get; set; } = int.MinValue; - set { this.intValue = value; } - } - - public SampleObject Child - { - get { return this.childValue; } - - set { this.childValue = value; } - } + public SampleObject Child { get; set; } } // @@ -39,16 +16,16 @@ public SampleObject Child class Program { // - static void Main(string[] args) + static void Main() { // - SampleObject root = new SampleObject(); + SampleObject root = new(); SampleObject currentObject = root; for (int i = 0; i < 10; i++) { - SampleObject o = new SampleObject(); + SampleObject o = new(); currentObject.Child = o; @@ -60,4 +37,4 @@ static void Main(string[] args) } // } -// \ No newline at end of file +// diff --git a/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/Project.csproj b/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/class1.cs b/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/class1.cs index 6f1ba332e2c..05c81496464 100644 --- a/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/class1.cs +++ b/snippets/csharp/System.ComponentModel.Design/CollectionEditor/Overview/class1.cs @@ -1,109 +1,56 @@ -using System; -using System.Collections; +using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Drawing.Design; -using System.Web.UI.Design; using System.Windows.Forms; -using System.Windows.Forms.Design; -namespace EditorAttributeExamples +namespace EditorExamples { - public class Class1 : System.ComponentModel.Component + public class Class1 : Component { - // System.ComponentModel.Design.CollectionEditor EditorAttribute example + // System.ComponentModel.Design.CollectionEditor Editor example. // - [EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))] - public ICollection testCollection - { - get - { - return Icollection; - } - set - { - Icollection = value; - } - } - private ICollection Icollection; + [Editor(typeof(CollectionEditor), typeof(UITypeEditor))] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] + public ICollection testCollection { get; set; } // - // System.Drawing.Design.FontEditor EditorAttribute example + // FontEditor Editor example. // - [EditorAttribute(typeof(System.Drawing.Design.FontEditor), typeof(System.Drawing.Design.UITypeEditor))] - public Font testFont - { - get - { - return font; - } - set - { - font = value; - } - } - private Font font; + [Editor(typeof(FontEditor), typeof(UITypeEditor))] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Font testFont { get; set; } // - // System.Drawing.Design.ImageEditor EditorAttribute example + // ImageEditor Editor example. // - [EditorAttribute(typeof(System.Drawing.Design.ImageEditor), typeof(System.Drawing.Design.UITypeEditor))] - public Image testImage - { - get - { - return testImg; - } - set - { - testImg = value; - } - } - private Image testImg; + [Editor(typeof(ImageEditor), typeof(UITypeEditor))] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public Image testImage { get; set; } // - // System.Windows.Forms.Design.AnchorEditor EditorAttribute example + // System.Windows.Forms.Design.AnchorEditor Editor example. // - [EditorAttribute(typeof(System.Windows.Forms.Design.AnchorEditor), typeof(System.Drawing.Design.UITypeEditor))] - public System.Windows.Forms.AnchorStyles testAnchor - { - get - { - return anchor; - } - set - { - anchor = value; - } - } - private AnchorStyles anchor; + [Editor(typeof(System.Windows.Forms.Design.AnchorEditor), typeof(UITypeEditor))] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public AnchorStyles testAnchor { get; set; } // - // System.Windows.Forms.Design.FileNameEditor EditorAttribute example + // System.Windows.Forms.Design.FileNameEditor Editor example. // - [EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] - public string testFilename - { - get - { - return filename; - } - set - { - filename = value; - } - } - private string filename; + [Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(UITypeEditor))] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public string testFilename { get; set; } // public Class1() { // Initialize collections for design-mode editor testing. - Icollection = new int[] { 0, 2, 4, 6, 8, 12, 14 }; - font = new Font("Arial", 8); + testCollection = new int[] { 0, 2, 4, 6, 8, 12, 14 }; + testFont = new("Arial", 8); testAnchor = AnchorStyles.None; - filename = string.Empty; + testFilename = string.Empty; } } } diff --git a/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/Project.csproj b/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/Project.csproj new file mode 100644 index 00000000000..4a6d98d26b7 --- /dev/null +++ b/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/Project.csproj @@ -0,0 +1,9 @@ + + + + Exe + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/form1.cs b/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/form1.cs index 600b196ad28..7fa4d4d28b5 100644 --- a/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/form1.cs +++ b/snippets/csharp/System.ComponentModel/AddingNewEventArgs/Overview/form1.cs @@ -1,29 +1,25 @@ // // using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Data.SqlClient; using System.Windows.Forms; // // // This form demonstrates using a BindingSource to provide // data from a collection of custom types to a DataGridView control. -public class Form1 : System.Windows.Forms.Form +public class Form1 : Form { // // This is the BindingSource that will provide data for // the DataGridView control. - private BindingSource customersBindingSource = new BindingSource(); + private BindingSource customersBindingSource = []; // This is the DataGridView control that will display our data. - private DataGridView customersDataGridView = new DataGridView(); + private DataGridView customersDataGridView = new(); - // Set up the StatusBar for displaying ListChanged events. - private StatusBar status = new StatusBar(); + // Set up the StatusStrip for displaying ListChanged events. + private StatusStrip status = new(); // @@ -31,52 +27,49 @@ public class Form1 : System.Windows.Forms.Form public Form1() { // Set up the form. - this.Size = new Size(800, 800); - this.Load += new EventHandler(Form1_Load); - this.Controls.Add(status); + Size = new(800, 800); + Load += new EventHandler(Form1_Load); + Controls.Add(status); // Set up the DataGridView control. - this.customersDataGridView.Dock = DockStyle.Fill; - this.Controls.Add(customersDataGridView); + customersDataGridView.Dock = DockStyle.Fill; + Controls.Add(customersDataGridView); // Attach an event handler for the AddingNew event. - this.customersBindingSource.AddingNew += + customersBindingSource.AddingNew += new AddingNewEventHandler(customersBindingSource_AddingNew); // Attach an event handler for the ListChanged event. - this.customersBindingSource.ListChanged += + customersBindingSource.ListChanged += new ListChangedEventHandler(customersBindingSource_ListChanged); } // // - private void Form1_Load(System.Object sender, System.EventArgs e) + private void Form1_Load(object sender, EventArgs e) { // Add a DemoCustomer to cause a row to be displayed. - this.customersBindingSource.AddNew(); + customersBindingSource.AddNew(); - // Bind the BindingSource to the DataGridView + // Bind the BindingSource to the DataGridView // control's DataSource. - this.customersDataGridView.DataSource = - this.customersBindingSource; + customersDataGridView.DataSource = customersBindingSource; } // // // This event handler provides custom item-creation behavior. - void customersBindingSource_AddingNew( - object sender, - AddingNewEventArgs e) + void customersBindingSource_AddingNew(object sender, AddingNewEventArgs e) { e.NewObject = DemoCustomer.CreateNewCustomer(); } // // - // This event handler detects changes in the BindingSource + // This event handler detects changes in the BindingSource // list or changes to items within the list. void customersBindingSource_ListChanged( - object sender, + object sender, ListChangedEventArgs e) { status.Text = e.ListChangedType.ToString(); @@ -96,18 +89,12 @@ static void Main() // This class implements a simple customer type. public class DemoCustomer { - // These fields hold the values for the public properties. - private Guid idValue = Guid.NewGuid(); - private string customerName = String.Empty; - private string companyNameValue = String.Empty; - private string phoneNumberValue = String.Empty; - // The constructor is private to enforce the factory pattern. private DemoCustomer() { - customerName = "no data"; - companyNameValue = "no data"; - phoneNumberValue = "no data"; + CustomerName = "no data"; + CompanyName = "no data"; + PhoneNumber = "no data"; } // This is the public factory method. @@ -118,39 +105,13 @@ public static DemoCustomer CreateNewCustomer() // This property represents an ID, suitable // for use as a primary key in a database. - public Guid ID - { - get - { - return this.idValue; - } - } + public Guid ID { get; } = Guid.NewGuid(); - public string CompanyName - { - get - { - return this.companyNameValue; - } - - set - { - this.companyNameValue = value; - } - } + public string CustomerName { get; set; } = string.Empty; - public string PhoneNumber - { - get - { - return this.phoneNumberValue; - } - - set - { - this.phoneNumberValue = value; - } - } + public string CompanyName { get; set; } = string.Empty; + + public string PhoneNumber { get; set; } = string.Empty; } // -// \ No newline at end of file +// diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/Project.csproj b/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source.cs b/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source.cs index d14a77e3b58..371f6f9b529 100644 --- a/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source.cs +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source.cs @@ -1,25 +1,21 @@ -using System; -using System.Windows.Forms; using System.ComponentModel; +using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected Button button1; - protected TextBox textBox1; -// -private void ContainsAttribute() { - // Creates a new collection and assigns it the attributes for button1. - AttributeCollection attributes; - attributes = TypeDescriptor.GetAttributes(button1); - - // Sets an Attribute to the specific attribute. - BrowsableAttribute myAttribute = BrowsableAttribute.Yes; + protected Button button1; + protected TextBox textBox1; + // + void ContainsAttribute() + { + // Creates a new collection and assigns it the attributes for button1. + AttributeCollection attributes; + attributes = TypeDescriptor.GetAttributes(button1); - if (attributes.Contains(myAttribute)) - textBox1.Text = "button1 has a browsable attribute."; - else - textBox1.Text = "button1 does not have a browsable attribute."; - } + // Sets an Attribute to the specific attribute. + BrowsableAttribute myAttribute = BrowsableAttribute.Yes; -// + textBox1.Text = attributes.Contains(myAttribute) ? "button1 has a browsable attribute." : "button1 does not have a browsable attribute."; + } + // } diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source1.cs b/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source1.cs index 5d7b0296298..67328d47267 100644 --- a/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source1.cs +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Contains/source1.cs @@ -1,24 +1,22 @@ -using System; -using System.Windows.Forms; +using System; using System.ComponentModel; +using System.Windows.Forms; -public class Form1: Form +public class Form2 : Form { - protected Button button1; - protected TextBox textBox1; -// - private void ContainsAttributes() { - // Creates a new collection and assigns it the attributes for button1. - AttributeCollection myCollection; - myCollection = TypeDescriptor.GetAttributes(button1); + protected Button button1; + protected TextBox textBox1; + // + void ContainsAttributes() + { + // Creates a new collection and assigns it the attributes for button1. + AttributeCollection myCollection; + myCollection = TypeDescriptor.GetAttributes(button1); - // Checks to see whether the attributes in myCollection are the attributes for textBox1. - Attribute[] myAttrArray = new Attribute[100]; - TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0); - if (myCollection.Contains(myAttrArray)) - textBox1.Text = "Both the button and text box have the same attributes."; - else - textBox1.Text = "The button and the text box do not have the same attributes."; - } -// + // Checks to see whether the attributes in myCollection are the attributes for textBox1. + Attribute[] myAttrArray = new Attribute[100]; + TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0); + textBox1.Text = myCollection.Contains(myAttrArray) ? "Both the button and text box have the same attributes." : "The button and the text box do not have the same attributes."; + } + // } diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Item/Project.csproj b/snippets/csharp/System.ComponentModel/AttributeCollection/Item/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Item/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source.cs b/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source.cs index 4a599016a08..17b9baa5b6d 100644 --- a/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source.cs +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source.cs @@ -1,20 +1,20 @@ -using System; +using System.ComponentModel; using System.Windows.Forms; -using System.ComponentModel; -public class Form1: Form +public class Form1 : Form { - protected Button button1; - protected TextBox textBox1; -// -private void PrintIndexItem() { - // Creates a new collection and assigns it the attributes for button1. - AttributeCollection attributes; - attributes = TypeDescriptor.GetAttributes(button1); + protected Button button1; + protected TextBox textBox1; - // Prints the second attribute's name. - textBox1.Text = attributes[1].ToString(); - } + // + void PrintIndexItem() + { + // Creates a new collection and assigns it the attributes for button1. + AttributeCollection attributes; + attributes = TypeDescriptor.GetAttributes(button1); -// + // Prints the second attribute's name. + textBox1.Text = attributes[1].ToString(); + } + // } diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source1.cs b/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source1.cs index 450c9a08e7a..58500be0516 100644 --- a/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source1.cs +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Item/source1.cs @@ -1,23 +1,23 @@ using System; -using System.Windows.Forms; using System.ComponentModel; +using System.Windows.Forms; -public class Form1: Form +public class Form2 : Form { - protected Button button1; - protected TextBox textBox1; -// -private void PrintIndexItem2() { - // Creates a new collection and assigns it the attributes for button1. - AttributeCollection attributes; - attributes = TypeDescriptor.GetAttributes(button1); - - // Gets the designer attribute from the collection. - DesignerAttribute myDesigner; - // You must supply a valid fully qualified assembly name here. - myDesigner = (DesignerAttribute)attributes[Type.GetType("Assembly text name, Version, Culture, PublicKeyToken")]; - textBox1.Text = myDesigner.DesignerTypeName; - } + protected Button button1; + protected TextBox textBox1; + + // + void PrintIndexItem2() + { + // Creates a new collection and assigns it the attributes for button1. + AttributeCollection attributes; + attributes = TypeDescriptor.GetAttributes(button1); -// + // Gets the designer attribute from the collection. + DesignerAttribute myDesigner; + myDesigner = (DesignerAttribute)attributes[typeof(DesignerAttribute)]; + textBox1.Text = myDesigner.DesignerTypeName; + } + // } diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/Project.csproj b/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source.cs b/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source.cs index d626cf61b7c..3d1bd15c4b4 100644 --- a/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source.cs +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source.cs @@ -1,23 +1,19 @@ -using System; -using System.Windows.Forms; using System.ComponentModel; +using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected Button button1; - protected TextBox textBox1; -// -private void MatchesAttribute() { - // Creates a new collection and assigns it the attributes for button1. - AttributeCollection attributes; - attributes = TypeDescriptor.GetAttributes(button1); - - // Checks to see if the browsable attribute is true. - if (attributes.Matches(BrowsableAttribute.Yes)) - textBox1.Text = "button1 is browsable."; - else - textBox1.Text = "button1 is not browsable."; - } + protected Button button1; + protected TextBox textBox1; + // + void MatchesAttribute() + { + // Creates a new collection and assigns it the attributes for button1. + AttributeCollection attributes; + attributes = TypeDescriptor.GetAttributes(button1); -// + // Checks to see if the browsable attribute is true. + textBox1.Text = attributes.Matches(BrowsableAttribute.Yes) ? "button1 is browsable." : "button1 is not browsable."; + } + // } diff --git a/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source1.cs b/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source1.cs index 9d9b2345296..997924abb7b 100644 --- a/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source1.cs +++ b/snippets/csharp/System.ComponentModel/AttributeCollection/Matches/source1.cs @@ -1,25 +1,22 @@ -using System; -using System.Windows.Forms; +using System; using System.ComponentModel; +using System.Windows.Forms; -public class Form1: Form +public class Form2 : Form { - protected Button button1; - protected TextBox textBox1; - -// - private void MatchesAttributes() { - // Creates a new collection and assigns it the attributes for button1. - AttributeCollection myCollection; - myCollection = TypeDescriptor.GetAttributes(button1); + protected Button button1; + protected TextBox textBox1; + // + void MatchesAttributes() + { + // Creates a new collection and assigns it the attributes for button1. + AttributeCollection myCollection; + myCollection = TypeDescriptor.GetAttributes(button1); - // Checks to see whether the attributes in myCollection match the attributes for textBox1. - Attribute[] myAttrArray = new Attribute[100]; - TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0); - if (myCollection.Matches(myAttrArray)) - textBox1.Text = "The attributes in the button and text box match."; - else - textBox1.Text = "The attributes in the button and text box do not match."; - } -// + // Checks to see whether the attributes in myCollection match the attributes for textBox1. + Attribute[] myAttrArray = new Attribute[100]; + TypeDescriptor.GetAttributes(textBox1).CopyTo(myAttrArray, 0); + textBox1.Text = myCollection.Matches(myAttrArray) ? "The attributes in the button and text box match." : "The attributes in the button and text box do not match."; + } + // } diff --git a/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/Project.csproj b/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source.cs b/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source.cs index b9ae03dabad..09d1973c80c 100644 --- a/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source.cs +++ b/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source.cs @@ -1,21 +1,21 @@ -using System; using System.ComponentModel; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected TextBox textBox1; -// -[Bindable(true)] - public int MyProperty { - get { - // Insert code here. - return 0; + protected TextBox textBox1; + // + [Bindable(true)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public int MyProperty + { + get => + // Insert code here. + 0; + set + { + // Insert code here. + } } - set { - // Insert code here. - } - } - -// + // } diff --git a/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source1.cs b/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source1.cs index bdbd7fb7fea..b0466ada2fe 100644 --- a/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source1.cs +++ b/snippets/csharp/System.ComponentModel/BindableAttribute/.ctor/source1.cs @@ -1,21 +1,21 @@ -using System; using System.ComponentModel; using System.Windows.Forms; -public class Form1: Form +public class Form2 : Form { - protected TextBox textBox1; -// -[Bindable(BindableSupport.Yes)] - public int MyProperty { - get { - // Insert code here. - return 0; + protected TextBox textBox1; + // + [Bindable(BindableSupport.Yes)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] + public int MyProperty + { + get => + // Insert code here. + 0; + set + { + // Insert code here. + } } - set { - // Insert code here. - } - } - -// + // } diff --git a/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/EventExamples.cs b/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/EventExamples.cs index 340d22288c8..b9753eb6964 100644 --- a/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/EventExamples.cs +++ b/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/EventExamples.cs @@ -784,14 +784,12 @@ private void ApplicationContext1_ThreadExit(Object sender, EventArgs e) { // // -private void AutoCompleteStringCollection1_CollectionChanged(Object sender, CollectionChangeEventArgs e) { - -System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); -messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action ); -messageBoxCS.AppendLine(); -messageBoxCS.AppendFormat("{0} = {1}", "Element", e.Element ); -messageBoxCS.AppendLine(); -MessageBox.Show(messageBoxCS.ToString(), "CollectionChanged Event" ); +private void AutoCompleteStringCollection1_CollectionChanged(object sender, CollectionChangeEventArgs e) +{ + System.Text.StringBuilder messageBoxCS = new(); + messageBoxCS.AppendLine($"Action = {e.Action}"); + messageBoxCS.AppendLine($"Element = {e.Element}"); + MessageBox.Show(messageBoxCS.ToString(), "CollectionChanged Event"); } // @@ -1378,18 +1376,14 @@ private void BindingSource1_CurrentItemChanged(Object sender, EventArgs e) { // // -private void BindingSource1_ListChanged(Object sender, ListChangedEventArgs e) { - -System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); -messageBoxCS.AppendFormat("{0} = {1}", "ListChangedType", e.ListChangedType ); -messageBoxCS.AppendLine(); -messageBoxCS.AppendFormat("{0} = {1}", "NewIndex", e.NewIndex ); -messageBoxCS.AppendLine(); -messageBoxCS.AppendFormat("{0} = {1}", "OldIndex", e.OldIndex ); -messageBoxCS.AppendLine(); -messageBoxCS.AppendFormat("{0} = {1}", "PropertyDescriptor", e.PropertyDescriptor ); -messageBoxCS.AppendLine(); -MessageBox.Show(messageBoxCS.ToString(), "ListChanged Event" ); +private void BindingSource1_ListChanged(object sender, ListChangedEventArgs e) +{ + System.Text.StringBuilder messageBoxCS = new(); + messageBoxCS.AppendLine($"ListChangedType = {e.ListChangedType}"); + messageBoxCS.AppendLine($"NewIndex = {e.NewIndex}"); + messageBoxCS.AppendLine($"OldIndex = {e.OldIndex}"); + messageBoxCS.AppendLine($"PropertyDescriptor = {e.PropertyDescriptor}"); + MessageBox.Show(messageBoxCS.ToString(), "ListChanged Event"); } // @@ -6303,14 +6297,12 @@ private void PictureBox1_LoadCompleted(Object sender, AsyncCompletedEventArgs e) // // -private void PictureBox1_LoadProgressChanged(Object sender, ProgressChangedEventArgs e) { - -System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); -messageBoxCS.AppendFormat("{0} = {1}", "ProgressPercentage", e.ProgressPercentage ); -messageBoxCS.AppendLine(); -messageBoxCS.AppendFormat("{0} = {1}", "UserState", e.UserState ); -messageBoxCS.AppendLine(); -MessageBox.Show(messageBoxCS.ToString(), "LoadProgressChanged Event" ); +private void PictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e) +{ + System.Text.StringBuilder messageBoxCS = new(); + messageBoxCS.AppendLine($"ProgressPercentage = {e.ProgressPercentage}"); + messageBoxCS.AppendLine($"UserState = {e.UserState}"); + MessageBox.Show(messageBoxCS.ToString(), "LoadProgressChanged Event"); } // diff --git a/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/Project.csproj b/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/Project.csproj new file mode 100644 index 00000000000..4a6d98d26b7 --- /dev/null +++ b/snippets/csharp/System.ComponentModel/CollectionChangeEventArgs/Overview/Project.csproj @@ -0,0 +1,9 @@ + + + + Exe + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/Project.csproj b/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source.cs b/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source.cs index 1d8a9c48beb..62dadfcdac8 100644 --- a/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source.cs +++ b/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source.cs @@ -1,20 +1,18 @@ -using System; -using System.Data; using System.ComponentModel; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected TextBox textBox1; - protected Button button1; -// -private void PrintIndexItem() { - // Creates a new collection and assigns it the events for button1. - EventDescriptorCollection events = TypeDescriptor.GetEvents(button1); - - // Prints the second event's name. - textBox1.Text = events[1].ToString(); - } + protected TextBox textBox1; + protected Button button1; + // + void PrintIndexItem() + { + // Creates a new collection and assigns it the events for button1. + EventDescriptorCollection events = TypeDescriptor.GetEvents(button1); -// + // Prints the second event's name. + textBox1.Text = events[1].ToString(); + } + // } diff --git a/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source1.cs b/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source1.cs index e1ed38edb4a..a17d6d56114 100644 --- a/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source1.cs +++ b/snippets/csharp/System.ComponentModel/EventDescriptorCollection/Item/source1.cs @@ -1,23 +1,21 @@ -using System; -using System.Data; using System.ComponentModel; using System.Windows.Forms; -public class Form1: Form +public class Form2 : Form { - protected TextBox textBox1; - protected Button button1; -// -private void PrintIndexItem2() { - // Creates a new collection and assigns it the events for button1. - EventDescriptorCollection events = TypeDescriptor.GetEvents(button1); - - // Sets an EventDescriptor to the specific event. - EventDescriptor myEvent = events["KeyDown"]; - - // Prints the name of the event. - textBox1.Text = myEvent.Name; - } + protected TextBox textBox1; + protected Button button1; + // + void PrintIndexItem2() + { + // Creates a new collection and assigns it the events for button1. + EventDescriptorCollection events = TypeDescriptor.GetEvents(button1); -// + // Sets an EventDescriptor to the specific event. + EventDescriptor myEvent = events["KeyDown"]; + + // Prints the name of the event. + textBox1.Text = myEvent.Name; + } + // } diff --git a/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Form1.cs b/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Form1.cs index 673b532727f..d004b3523ca 100644 --- a/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Form1.cs +++ b/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Form1.cs @@ -1,6 +1,5 @@ -// +// using System; -using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Runtime.CompilerServices; @@ -13,21 +12,19 @@ namespace TestNotifyPropertyChangedCS // a list to a DataGridView control. The list does not // raise change notifications. However the DemoCustomer type // in the list does. - public partial class Form1 : Form + public class Form1 : Form { // This button causes the value of a list element to be changed. - private Button changeItemBtn = new Button(); + private Button changeItemBtn = new(); // This DataGridView control displays the contents of the list. - private DataGridView customersDataGridView = new DataGridView(); + private DataGridView customersDataGridView = new(); // This BindingSource binds the list to the DataGridView control. - private BindingSource customersBindingSource = new BindingSource(); + private BindingSource customersBindingSource = new(); public Form1() { - InitializeComponent(); - // Set up the "Change Item" button. this.changeItemBtn.Text = "Change Item"; this.changeItemBtn.Dock = DockStyle.Bottom; @@ -39,14 +36,14 @@ public Form1() customersDataGridView.Dock = DockStyle.Top; this.Controls.Add(customersDataGridView); - this.Size = new Size(400, 200); + this.Size = new(400, 200); } private void Form1_Load(object sender, EventArgs e) { // Create and populate the list of DemoCustomer objects // which will supply data to the DataGridView. - BindingList customerList = new BindingList(); + BindingList customerList = new(); customerList.Add(DemoCustomer.CreateNewCustomer()); customerList.Add(DemoCustomer.CreateNewCustomer()); customerList.Add(DemoCustomer.CreateNewCustomer()); @@ -80,7 +77,6 @@ void changeItemBtn_Click(object sender, EventArgs e) public class DemoCustomer : INotifyPropertyChanged { // These fields hold the values for the public properties. - private Guid idValue = Guid.NewGuid(); private string customerNameValue = string.Empty; private string phoneNumberValue = string.Empty; @@ -112,20 +108,11 @@ public static DemoCustomer CreateNewCustomer() // This property represents an ID, suitable // for use as a primary key in a database. - public Guid ID - { - get - { - return this.idValue; - } - } + public Guid ID { get; } = Guid.NewGuid(); public string CustomerName { - get - { - return this.customerNameValue; - } + get => this.customerNameValue; set { @@ -139,10 +126,7 @@ public string CustomerName public string PhoneNumber { - get - { - return this.phoneNumberValue; - } + get => this.phoneNumberValue; set { diff --git a/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Project.csproj b/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/INotifyPropertyChanged/PropertyChanged/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/Project.csproj b/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/Project.csproj new file mode 100644 index 00000000000..b62ae7deede --- /dev/null +++ b/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/Project.csproj @@ -0,0 +1,9 @@ + + + + Library + net10.0-windows + true + + + diff --git a/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source.cs b/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source.cs index b7c24b97ae0..1d51b215003 100644 --- a/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source.cs +++ b/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source.cs @@ -1,20 +1,18 @@ -using System; -using System.Data; using System.ComponentModel; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected Button button1; - protected TextBox textBox1; -// -private void PrintIndexItem() { - // Creates a new collection and assigns it the properties for button1. - PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1); - - // Prints the second property's name. - textBox1.Text = properties[1].ToString(); - } + protected Button button1; + protected TextBox textBox1; + // + void PrintIndexItem() + { + // Creates a new collection and assigns it the properties for button1. + PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1); -// + // Prints the second property's name. + textBox1.Text = properties[1].ToString(); + } + // } diff --git a/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source1.cs b/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source1.cs index 000c5afd8c0..f9ef3f205d3 100644 --- a/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source1.cs +++ b/snippets/csharp/System.ComponentModel/PropertyDescriptorCollection/Item/source1.cs @@ -1,24 +1,21 @@ -using System; -using System.Data; using System.ComponentModel; using System.Windows.Forms; -public class Form1: Form +public class Form2 : Form { - protected Button button1; - protected TextBox textBox1; -// - private void PrintIndexItem2() { - // Creates a new collection and assigns it the properties for button1. - PropertyDescriptorCollection properties = - TypeDescriptor.GetProperties(button1); - - // Sets a PropertyDescriptor to the specific property. - PropertyDescriptor myProperty = properties["Opacity"]; - - // Prints the display name for the property. - textBox1.Text = myProperty.DisplayName; - } + protected Button button1; + protected TextBox textBox1; + // + void PrintIndexItem2() + { + // Creates a new collection and assigns it the properties for button1. + PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1); -// + // Sets a PropertyDescriptor to the specific property. + PropertyDescriptor myProperty = properties["Opacity"]; + + // Prints the display name for the property. + textBox1.Text = myProperty.DisplayName; + } + // }