Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

//<snippet1>
using namespace System;
using namespace System::Runtime::InteropServices;

// Force the layout of your fields to the C-style struct layout.
// Without this, the .NET Framework will reorder your fields.
// Without this, .NET will reorder your fields.

[StructLayoutAttribute(LayoutKind::Sequential)]
value struct Vertex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//<Snippet1>
#using <system.dll>
#using <system.design.dll>
Expand Down Expand Up @@ -87,14 +87,14 @@
{
IDesignerHost^ host = static_cast<IDesignerHost^>(GetService( IDesignerHost::typeid ));
DesignerTransaction^ t = host->CreateTransaction( "Change Text and Size" );

/* The code within the using statement is considered to be a single transaction.
When the user selects Undo, the system will undo everything executed in this code block.
*/
if ( notification_mode )
MessageBox::Show( "Entering a Designer-Initiated Designer Transaction" );

// The .NET Framework automatically associates the TypeDescriptor with the correct component
// .NET automatically associates the TypeDescriptor with the correct component.
PropertyDescriptor^ someText = TypeDescriptor::GetProperties( Component )[ "StringProperty" ];
someText->SetValue( Component, "This text was set by the designer for this component." );
PropertyDescriptor^ anInteger = TypeDescriptor::GetProperties( Component )[ "CountProperty" ];
Expand All @@ -108,7 +108,7 @@
}

public:
property DesignerVerbCollection^ Verbs
property DesignerVerbCollection^ Verbs
{
// The Verbs property is overridden from ComponentDesigner
virtual DesignerVerbCollection^ get() override
Expand Down Expand Up @@ -167,7 +167,7 @@
}

public:
property String^ StringProperty
property String^ StringProperty
{
String^ get()
{
Expand All @@ -180,7 +180,7 @@
}
}

property int CountProperty
property int CountProperty
{
int get()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@


//<snippet1>
Expand All @@ -12,11 +12,11 @@
using namespace System::Collections;
using namespace System::Reflection;

/* This sample shows how to support code generation for a custom type of object
/* This sample shows how to support code generation for a custom type of object
using a type converter and InstanceDescriptor objects.

To use this code, copy it to a file and add the file to a project. Then add
a component to the project and declare a Triangle field and a public property
a component to the project and declare a Triangle field and a public property
with accessors for the Triangle field on the component.

The Triangle property will be persisted using code generation.
Expand All @@ -35,7 +35,7 @@

public:

property Point Point1
property Point Point1
{
Point get()
{
Expand All @@ -48,7 +48,7 @@
}
}

property Point Point2
property Point Point2
{
Point get()
{
Expand All @@ -61,7 +61,7 @@
}
}

property Point Point3
property Point Point3
{
Point get()
{
Expand All @@ -81,12 +81,11 @@
P3 = point3;
}


/* A TypeConverter for the Triangle object. Note that you can make it internal,
/* A TypeConverter for the Triangle object. Note that you can make it internal,
private, or any scope you want and the designers will still be able to use
it through the TypeDescriptor object. This type converter provides the
capability to convert to an InstanceDescriptor. This object can be used by
the .NET Framework to generate source code that creates an instance of a
capability to convert to an InstanceDescriptor. This object can be used by
.NET to generate source code that creates an instance of a
Triangle object. */
[System::Security::Permissions::PermissionSet(System::Security::
Permissions::SecurityAction::Demand, Name = "FullTrust")]
Expand All @@ -104,7 +103,7 @@
return true;
}


// Always call the base to see if it can perform the conversion.
return TypeConverter::CanConvertTo( context, destinationType );
}
Expand Down Expand Up @@ -138,7 +137,7 @@
myTriangle = gcnew Triangle( Point(5,5),Point(10,10),Point(1,8) );
}

property Triangle^ MyTriangle
property Triangle^ MyTriangle
{
Triangle^ get()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// System.CodeDom.Compiler.CompilerInfo
//
// Requires .NET Framework version 2.0 or higher.
//
// The following example displays compiler configuration settings.
// Command-line arguments are used to specify a compiler language,
// file extension, or provider type. For the given input, the
Expand Down Expand Up @@ -335,4 +333,4 @@ static void DisplayAllCompilerInfo()
}
}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@
using System.Windows.Forms.Design;

/*
This sample demonstrates how to perform a series of actions in a designer
transaction, how to change values of properties of a component from a
designer, and how to complete transactions without being interrupted
This sample demonstrates how to perform a series of actions in a designer
transaction, how to change values of properties of a component from a
designer, and how to complete transactions without being interrupted
by other activities.

To run this sample, add this code to a class library project and compile.
Create a new Windows Forms project or load a form in the designer. Add a
To run this sample, add this code to a class library project and compile.
Create a new Windows Forms project or load a form in the designer. Add a
reference to the class library that was compiled in the first step.
Right-click the Toolbox in design mode and click Customize Toolbox.
Browse to the class library that was compiled in the first step and
select OK until the DTComponent item appears in the Toolbox. Add an
instance of this component to the form.
Right-click the Toolbox in design mode and click Customize Toolbox.
Browse to the class library that was compiled in the first step and
select OK until the DTComponent item appears in the Toolbox. Add an
instance of this component to the form.

When the component is created and added to the component tray for your
design project, the Initialize method of the designer is called.
design project, the Initialize method of the designer is called.
This method displays a message box informing you that designer transaction
event handlers will be registered unless you click Cancel. When you set
properties in the properties window, each change will be encapsulated in
a designer transaction, allowing the change to be undone later.
When you right-click the component, the shortcut menu for the component
is displayed. The designer constructs this menu according to whether
event handlers will be registered unless you click Cancel. When you set
properties in the properties window, each change will be encapsulated in
a designer transaction, allowing the change to be undone later.

When you right-click the component, the shortcut menu for the component
is displayed. The designer constructs this menu according to whether
designer transaction notifications are enabled, and offers the option
of enabling or disabling the notifications, depending on the current
mode. The shortcut menu also presents a Perform Example Transaction
item, which will set the values of the component's StringProperty and
CountProperty properties. You can undo the last designer transaction using
of enabling or disabling the notifications, depending on the current
mode. The shortcut menu also presents a Perform Example Transaction
item, which will set the values of the component's StringProperty and
CountProperty properties. You can undo the last designer transaction using
the Undo command provided by the Visual Studio development environment.
*/

Expand All @@ -44,7 +44,7 @@ public class DTComponent : System.ComponentModel.Component
{
private string m_String;
private int m_Count;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string StringProperty
{
Expand All @@ -53,7 +53,7 @@ public string StringProperty
set
{ m_String = value; }
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int CountProperty
{
Expand All @@ -69,50 +69,50 @@ private void InitializeComponent()
m_Count = 0;
}
}

internal class DTDesigner : ComponentDesigner
{
private bool notification_mode = false;
private int count = 10;

// The Verbs property is overridden from ComponentDesigner
public override DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection dvc = new DesignerVerbCollection();
{
DesignerVerbCollection dvc = new DesignerVerbCollection();
dvc.Add( new DesignerVerb("Perform Example Transaction", new EventHandler(this.DoTransaction)) );
if(notification_mode)
dvc.Add(new DesignerVerb("End Designer Transaction Notifications", new EventHandler(this.UnlinkDTNotifications)));
else
dvc.Add(new DesignerVerb("Show Designer Transaction Notifications", new EventHandler(this.LinkDTNotifications))); return dvc;
}
}

public override void Initialize(System.ComponentModel.IComponent component)
{
base.Initialize(component);

IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if(host == null)
{
MessageBox.Show("The IDesignerHost service interface could not be obtained.");
return;
}

if( MessageBox.Show("Press the Yes button to display notification message boxes for the designer transaction opened and closed notifications.","Link DesignerTransaction Notifications?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign) == DialogResult.Yes )
{
{
host.TransactionOpened += new EventHandler(OnDesignerTransactionOpened);
host.TransactionClosed += new DesignerTransactionCloseEventHandler(OnDesignerTransactionClosed);
notification_mode = true;
}
}

private void LinkDTNotifications(object sender, EventArgs e)
{
if(!notification_mode)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if(host != null)
{
notification_mode = true;
Expand All @@ -126,9 +126,9 @@ private void UnlinkDTNotifications(object sender, EventArgs e)
{
if(notification_mode)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
if(host != null)
{
{
notification_mode = false;
host.TransactionOpened -= new EventHandler(OnDesignerTransactionOpened);
host.TransactionClosed -= new DesignerTransactionCloseEventHandler(OnDesignerTransactionClosed);
Expand All @@ -137,18 +137,18 @@ private void UnlinkDTNotifications(object sender, EventArgs e)
}

private void OnDesignerTransactionOpened(object sender, EventArgs e)
{
{
System.Windows.Forms.MessageBox.Show("A Designer Transaction was started. (TransactionOpened)");
}

private void OnDesignerTransactionClosed(object sender, DesignerTransactionCloseEventArgs e)
{
{
System.Windows.Forms.MessageBox.Show("A Designer Transaction was completed. (TransactionClosed)");
}
}

private void DoTransaction(object sender, EventArgs e)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
private void DoTransaction(object sender, EventArgs e)
{
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
DesignerTransaction t = host.CreateTransaction("Change Text and Size");

/* The code within the using statement is considered to be a single transaction.
Expand All @@ -157,8 +157,8 @@ private void DoTransaction(object sender, EventArgs e)
{
if(notification_mode)
System.Windows.Forms.MessageBox.Show("Entering a Designer-Initiated Designer Transaction");
// The .NET Framework automatically associates the TypeDescriptor with the correct component

// .NET automatically associates the TypeDescriptor with the correct component.
PropertyDescriptor someText = TypeDescriptor.GetProperties(Component)["StringProperty"];
someText.SetValue(Component, "This text was set by the designer for this component.");

Expand All @@ -168,17 +168,17 @@ private void DoTransaction(object sender, EventArgs e)

// Complete the designer transaction.
t.Commit();

if(notification_mode)
System.Windows.Forms.MessageBox.Show("Designer-Initiated Designer Transaction Completed");
}
}

protected override void Dispose(bool disposing)
{
UnlinkDTNotifications(this, new EventArgs());
base.Dispose(disposing);
}
}
}
//</Snippet1>
//</Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
using System.Reflection;

namespace Microsoft.Samples.InstanceDescriptorSample;
// This sample shows how to support code generation for a custom type
// This sample shows how to support code generation for a custom type
// of object using a type converter and InstanceDescriptor objects.

// To use this code, copy it to a file and add the file to a project.
// Then add a component to the project and declare a Triangle field and
// To use this code, copy it to a file and add the file to a project.
// Then add a component to the project and declare a Triangle field and
// a public property with accessors for the Triangle field on the component.

// The Triangle property will be persisted using code generation.
Expand Down Expand Up @@ -45,11 +45,11 @@ public Triangle(Point point1, Point point2, Point point3)
P3 = point3;
}

// A TypeConverter for the Triangle object. Note that you can make it internal,
// A TypeConverter for the Triangle object. Note that you can make it internal,
// private, or any scope you want and the designers will still be able to use
// it through the TypeDescriptor object. This type converter provides the
// capability to convert to an InstanceDescriptor. This object can be used by
// the .NET Framework to generate source code that creates an instance of a
// it through the TypeDescriptor object.This type converter provides the
// capability to convert to an InstanceDescriptor.This object can be used by
// .NET to generate source code that creates an instance of a
// Triangle object.
internal class TriangleConverter : TypeConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>library</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
Loading
Loading