Initial winforms content migrated (#18)

* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
This commit is contained in:
Andy De George
2020-09-01 16:26:21 -07:00
committed by GitHub
parent 1a27c9b107
commit c0ba284473
1557 changed files with 129980 additions and 13 deletions
@@ -0,0 +1,258 @@
//<SNIPPET1>
#pragma region Using directives
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.Xml.dll>
#using <System.EnterpriseServices.dll>
#using <System.Transactions.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Data::SqlClient;
#pragma endregion
namespace MaskedTextBoxDataCSharp
{
public ref class Form1 : public Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private:
System::ComponentModel::IContainer^ components;
public:
Form1()
{
InitializeComponent();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected:
~Form1()
{
if (components != nullptr)
{
delete components;
}
}
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private:
void InitializeComponent()
{
employeesTable = gcnew DataSet();
components = nullptr;
this->firstName = gcnew System::Windows::Forms::TextBox();
this->lastName = gcnew System::Windows::Forms::TextBox();
this->phoneMask = gcnew System::Windows::Forms::MaskedTextBox();
this->previousButton = gcnew System::Windows::Forms::Button();
this->nextButton = gcnew System::Windows::Forms::Button();
this->SuspendLayout();
//
// firstName
//
this->firstName->Location = System::Drawing::Point(13, 14);
this->firstName->Name = "firstName";
this->firstName->Size = System::Drawing::Size(184, 20);
this->firstName->TabIndex = 0;
//
// lastName
//
this->lastName->Location = System::Drawing::Point(204, 14);
this->lastName->Name = "lastName";
this->lastName->Size = System::Drawing::Size(184, 20);
this->lastName->TabIndex = 1;
//
// phoneMask
//
this->phoneMask->Location = System::Drawing::Point(441, 14);
this->phoneMask->Mask = "(009) 000-0000 x9999";
this->phoneMask->Name = "phoneMask";
this->phoneMask->Size = System::Drawing::Size(169, 20);
this->phoneMask->TabIndex = 2;
//
// previousButton
//
this->previousButton->Location = System::Drawing::Point(630, 14);
this->previousButton->Name = "previousButton";
this->previousButton->TabIndex = 3;
this->previousButton->Text = "Previous";
this->previousButton->Click += gcnew System::EventHandler(this,&Form1::previousButton_Click);
//
// nextButton
//
this->nextButton->Location = System::Drawing::Point(723, 14);
this->nextButton->Name = "nextButton";
this->nextButton->TabIndex = 4;
this->nextButton->Text = "Next";
this->nextButton->Click += gcnew System::EventHandler(this,&Form1::nextButton_Click);
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(887, 46);
this->Controls->Add(this->nextButton);
this->Controls->Add(this->previousButton);
this->Controls->Add(this->phoneMask);
this->Controls->Add(this->lastName);
this->Controls->Add(this->firstName);
this->Name = "Form1";
this->Text = "Form1";
this->Load += gcnew System::EventHandler(this,&Form1::Form1_Load);
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private:
System::Windows::Forms::TextBox^ firstName;
System::Windows::Forms::TextBox^ lastName;
System::Windows::Forms::MaskedTextBox^ phoneMask;
System::Windows::Forms::Button^ previousButton;
System::Windows::Forms::Button^ nextButton;
private:
Binding^ currentBinding;
Binding^ phoneBinding;
DataSet^ employeesTable;
SqlConnection^ sc;
SqlDataAdapter^ dataConnect;
private:
void Form1_Load(Object^ sender, EventArgs^ e)
{
DoMaskBinding();
}
private:
void DoMaskBinding()
{
try
{
sc = gcnew SqlConnection("Data Source=localhost;" +
"Initial Catalog=NORTHWIND;Integrated Security=SSPI");
sc->Open();
}
catch (Exception^ ex)
{
MessageBox::Show(ex->Message);
return;
}
dataConnect = gcnew SqlDataAdapter("SELECT * FROM Employees", sc);
dataConnect->Fill(employeesTable, "Employees");
// Now bind MaskedTextBox to appropriate field. Note that we must
// create the Binding objects before adding them to the control -
// otherwise, we won't get a Format event on the initial load.
try
{
currentBinding = gcnew Binding("Text", employeesTable,
"Employees.FirstName");
firstName->DataBindings->Add(currentBinding);
currentBinding = gcnew Binding("Text", employeesTable,
"Employees.LastName");
lastName->DataBindings->Add(currentBinding);
phoneBinding = gcnew Binding("Text", employeesTable,
"Employees.HomePhone");
// We must add the event handlers before we bind, or the
// Format event will not get called for the first record.
phoneBinding->Format += gcnew
ConvertEventHandler(this, &Form1::phoneBinding_Format);
phoneBinding->Parse += gcnew
ConvertEventHandler(this, &Form1::phoneBinding_Parse);
phoneMask->DataBindings->Add(phoneBinding);
}
catch (Exception^ ex)
{
MessageBox::Show(ex->Message);
return;
}
}
private:
void phoneBinding_Format(Object^ sender, ConvertEventArgs^ e)
{
String^ ext;
DataRowView^ currentRow = (DataRowView^) BindingContext[
employeesTable, "Employees"]->Current;
if (currentRow["Extension"] == nullptr)
{
ext = "";
}
else
{
ext = currentRow["Extension"]->ToString();
}
e->Value = e->Value->ToString()->Trim() + " x" + ext;
}
private:
void phoneBinding_Parse(Object^ sender, ConvertEventArgs^ e)
{
String^ phoneNumberAndExt = e->Value->ToString();
int extIndex = phoneNumberAndExt->IndexOf("x");
String^ ext = phoneNumberAndExt->Substring(extIndex)->Trim();
String^ phoneNumber =
phoneNumberAndExt->Substring(0, extIndex)->Trim();
//Get the current binding object, and set the new extension
//manually.
DataRowView^ currentRow =
(DataRowView^ ) BindingContext[employeesTable,
"Employees"]->Current;
// Remove the "x" from the extension.
currentRow["Extension"] = ext->Substring(1);
//Return the phone number.
e->Value = phoneNumber;
}
private:
void previousButton_Click(Object^ sender, EventArgs^ e)
{
BindingContext[employeesTable, "Employees"]->Position =
BindingContext[employeesTable, "Employees"]->Position - 1;
}
private:
void nextButton_Click(Object^ sender, EventArgs^ e)
{
BindingContext[employeesTable, "Employees"]->Position =
BindingContext[employeesTable, "Employees"]->Position + 1;
}
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew MaskedTextBoxDataCSharp::Form1());
}
//</SNIPPET1>
@@ -0,0 +1,2 @@
MaskedTextBoxData.exe: form1.cpp
cl /clr:pure /Femydll.dll form1.cpp
@@ -0,0 +1,310 @@
// <snippet1>
// <snippet2>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Threading;
using namespace System::Windows::Forms;
// </snippet2>
public ref class FibonacciForm: public System::Windows::Forms::Form
{
private:
// <snippet14>
int numberToCompute;
int highestPercentageReached;
// </snippet14>
System::Windows::Forms::NumericUpDown^ numericUpDown1;
System::Windows::Forms::Button^ startAsyncButton;
System::Windows::Forms::Button^ cancelAsyncButton;
System::Windows::Forms::ProgressBar^ progressBar1;
System::Windows::Forms::Label ^ resultLabel;
System::ComponentModel::BackgroundWorker^ backgroundWorker1;
public:
FibonacciForm()
{
InitializeComponent();
numberToCompute = highestPercentageReached = 0;
InitializeBackgoundWorker();
}
private:
// Set up the BackgroundWorker object by
// attaching event handlers.
void InitializeBackgoundWorker()
{
backgroundWorker1->DoWork += gcnew DoWorkEventHandler( this, &FibonacciForm::backgroundWorker1_DoWork );
backgroundWorker1->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler( this, &FibonacciForm::backgroundWorker1_RunWorkerCompleted );
backgroundWorker1->ProgressChanged += gcnew ProgressChangedEventHandler( this, &FibonacciForm::backgroundWorker1_ProgressChanged );
}
// <snippet13>
void startAsyncButton_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Reset the text in the result label.
resultLabel->Text = String::Empty;
// Disable the UpDown control until
// the asynchronous operation is done.
this->numericUpDown1->Enabled = false;
// Disable the Start button until
// the asynchronous operation is done.
this->startAsyncButton->Enabled = false;
// Enable the Cancel button while
// the asynchronous operation runs.
this->cancelAsyncButton->Enabled = true;
// Get the value from the UpDown control.
numberToCompute = (int)numericUpDown1->Value;
// Reset the variable for percentage tracking.
highestPercentageReached = 0;
// <snippet3>
// Start the asynchronous operation.
backgroundWorker1->RunWorkerAsync( numberToCompute );
// </snippet3>
}
// </snippet13>
// <snippet4>
void cancelAsyncButton_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Cancel the asynchronous operation.
this->backgroundWorker1->CancelAsync();
// Disable the Cancel button.
cancelAsyncButton->Enabled = false;
}
// </snippet4>
// <snippet5>
// This event handler is where the actual,
// potentially time-consuming work is done.
void backgroundWorker1_DoWork( Object^ sender, DoWorkEventArgs^ e )
{
// Get the BackgroundWorker that raised this event.
BackgroundWorker^ worker = dynamic_cast<BackgroundWorker^>(sender);
// Assign the result of the computation
// to the Result property of the DoWorkEventArgs
// object. This is will be available to the
// RunWorkerCompleted eventhandler.
e->Result = ComputeFibonacci( safe_cast<Int32>(e->Argument), worker, e );
}
// </snippet5>
// <snippet6>
// This event handler deals with the results of the
// background operation.
void backgroundWorker1_RunWorkerCompleted( Object^ /*sender*/, RunWorkerCompletedEventArgs^ e )
{
// First, handle the case where an exception was thrown.
if ( e->Error != nullptr )
{
MessageBox::Show( e->Error->Message );
}
else
if ( e->Cancelled )
{
// Next, handle the case where the user cancelled
// the operation.
// Note that due to a race condition in
// the DoWork event handler, the Cancelled
// flag may not have been set, even though
// CancelAsync was called.
resultLabel->Text = "Cancelled";
}
else
{
// Finally, handle the case where the operation
// succeeded.
resultLabel->Text = e->Result->ToString();
}
// Enable the UpDown control.
this->numericUpDown1->Enabled = true;
// Enable the Start button.
startAsyncButton->Enabled = true;
// Disable the Cancel button.
cancelAsyncButton->Enabled = false;
}
// </snippet6>
// <snippet7>
// This event handler updates the progress bar.
void backgroundWorker1_ProgressChanged( Object^ /*sender*/, ProgressChangedEventArgs^ e )
{
this->progressBar1->Value = e->ProgressPercentage;
}
// </snippet7>
// <snippet10>
// This is the method that does the actual work. For this
// example, it computes a Fibonacci number and
// reports progress as it does its work.
long ComputeFibonacci( int n, BackgroundWorker^ worker, DoWorkEventArgs ^ e )
{
// The parameter n must be >= 0 and <= 91.
// Fib(n), with n > 91, overflows a long.
if ( (n < 0) || (n > 91) )
{
throw gcnew ArgumentException( "value must be >= 0 and <= 91","n" );
}
long result = 0;
// <snippet8>
// Abort the operation if the user has cancelled.
// Note that a call to CancelAsync may have set
// CancellationPending to true just after the
// last invocation of this method exits, so this
// code will not have the opportunity to set the
// DoWorkEventArgs.Cancel flag to true. This means
// that RunWorkerCompletedEventArgs.Cancelled will
// not be set to true in your RunWorkerCompleted
// event handler. This is a race condition.
// <snippet11>
if ( worker->CancellationPending )
{
e->Cancel = true;
}
// </snippet11>
else
{
if ( n < 2 )
{
result = 1;
}
else
{
result = ComputeFibonacci( n - 1, worker, e ) + ComputeFibonacci( n - 2, worker, e );
}
// <snippet12>
// Report progress as a percentage of the total task.
int percentComplete = (int)((float)n / (float)numberToCompute * 100);
if ( percentComplete > highestPercentageReached )
{
highestPercentageReached = percentComplete;
worker->ReportProgress( percentComplete );
}
// </snippet12>
}
// </snippet8>
return result;
}
// </snippet10>
void InitializeComponent()
{
this->numericUpDown1 = gcnew System::Windows::Forms::NumericUpDown;
this->startAsyncButton = gcnew System::Windows::Forms::Button;
this->cancelAsyncButton = gcnew System::Windows::Forms::Button;
this->resultLabel = gcnew System::Windows::Forms::Label;
this->progressBar1 = gcnew System::Windows::Forms::ProgressBar;
this->backgroundWorker1 = gcnew System::ComponentModel::BackgroundWorker;
(dynamic_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->BeginInit();
this->SuspendLayout();
//
// numericUpDown1
//
this->numericUpDown1->Location = System::Drawing::Point( 16, 16 );
array<Int32>^temp0 = {91,0,0,0};
this->numericUpDown1->Maximum = System::Decimal( temp0 );
array<Int32>^temp1 = {1,0,0,0};
this->numericUpDown1->Minimum = System::Decimal( temp1 );
this->numericUpDown1->Name = "numericUpDown1";
this->numericUpDown1->Size = System::Drawing::Size( 80, 20 );
this->numericUpDown1->TabIndex = 0;
array<Int32>^temp2 = {1,0,0,0};
this->numericUpDown1->Value = System::Decimal( temp2 );
//
// startAsyncButton
//
this->startAsyncButton->Location = System::Drawing::Point( 16, 72 );
this->startAsyncButton->Name = "startAsyncButton";
this->startAsyncButton->Size = System::Drawing::Size( 120, 23 );
this->startAsyncButton->TabIndex = 1;
this->startAsyncButton->Text = "Start Async";
this->startAsyncButton->Click += gcnew System::EventHandler( this, &FibonacciForm::startAsyncButton_Click );
//
// cancelAsyncButton
//
this->cancelAsyncButton->Enabled = false;
this->cancelAsyncButton->Location = System::Drawing::Point( 153, 72 );
this->cancelAsyncButton->Name = "cancelAsyncButton";
this->cancelAsyncButton->Size = System::Drawing::Size( 119, 23 );
this->cancelAsyncButton->TabIndex = 2;
this->cancelAsyncButton->Text = "Cancel Async";
this->cancelAsyncButton->Click += gcnew System::EventHandler( this, &FibonacciForm::cancelAsyncButton_Click );
//
// resultLabel
//
this->resultLabel->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->resultLabel->Location = System::Drawing::Point( 112, 16 );
this->resultLabel->Name = "resultLabel";
this->resultLabel->Size = System::Drawing::Size( 160, 23 );
this->resultLabel->TabIndex = 3;
this->resultLabel->Text = "(no result)";
this->resultLabel->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// progressBar1
//
this->progressBar1->Location = System::Drawing::Point( 18, 48 );
this->progressBar1->Name = "progressBar1";
this->progressBar1->Size = System::Drawing::Size( 256, 8 );
this->progressBar1->Step = 2;
this->progressBar1->TabIndex = 4;
//
// backgroundWorker1
//
this->backgroundWorker1->WorkerReportsProgress = true;
this->backgroundWorker1->WorkerSupportsCancellation = true;
//
// FibonacciForm
//
this->ClientSize = System::Drawing::Size( 292, 118 );
this->Controls->Add( this->progressBar1 );
this->Controls->Add( this->resultLabel );
this->Controls->Add( this->cancelAsyncButton );
this->Controls->Add( this->startAsyncButton );
this->Controls->Add( this->numericUpDown1 );
this->Name = "FibonacciForm";
this->Text = "Fibonacci Calculator";
(dynamic_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->EndInit();
this->ResumeLayout( false );
}
};
[STAThread]
int main()
{
Application::Run( gcnew FibonacciForm );
}
// </snippet1>
@@ -0,0 +1,165 @@
// <snippet1>
// <snippet2>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Windows::Forms;
// </snippet2>
// This sample demonstrates the use of the
// DesignerSerializationVisibility attribute
// to serialize a collection of strings
// at design time.
namespace SerializationDemo
{
// <snippet3>
public ref class SerializationDemoControl :
public System::Windows::Forms::UserControl
{
// This is the TextBox contained by
// the SerializationDemoControl.
private:
System::Windows::Forms::TextBox^ demoControlTextBox;
// <snippet4>
// This field backs the Strings property.
private:
array<String^>^ stringsValue;
// </snippet4>
public:
SerializationDemoControl()
{
InitializeComponent();
stringsValue = gcnew array<String^>(1);
}
// <snippet5>
// When the DesignerSerializationVisibility attribute has
// a value of "Content" or "Visible" the designer will
// serialize the property. This property can also be edited
// at design time with a CollectionEditor.
public:
[DesignerSerializationVisibility(
DesignerSerializationVisibility::Content)]
property array<String^>^ Strings
{
array<String^>^ get()
{
return this->stringsValue;
}
void set(array<String^>^ value)
{
this->stringsValue = value;
// Populate the contained TextBox with the values
// in the stringsValue array.
StringBuilder^ sb =
gcnew StringBuilder(this->stringsValue->Length);
for (int i = 0; i < this->stringsValue->Length; i++)
{
sb->Append(this->stringsValue[i]);
sb->Append(Environment::NewLine);
}
this->demoControlTextBox->Text = sb->ToString();
}
}
// </snippet5>
private:
void InitializeComponent()
{
this->demoControlTextBox =
gcnew System::Windows::Forms::TextBox();
this->SuspendLayout();
// Settings for the contained TextBox control.
this->demoControlTextBox->AutoSize = false;
this->demoControlTextBox->Dock =
System::Windows::Forms::DockStyle::Fill;
this->demoControlTextBox->Location =
System::Drawing::Point(5, 5);
this->demoControlTextBox->Margin =
System::Windows::Forms::Padding(0);
this->demoControlTextBox->Multiline = true;
this->demoControlTextBox->Name = "textBox1";
this->demoControlTextBox->ReadOnly = true;
this->demoControlTextBox->ScrollBars = ScrollBars::Vertical;
this->demoControlTextBox->Size =
System::Drawing::Size(140, 140);
this->demoControlTextBox->TabIndex = 0;
// Settings for SerializationDemoControl.
this->Controls->Add(this->demoControlTextBox);
this->Name = "SerializationDemoControl";
this->Padding = System::Windows::Forms::Padding(5);
this->ResumeLayout(false);
}
};
// </snippet3>
public ref class SerializationDemoForm :
public System::Windows::Forms::Form
{
SerializationDemoControl^ serializationDemoControl;
public:
SerializationDemoForm()
{
InitializeComponent();
serializationDemoControl = nullptr;
}
// The Windows Forms Designer emits code to this method.
// If an instance of SerializationDemoControl is added
// to the form, the Strings will be serialized here.
private:
void InitializeComponent()
{
this->serializationDemoControl =
gcnew SerializationDemo::SerializationDemoControl();
this->SuspendLayout();
//
// serializationDemoControl
//
this->serializationDemoControl->Location =
System::Drawing::Point(0, 0);
this->serializationDemoControl->Name =
"serializationDemoControl";
this->serializationDemoControl->Padding =
System::Windows::Forms::Padding(5);
this->serializationDemoControl->TabIndex = 0;
//
// SerializationDemoForm
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->serializationDemoControl);
this->Name = "SerializationDemoForm";
this->Text = "Form1";
this->ResumeLayout(false);
}
};
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew SerializationDemo::SerializationDemoForm());
}
// </snippet1>
@@ -0,0 +1,2 @@
System.ComponentModel.DesignerSerializationVisibilityAttribute.exe : form1.cpp
cl /W4 /clr:pure /FeSystem.ComponentModel.DesignerSerializationVisibilityAttribute.exe form1.cpp
@@ -0,0 +1,180 @@
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
public ref class Form1: public System::Windows::Forms::Form
{
private:
void DoSomething1()
{
// Snippet for:
// \vbtskcodeexampledrawingfilledellipseonform.xml
// <snippet1>
System::Drawing::SolidBrush^ myBrush =
gcnew System::Drawing::SolidBrush(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->FillEllipse(myBrush, Rectangle(0, 0, 200, 300));
delete myBrush;
delete formGraphics;
// </snippet1>
}
private:
void DoSomething2()
{
// Snippet for:
// \vbtskcodeexampledrawingfilledrectangleonform.xml
// <snippet2>
System::Drawing::SolidBrush^ myBrush =
gcnew System::Drawing::SolidBrush(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->FillRectangle(myBrush, Rectangle(0, 0, 200, 300));
delete myBrush;
delete formGraphics;
// </snippet2>
}
private:
void DoSomething3()
{
// Snippet for: \vbtskcodeexamplecreatingpen.xml
// <snippet3>
System::Drawing::Pen^ myPen;
myPen = gcnew System::Drawing::Pen(System::Drawing::Color::Tomato);
// </snippet3>
}
private:
void DoSomething4()
{
// Snippet for: \vbtskcodeexamplecreatingsolidbrush.xml
// <snippet4>
System::Drawing::SolidBrush^ myBrush;
myBrush = gcnew System::Drawing::SolidBrush(
System::Drawing::Color::PeachPuff);
// </snippet4>
}
private:
void DoSomething5()
{
// Snippet for: \vbtskcodeexampledrawinglineonform.xml
// <snippet5>
System::Drawing::Pen^ myPen =
gcnew System::Drawing::Pen(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->DrawLine(myPen, 0, 0, 200, 200);
delete myPen;
delete formGraphics;
// </snippet5>
}
// Snippet for: \vbtskcodeexampledrawingoutlinedshapes.xml
// <snippet6>
private:
void DrawEllipse()
{
System::Drawing::Pen^ myPen =
gcnew System::Drawing::Pen(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->DrawEllipse(myPen, Rectangle(0, 0, 200, 300));
delete myPen;
delete formGraphics;
}
private:
void DrawRectangle()
{
System::Drawing::Pen^ myPen =
gcnew System::Drawing::Pen(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->DrawRectangle(myPen, Rectangle(0, 0, 200, 300));
delete myPen;
delete formGraphics;
}
// </snippet6>
// Snippet for: \vbtskcodeexampledrawingtextonform2.xml
// <snippet7>
public:
void DrawString()
{
System::Drawing::Graphics^ formGraphics = this->CreateGraphics();
String^ drawString = "Sample Text";
System::Drawing::Font^ drawFont =
gcnew System::Drawing::Font("Arial", 16);
System::Drawing::SolidBrush^ drawBrush = gcnew
System::Drawing::SolidBrush(System::Drawing::Color::Black);
float x = 150.0F;
float y = 50.0F;
System::Drawing::StringFormat^ drawFormat =
gcnew System::Drawing::StringFormat();
formGraphics->DrawString(drawString, drawFont, drawBrush, x,
y, drawFormat);
delete drawFont;
delete drawBrush;
delete formGraphics;
}
// </snippet7>
// Snippet for: \vbtskcodeexampledrawingtextonform.xml
// <snippet8>
public:
void DrawVerticalString()
{
System::Drawing::Graphics^ formGraphics = this->CreateGraphics();
String^ drawString = "Sample Text";
System::Drawing::Font^ drawFont =
gcnew System::Drawing::Font("Arial", 16);
System::Drawing::SolidBrush^ drawBrush = gcnew
System::Drawing::SolidBrush(System::Drawing::Color::Black);
float x = 150.0F;
float y = 50.0F;
System::Drawing::StringFormat^ drawFormat =
gcnew System::Drawing::StringFormat();
drawFormat->FormatFlags = StringFormatFlags::DirectionVertical;
formGraphics->DrawString(drawString, drawFont, drawBrush, x,
y, drawFormat);
delete drawFont;
delete drawBrush;
delete formGraphics;
}
// </snippet8>
private:
void DoSomething9()
{
Pen^ myPen = gcnew Pen(Color::Red);
// Snippet for: \vbtskcodeexamplesetcolorofpen.xml
// <snippet9>
myPen->Color = System::Drawing::Color::PeachPuff;
// </snippet9>
}
// Snippet for: \vbtskcreateashapedwindowsform.xml
// <snippet10>
protected:
virtual void OnPaint(
System::Windows::Forms::PaintEventArgs^ e) override
{
System::Drawing::Drawing2D::GraphicsPath^ shape =
gcnew System::Drawing::Drawing2D::GraphicsPath();
shape->AddEllipse(0, 0, this->Width, this->Height);
this->Region = gcnew System::Drawing::Region(shape);
}
// </snippet10>
};
int main()
{
Application::Run(gcnew Form1());
}
@@ -0,0 +1,2 @@
System.Drawing.ConceptualHowTos.exe: form1.cpp
cl /clr:pure /FeSystem.Drawing.ConceptualHowTos.exe form1.cpp
@@ -0,0 +1,181 @@
// <snippet1>
// <snippet2>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Globalization;
using namespace System::Windows::Forms;
// </snippet2>
namespace DataConnectorAddingNewExample
{
// <snippet4>
// This class implements a simple customer type.
public ref class DemoCustomer
{
private:
// These fields hold the values for the public properties.
Guid idValue;
String^ customerName;
String^ companyNameValue;
String^ phoneNumberValue;
// The constructor is private to enforce the factory pattern.
DemoCustomer()
{
idValue = Guid::NewGuid();
customerName = String::Empty;
companyNameValue = String::Empty;
phoneNumberValue = String::Empty;
customerName = "no data";
companyNameValue = "no data";
phoneNumberValue = "no data";
}
public:
// This is the public factory method.
static DemoCustomer^ CreateNewCustomer()
{
return gcnew DemoCustomer;
}
property Guid ID
{
// This property represents an ID, suitable
// for use as a primary key in a database.
Guid get()
{
return this->idValue;
}
}
property String^ CompanyName
{
String^ get()
{
return this->companyNameValue;
}
void set(String^ value)
{
this->companyNameValue = value;
}
}
property String^ PhoneNumber
{
String^ get()
{
return this->phoneNumberValue;
}
void set(String^ value)
{
this->phoneNumberValue = value;
}
}
};
// </snippet4>
// <snippet3>
// This form demonstrates using a BindingSource to provide
// data from a collection of custom types
// to a DataGridView control.
public ref class MainForm: public System::Windows::Forms::Form
{
// <snippet5>
private:
// This is the BindingSource that will provide data for
// the DataGridView control.
BindingSource^ customersBindingSource;
// This is the DataGridView control
// that will display our data.
DataGridView^ customersDataGridView;
// Set up the StatusBar for displaying ListChanged events.
StatusBar^ status;
// </snippet5>
// <snippet6>
public:
MainForm()
{
customersBindingSource = gcnew BindingSource;
customersDataGridView = gcnew DataGridView;
status = gcnew StatusBar;
// Set up the form.
this->Size = System::Drawing::Size(600, 400);
this->Text = "BindingSource.AddingNew sample";
this->Load +=
gcnew EventHandler(this, &MainForm::OnMainFormLoad);
this->Controls->Add(status);
// Set up the DataGridView control.
this->customersDataGridView->Dock = DockStyle::Fill;
this->Controls->Add(this->customersDataGridView);
// Attach an event handler for the AddingNew event.
this->customersBindingSource->AddingNew +=
gcnew AddingNewEventHandler(this,
&MainForm::OnCustomersBindingSourceAddingNew);
// Attach an event handler for the ListChanged event.
this->customersBindingSource->ListChanged +=
gcnew ListChangedEventHandler(this,
&MainForm::OnCustomersBindingSourceListChanged);
}
// </snippet6>
// <snippet7>
private:
void OnMainFormLoad(Object^ sender, EventArgs^ e)
{
// Add a DemoCustomer to cause a row to be displayed.
this->customersBindingSource->AddNew();
// Bind the BindingSource to the DataGridView
// control's DataSource.
this->customersDataGridView->DataSource =
this->customersBindingSource;
}
// </snippet7>
// <snippet8>
// This event handler provides custom item-creation behavior.
void OnCustomersBindingSourceAddingNew(Object^ sender,
AddingNewEventArgs^ e)
{
e->NewObject = DemoCustomer::CreateNewCustomer();
}
// </snippet8>
// <snippet9>
// This event handler detects changes in the BindingSource
// list or changes to items within the list.
void OnCustomersBindingSourceListChanged(Object^ sender,
ListChangedEventArgs^ e)
{
status->Text = Convert::ToString(e->ListChangedType,
CultureInfo::CurrentCulture);
}
// </snippet9>
};
// </snippet3>
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew DataConnectorAddingNewExample::MainForm);
}
// </snippet1>
@@ -0,0 +1,136 @@
// <snippet1>
// <snippet2>
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.EnterpriseServices.dll>
#using <System.Transactions.dll>
#using <System.Windows.Forms.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Data::Common;
using namespace System::Data::SqlClient;
using namespace System::Diagnostics;
using namespace System::Drawing;
using namespace System::Windows::Forms;
// </snippet2>
// <snippet3>
// This form demonstrates using a BindingSource to bind to a factory
// object.
public ref class Form1: public System::Windows::Forms::Form
{
private:
// <snippet4>
// This is the TextBox for entering CustomerID values.
static TextBox^ customerIdTextBox = gcnew TextBox;
// This is the DataGridView that displays orders for the
// specified customer.
static DataGridView^ customersDataGridView = gcnew DataGridView;
// This is the BindingSource for binding the database query
// result set to the DataGridView.
static BindingSource^ ordersBindingSource = gcnew BindingSource;
// </snippet4>
public:
// <snippet5>
Form1()
{
// Set up the CustomerID TextBox.
this->customerIdTextBox->Dock = DockStyle::Bottom;
this->customerIdTextBox->Text =
L"Enter a valid Northwind CustomerID, for example: ALFKI,"
L" then TAB or click outside the TextBox";
this->customerIdTextBox->Leave += gcnew EventHandler(
this, &Form1::customerIdTextBox_Leave );
this->Controls->Add( this->customerIdTextBox );
// Set up the DataGridView.
customersDataGridView->Dock = DockStyle::Top;
this->Controls->Add( customersDataGridView );
// Set up the form.
this->Size = System::Drawing::Size( 800, 800 );
this->Load += gcnew EventHandler( this, &Form1::Form1_Load );
}
// </snippet5>
private:
// <snippet6>
// This event handler binds the BindingSource to the DataGridView
// control's DataSource property.
void Form1_Load(
System::Object^ /*sender*/,
System::EventArgs^ /*e*/ )
{
// Attach the BindingSource to the DataGridView.
this->customersDataGridView->DataSource =
this->ordersBindingSource;
}
// </snippet6>
public:
// <snippet7>
// This is a static factory method. It queries the Northwind
// database for the orders belonging to the specified
// customer and returns an IList.
static System::Collections::IList^ GetOrdersByCustomerId( String^ id )
{
// Open a connection to the database.
String^ connectString = L"Integrated Security=SSPI;"
L"Persist Security Info=False;Initial Catalog=Northwind;"
L"Data Source= localhost";
SqlConnection^ connection = gcnew SqlConnection;
connection->ConnectionString = connectString;
connection->Open();
// Execute the query.
String^ queryString = String::Format(
L"Select * From Orders where CustomerID = '{0}'", id );
SqlCommand^ command = gcnew SqlCommand( queryString,connection );
SqlDataReader^ reader = command->ExecuteReader(
CommandBehavior::CloseConnection );
// Build an IList from the result set.
List< DbDataRecord^ >^ list = gcnew List< DbDataRecord^ >;
System::Collections::IEnumerator^ e = reader->GetEnumerator();
while ( e->MoveNext() )
{
list->Add( dynamic_cast<DbDataRecord^>(e->Current) );
}
return list;
}
// </snippet7>
// <snippet8>
// This event handler is called when the user tabs or clicks
// out of the customerIdTextBox. The database is then queried
// with the CustomerID in the customerIdTextBox.Text property.
private:
void customerIdTextBox_Leave( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Attach the data source to the BindingSource control.
this->ordersBindingSource->DataSource = GetOrdersByCustomerId(
this->customerIdTextBox->Text );
}
// </snippet8>
public:
[STAThread]
static void main()
{
Application::EnableVisualStyles();
Application::Run( gcnew Form1 );
}
};
// </snippet3>
// </snippet1>
@@ -0,0 +1,169 @@
//<snippet1>
#using <System.Xml.dll>
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Xml;
using namespace System::Windows::Forms;
using namespace System::IO;
namespace System_Windows_Forms_UpdateBinding
{
public ref class Form1: public Form
{
public:
Form1()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application::EnableVisualStyles();
Application::Run( gcnew Form1 );
}
//<snippet2>
private:
void Form1_Load( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// The xml to bind to.
String^ xml = "<US><states>" +
"<state><name>Washington</name><capital>Olympia</capital></state>" +
"<state><name>Oregon</name><capital>Salem</capital></state>" +
"<state><name>California</name><capital>Sacramento</capital></state>" +
"<state><name>Nevada</name><capital>Carson City</capital></state>" +
"</states></US>";
// Convert the xml string to bytes and load into a memory stream.
array<Byte>^ xmlBytes = Encoding::UTF8->GetBytes( xml );
MemoryStream^ stream = gcnew MemoryStream( xmlBytes,false );
// Create a DataSet and load the xml into it.
dataSet1->ReadXml( stream );
// Set the DataSource to the DataSet, and the DataMember
// to state.
bindingSource1->DataSource = dataSet1;
bindingSource1->DataMember = "state";
dataGridView1->DataSource = bindingSource1;
}
//</snippet2>
//<snippet3>
private:
void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
String^ xml = "<US><states>"
+ "<state><name>Washington</name><capital>Olympia</capital> "
+ "<flower>Coast Rhododendron</flower></state>"
+ "<state><name>Oregon</name><capital>Salem</capital>"
+ "<flower>Oregon Grape</flower></state>"
+ "<state><name>California</name><capital>Sacramento</capital>"
+ "<flower>California Poppy</flower></state>"
+ "<state><name>Nevada</name><capital>Carson City</capital>"
+ "<flower>Sagebrush</flower></state>"
+ "</states></US>";
// Convert the xml string to bytes and load into a memory stream.
array<Byte>^ xmlBytes = Encoding::UTF8->GetBytes( xml );
MemoryStream^ stream = gcnew MemoryStream( xmlBytes,false );
// Create a DataSet and load the xml into it.
dataSet2->ReadXml( stream );
// Set the data source.
bindingSource1->DataSource = dataSet2;
bindingSource1->ResetBindings( true );
}
//</snippet3>
System::Windows::Forms::Button^ button1;
System::Windows::Forms::DataGridView^ dataGridView1;
System::Windows::Forms::BindingSource^ bindingSource1;
System::Data::DataSet^ dataSet1;
DataSet^ dataSet2;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent()
{
this->button1 = gcnew System::Windows::Forms::Button;
this->dataGridView1 = gcnew System::Windows::Forms::DataGridView;
this->bindingSource1 = gcnew System::Windows::Forms::BindingSource;
this->dataSet1 = gcnew System::Data::DataSet;
this->dataSet2 = gcnew System::Data::DataSet;
( (System::ComponentModel::ISupportInitialize^)(this->dataGridView1) )->BeginInit();
( (System::ComponentModel::ISupportInitialize^)(this->bindingSource1) )->BeginInit();
( (System::ComponentModel::ISupportInitialize^)(this->dataSet1) )->BeginInit();
( (System::ComponentModel::ISupportInitialize^)(this->dataSet2) )->BeginInit();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point( 98, 222 );
this->button1->Name = "button1";
this->button1->TabIndex = 0;
this->button1->Text = "button1";
this->button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );
//
// dataGridView1
//
this->dataGridView1->Dock = System::Windows::Forms::DockStyle::Top;
this->dataGridView1->Location = System::Drawing::Point( 0, 0 );
this->dataGridView1->Name = "dataGridView1";
this->dataGridView1->Size = System::Drawing::Size( 292, 150 );
this->dataGridView1->TabIndex = 1;
//
// dataSet1
//
this->dataSet1->DataSetName = "NewDataSet";
this->dataSet1->Locale = gcnew System::Globalization::CultureInfo( "en-US" );
//
// dataSet2
//
this->dataSet2->DataSetName = "NewDataSet";
this->dataSet2->Locale = gcnew System::Globalization::CultureInfo( "en-US" );
//
// Form1
//
this->ClientSize = System::Drawing::Size( 292, 273 );
this->Controls->Add( this->dataGridView1 );
this->Controls->Add( this->button1 );
this->Name = "Form1";
this->Text = "Form1";
this->Load += gcnew EventHandler( this, &Form1::Form1_Load );
( (System::ComponentModel::ISupportInitialize^)(this->dataGridView1) )->EndInit();
( (System::ComponentModel::ISupportInitialize^)(this->bindingSource1) )->EndInit();
( (System::ComponentModel::ISupportInitialize^)(this->dataSet1) )->EndInit();
( (System::ComponentModel::ISupportInitialize^)(this->dataSet2) )->EndInit();
this->ResumeLayout( false );
}
#pragma endregion
};
}
int main()
{
System_Windows_Forms_UpdateBinding::Form1::Main();
}
//</snippet1>
@@ -0,0 +1,178 @@
// <snippet1>
// <snippet2>
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.EnterpriseServices.dll>
#using <System.Transactions.dll>
#using <System.Windows.Forms.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Data::Common;
using namespace System::Data::SqlClient;
using namespace System::Diagnostics;
using namespace System::Drawing;
using namespace System::Windows::Forms;
// </snippet2>
// <snippet9>
// This class implements a simple customer type.
public ref class DemoCustomer
{
private:
// These fields hold the values for the public properties.
Guid idValue;
String^ customerName;
String^ companyNameValue;
String^ phoneNumberValue;
// The constructor is private to enforce the factory pattern.
DemoCustomer()
{
idValue = Guid::NewGuid();
customerName = L"no data";
companyNameValue = L"no data";
phoneNumberValue = L"no data";
}
public:
// This is the public factory method.
static DemoCustomer^ CreateNewCustomer()
{
return gcnew DemoCustomer;
}
property Guid ID
{
// This property represents an ID, suitable
// for use as a primary key in a database.
Guid get()
{
return this->idValue;
}
}
property String^ CompanyName
{
String^ get()
{
return this->companyNameValue;
}
void set( String^ value )
{
this->companyNameValue = value;
}
}
property String^ PhoneNumber
{
String^ get()
{
return this->phoneNumberValue;
}
void set( String^ value )
{
this->phoneNumberValue = value;
}
}
};
// </snippet9>
// <snippet3>
// This form demonstrates using a BindingSource to bind
// a list to a DataGridView control. The list does not
// raise change notifications, so the ResetItem method
// on the BindingSource is used.
public ref class Form1: public System::Windows::Forms::Form
{
private:
// <snippet4>
// This button causes the value of a list element to be changed.
Button^ changeItemBtn;
// This is the DataGridView control that displays the contents
// of the list.
DataGridView^ customersDataGridView;
// This is the BindingSource used to bind the list to the
// DataGridView control.
BindingSource^ customersBindingSource;
// </snippet4>
public:
// <snippet5>
Form1()
{
changeItemBtn = gcnew Button;
customersDataGridView = gcnew DataGridView;
customersBindingSource = gcnew BindingSource;
// Set up the "Change Item" button.
this->changeItemBtn->Text = L"Change Item";
this->changeItemBtn->Dock = DockStyle::Bottom;
this->changeItemBtn->Click += gcnew EventHandler(
this, &Form1::changeItemBtn_Click );
this->Controls->Add( this->changeItemBtn );
// Set up the DataGridView.
customersDataGridView->Dock = DockStyle::Top;
this->Controls->Add( customersDataGridView );
this->Size = System::Drawing::Size( 800, 200 );
this->Load += gcnew EventHandler( this, &Form1::Form1_Load );
}
// </snippet5>
private:
// <snippet6>
void Form1_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Create and populate the list of DemoCustomer objects
// which will supply data to the DataGridView.
List< DemoCustomer^ >^ customerList = gcnew List< DemoCustomer^ >;
customerList->Add( DemoCustomer::CreateNewCustomer() );
customerList->Add( DemoCustomer::CreateNewCustomer() );
customerList->Add( DemoCustomer::CreateNewCustomer() );
// Bind the list to the BindingSource.
this->customersBindingSource->DataSource = customerList;
// Attach the BindingSource to the DataGridView.
this->customersDataGridView->DataSource =
this->customersBindingSource;
}
// </snippet6>
// <snippet7>
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Get a reference to the list from the BindingSource.
List< DemoCustomer^ >^ customerList =
static_cast<List< DemoCustomer^ >^>(
this->customersBindingSource->DataSource);
// Change the value of the CompanyName property for the
// first item in the list.
customerList->default[ 0 ]->CompanyName = L"Tailspin Toys";
// Call ResetItem to alert the BindingSource that the
// list has changed.
this->customersBindingSource->ResetItem( 0 );
}
// </snippet7>
};
int main()
{
Application::EnableVisualStyles();
Application::Run( gcnew Form1 );
}
// </snippet3>
// </snippet1>
@@ -0,0 +1,215 @@
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Globalization;
namespace DataConnectorBindingCompleteExample
{
//<snippet3>
//<snippet2>
// Represents a business object that throws exceptions when
// invalid values are entered for some of its properties.
public ref class Part
{
private:
String^ name;
int number;
double price;
public:
Part(String^ name, int number, double price)
{
PartName = name;
PartNumber = number;
PartPrice = price;
}
property String^ PartName
{
String^ get()
{
return name;
}
void set(String^ value)
{
if (value->Length <= 0)
{
throw gcnew Exception(
"Each part must have a name.");
}
else
{
name = value;
}
}
}
property double PartPrice
{
double get()
{
return price;
}
void set(double value)
{
price = value;
}
}
property int PartNumber
{
int get()
{
return number;
}
void set(int value)
{
if (value < 100)
{
throw gcnew Exception(
"Invalid part number." \
"Part numbers must be " \
"greater than 100.");
}
else
{
number = value;
}
}
}
};
ref class MainForm: public Form
{
private:
BindingSource^ bindingSource;
TextBox^ partNameTextBox;
TextBox^ partNumberTextBox;
TextBox^ partPriceTextBox;
public:
MainForm()
{
bindingSource = gcnew BindingSource;
partNameTextBox = gcnew TextBox;
partNumberTextBox = gcnew TextBox;
partPriceTextBox = gcnew TextBox;
//Set up the textbox controls.
this->partNameTextBox->Location = Point(82, 13);
this->partNameTextBox->TabIndex = 1;
this->partNumberTextBox->Location = Point(81, 47);
this->partNumberTextBox->TabIndex = 2;
this->partPriceTextBox->Location = Point(81, 83);
this->partPriceTextBox->TabIndex = 3;
// Add the textbox controls to the form
this->Controls->Add(this->partNumberTextBox);
this->Controls->Add(this->partNameTextBox);
this->Controls->Add(this->partPriceTextBox);
// Handle the form's Load event.
this->Load += gcnew EventHandler(this,
&MainForm::OnMainFormLoad);
}
private:
//<snippet1>
void OnMainFormLoad(Object^ sender, EventArgs^ e)
{
// Set the DataSource of bindingSource to the Part type.
bindingSource->DataSource = Part::typeid;
// Bind the textboxes to the properties of the Part type,
// enabling formatting.
partNameTextBox->DataBindings->Add(
"Text", bindingSource, "PartName", true);
partNumberTextBox->DataBindings->Add(
"Text", bindingSource, "PartNumber", true);
//Bind the textbox to the PartPrice value
// with currency formatting.
partPriceTextBox->DataBindings->Add("Text", bindingSource, "PartPrice", true,
DataSourceUpdateMode::OnPropertyChanged, nullptr, "C");
// Handle the BindingComplete event for bindingSource and
// the partNameBinding.
bindingSource->BindingComplete +=
gcnew BindingCompleteEventHandler(this,
&MainForm::OnBindingSourceBindingComplete);
bindingSource->BindingComplete +=
gcnew BindingCompleteEventHandler(this,
&MainForm::OnPartNameBindingBindingComplete);
// Add a new part to bindingSource.
bindingSource->Add(gcnew Part("Widget", 1234, 12.45));
}
// Handle the BindingComplete event to catch errors and
// exceptions in binding process.
void OnBindingSourceBindingComplete(Object^ sender,
BindingCompleteEventArgs^ e)
{
if (e->BindingCompleteState ==
BindingCompleteState::Exception)
{
MessageBox::Show(String::Format(
CultureInfo::CurrentCulture,
"bindingSource: {0}", e->Exception->Message));
}
if (e->BindingCompleteState ==
BindingCompleteState::DataError)
{
MessageBox::Show(String::Format(
CultureInfo::CurrentCulture,
"bindingSource: {0}", e->Exception->Message));
}
}
// Handle the BindingComplete event to catch errors and
// exceptions in binding process.
void OnPartNameBindingBindingComplete(Object^ sender,
BindingCompleteEventArgs^ e)
{
if (e->BindingCompleteState ==
BindingCompleteState::Exception)
{
MessageBox::Show(String::Format(
CultureInfo::CurrentCulture,
"PartNameBinding: {0}", e->Exception->Message));
}
if (e->BindingCompleteState ==
BindingCompleteState::DataError)
{
MessageBox::Show(String::Format(
CultureInfo::CurrentCulture,
"PartNameBinding: {0}", e->Exception->Message));
}
}
//</snippet1>
};
//</snippet2>
//</snippet3>
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew
DataConnectorBindingCompleteExample::MainForm());
}
@@ -0,0 +1,248 @@
//<snippet1>
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Web.Services.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace BindToWebService {
//<snippet4>
[System::SerializableAttribute, System::Xml::Serialization::XmlTypeAttribute(
Namespace="http://webservices.eraserver.net/")]
public ref class USPSAddress
{
private:
String^ streetField;
String^ cityField;
String^ stateField;
String^ shortZIPField;
String^ fullZIPField;
public:
property String^ Street
{
String^ get()
{
return this->streetField;
}
void set( String^ value )
{
this->streetField = value;
}
}
property String^ City
{
String^ get()
{
return this->cityField;
}
void set( String^ value )
{
this->cityField = value;
}
}
property String^ State
{
String^ get()
{
return this->stateField;
}
void set( String^ value )
{
this->stateField = value;
}
}
property String^ ShortZIP
{
String^ get()
{
return this->shortZIPField;
}
void set( String^ value )
{
this->shortZIPField = value;
}
}
property String^ FullZIP
{
String^ get()
{
return this->fullZIPField;
}
void set( String^ value )
{
this->fullZIPField = value;
}
}
};
//</snippet4>
[System::Web::Services::WebServiceBindingAttribute(Name="ZipCodeResolverSoap",
Namespace="http://webservices.eraserver.net/")]
public ref class ZipCodeResolver:
public System::Web::Services::Protocols::SoapHttpClientProtocol
{
public:
ZipCodeResolver() : SoapHttpClientProtocol()
{
this->Url =
"http://webservices.eraserver.net/zipcoderesolver/zipcoderesolver.asmx";
}
//''<remarks/>
[System::Web::Services::Protocols::SoapDocumentMethodAttribute
("http://webservices.eraserver.net/CorrectedAddressXml",
RequestNamespace="http://webservices.eraserver.net/",
ResponseNamespace="http://webservices.eraserver.net/",
Use=System::Web::Services::Description::SoapBindingUse::Literal,
ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)]
USPSAddress^ CorrectedAddressXml(String^ accessCode,
String^ address, String^ city, String^ state)
{
array<Object^>^ results = this->Invoke("CorrectedAddressXml",
gcnew array<Object^>{accessCode, address, city, state});
return ((USPSAddress^) results[0]);
}
//''<remarks/>
System::IAsyncResult^ BeginCorrectedAddressXml(String^ accessCode,
String^ address, String^ city, String^ state,
System::AsyncCallback^ callback, Object^ asyncState)
{
return this->BeginInvoke("CorrectedAddressXml",
gcnew array<Object^>{accessCode, address, city, state}, callback, asyncState);
}
USPSAddress^ EndCorrectedAddressXml(System::IAsyncResult^ asyncResult)
{
array<Object^>^ results = this->EndInvoke(asyncResult);
return ((USPSAddress^) results[0]);
}
};
ref class Form1: public Form
{
public:
[STAThread]
static void Main()
{
Application::EnableVisualStyles();
Application::Run(gcnew Form1());
}
private:
BindingSource^ BindingSource1;
TextBox^ textBox1;
TextBox^ textBox2;
Button^ button1;
public:
Form1()
{
this->Load += gcnew EventHandler(this, &Form1::Form1_Load);
textBox1->Location = System::Drawing::Point(118, 131);
textBox1->ReadOnly = true;
button1->Location = System::Drawing::Point(133, 60);
button1->Click += gcnew EventHandler(this, &Form1::button1_Click);
button1->Text = "Get zipcode";
ClientSize = System::Drawing::Size(292, 266);
Controls->Add(this->button1);
Controls->Add(this->textBox1);
BindingSource1 = gcnew BindingSource();
textBox1 = gcnew TextBox();
textBox2 = gcnew TextBox();
button1 = gcnew Button();
}
private:
void button1_Click(Object^ sender, EventArgs^ e)
{
textBox1->Text = "Calling Web service..";
ZipCodeResolver^ resolver = gcnew ZipCodeResolver();
BindingSource1->Add(resolver->CorrectedAddressXml("0",
"One Microsoft Way", "Redmond", "WA"));
}
public:
void Form1_Load(Object^ sender, EventArgs^ e)
{
//<snippet2>
BindingSource1->DataSource = USPSAddress::typeid;
//</snippet2>
//<snippet3>
textBox1->DataBindings->Add("Text", this->BindingSource1, "FullZIP", true);
//</snippet3>
}
};
public ref class CorrectedAddressXmlCompletedEventArgs:
public System::ComponentModel::AsyncCompletedEventArgs
{
private:
array<Object^>^ results;
internal:
CorrectedAddressXmlCompletedEventArgs(array<Object^>^ results,
System::Exception^ exception, bool cancelled, Object^ userState) :
AsyncCompletedEventArgs(exception, cancelled, userState)
{
this->results = results;
}
public:
property USPSAddress^ Result
{
USPSAddress^ get()
{
this->RaiseExceptionIfNecessary();
return ((USPSAddress^) this->results[0]);
}
}
delegate void CorrectedAddressXmlCompletedEventHandler(Object^ sender,
CorrectedAddressXmlCompletedEventArgs^ args);
};
}
int main()
{
BindToWebService::Form1::Main();
return 1;
}
//</snippet1>
@@ -0,0 +1,303 @@
//<snippet0>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
public ref class AutoSizing: public System::Windows::Forms::Form
{
private:
FlowLayoutPanel^ flowLayoutPanel1;
Button^ button1;
Button^ button2;
Button^ button3;
Button^ button4;
Button^ button5;
Button^ button6;
Button^ button7;
Button^ button8;
Button^ button9;
Button^ button10;
Button^ button11;
public:
AutoSizing()
{
button1 = gcnew Button;
button2 = gcnew Button;
button3 = gcnew Button;
button4 = gcnew Button;
button5 = gcnew Button;
button6 = gcnew Button;
button7 = gcnew Button;
button8 = gcnew Button;
button9 = gcnew Button;
button10 = gcnew Button;
button11 = gcnew Button;
thirdColumnHeader = "Main Ingredients";
boringMeatloaf = "ground beef";
boringMeatloafRanking = "*";
otherRestaurant = "Gomes's Saharan Sushi";
currentLayoutName = "DataGridView.AutoSizeRowsMode is currently: ";
InitializeComponent();
this->Load += gcnew EventHandler( this, &AutoSizing::InitializeDataGridView );
AddDirections();
AddButton( button1, "Reset", gcnew EventHandler( this, &AutoSizing::ResetToDisorder ) );
AddButton( button2, "Change Column 3 Header", gcnew EventHandler( this, &AutoSizing::ChangeColumn3Header ) );
AddButton( button3, "Change Meatloaf Recipe", gcnew EventHandler( this, &AutoSizing::ChangeMeatloafRecipe ) );
AddButton( button4, "Change Restaurant 2", gcnew EventHandler( this, &AutoSizing::ChangeRestaurant ) );
AddButtonsForAutomaticResizing();
}
private:
void AddDirections()
{
Label^ directions = gcnew Label;
directions->AutoSize = true;
String^ newLine = Environment::NewLine;
directions->Text = String::Format( "Press the buttons that start {0}with 'Change' to see how different sizing {1}modes deal with content changes.", newLine, newLine );
flowLayoutPanel1->Controls->Add( directions );
}
void InitializeComponent()
{
flowLayoutPanel1 = gcnew FlowLayoutPanel;
flowLayoutPanel1->FlowDirection = FlowDirection::TopDown;
flowLayoutPanel1->Location = System::Drawing::Point( 492, 0 );
flowLayoutPanel1->AutoSize = true;
flowLayoutPanel1->TabIndex = 1;
ClientSize = System::Drawing::Size( 674, 419 );
Controls->Add( flowLayoutPanel1 );
Text = this->GetType()->Name;
AutoSize = true;
}
System::Drawing::Size startingSize;
String^ thirdColumnHeader;
String^ boringMeatloaf;
String^ boringMeatloafRanking;
bool boringRecipe;
bool shortMode;
DataGridView^ dataGridView1;
String^ otherRestaurant;
void InitializeDataGridView( Object^ /*ignored*/, EventArgs^ /*ignoredToo*/ )
{
dataGridView1 = gcnew System::Windows::Forms::DataGridView;
Controls->Add( dataGridView1 );
startingSize = System::Drawing::Size( 450, 400 );
dataGridView1->Size = startingSize;
dataGridView1->AutoSizeRowsModeChanged += gcnew DataGridViewAutoSizeModeEventHandler( this, &AutoSizing::WatchRowsModeChanges );
AddLabels();
SetUpColumns();
PopulateRows();
shortMode = false;
boringRecipe = true;
}
void SetUpColumns()
{
dataGridView1->ColumnCount = 4;
dataGridView1->ColumnHeadersVisible = true;
DataGridViewCellStyle ^ columnHeaderStyle = gcnew DataGridViewCellStyle;
columnHeaderStyle->BackColor = Color::Aqua;
columnHeaderStyle->Font = gcnew System::Drawing::Font( "Verdana",10,FontStyle::Bold );
dataGridView1->ColumnHeadersDefaultCellStyle = columnHeaderStyle;
dataGridView1->Columns[ 0 ]->Name = "Recipe";
dataGridView1->Columns[ 1 ]->Name = "Category";
dataGridView1->Columns[ 2 ]->Name = thirdColumnHeader;
dataGridView1->Columns[ 3 ]->Name = "Rating";
}
void PopulateRows()
{
array<String^>^row1 = {"Meatloaf","Main Dish",boringMeatloaf,boringMeatloafRanking};
array<String^>^row2 = {"Key Lime Pie","Dessert","lime juice, evaporated milk","****"};
array<String^>^row3 = {"Orange-Salsa Pork Chops","Main Dish","pork chops, salsa, orange juice","****"};
array<String^>^row4 = {"Black Bean and Rice Salad","Salad","black beans, brown rice","****"};
array<String^>^row5 = {"Chocolate Cheesecake","Dessert","cream cheese","***"};
array<String^>^row6 = {"Black Bean Dip","Appetizer","black beans, sour cream","***"};
array<Object^>^rows = {row1,row2,row3,row4,row5,row6};
IEnumerator^ myEnum = rows->GetEnumerator();
while ( myEnum->MoveNext() )
{
array<String^>^row = safe_cast<array<String^>^>(myEnum->Current);
dataGridView1->Rows->Add( row );
}
IEnumerator^ myEnum1 = safe_cast<IEnumerable^>(dataGridView1->Rows)->GetEnumerator();
while ( myEnum1->MoveNext() )
{
DataGridViewRow ^ row = safe_cast<DataGridViewRow ^>(myEnum1->Current);
if ( row->IsNewRow )
break;
row->HeaderCell->Value = String::Format( "Restaurant {0}", row->Index );
}
}
void AddButton( Button^ button, String^ buttonLabel, EventHandler^ handler )
{
button->Click += handler;
button->Text = buttonLabel;
button->AutoSize = true;
button->TabIndex = flowLayoutPanel1->Controls->Count;
flowLayoutPanel1->Controls->Add( button );
}
void ResetToDisorder( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Controls->Remove( dataGridView1 );
dataGridView1->DataGridView::~DataGridView();
InitializeDataGridView( nullptr, nullptr );
}
void ChangeColumn3Header( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Toggle( &shortMode );
if ( shortMode )
dataGridView1->Columns[ 2 ]->HeaderText = "S";
else
dataGridView1->Columns[ 2 ]->HeaderText = thirdColumnHeader;
}
Boolean Toggle( interior_ptr<Boolean> toggleThis )
{
*toggleThis = ! *toggleThis;
return *toggleThis;
}
void ChangeMeatloafRecipe( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Toggle( &boringRecipe );
if ( boringRecipe )
SetMeatloaf( boringMeatloaf, boringMeatloafRanking );
else
{
String^ greatMeatloafRecipe = "1 lb. lean ground beef, "
"1/2 cup bread crumbs, 1/4 cup ketchup,"
"1/3 tsp onion powder, "
"1 clove of garlic, 1/2 pack onion soup mix,"
" dash of your favorite BBQ Sauce";
SetMeatloaf( greatMeatloafRecipe, "***" );
}
}
void ChangeRestaurant( Object^ /*sender*/, EventArgs^ /*ignored*/ )
{
if ( dataGridView1->Rows[ 2 ]->HeaderCell->Value->ToString()->Equals( otherRestaurant ) )
dataGridView1->Rows[ 2 ]->HeaderCell->Value = "Restaurant 2";
else
dataGridView1->Rows[ 2 ]->HeaderCell->Value = otherRestaurant;
}
void SetMeatloaf( String^ recipe, String^ rating )
{
dataGridView1->Rows[ 0 ]->Cells[ 2 ]->Value = recipe;
dataGridView1->Rows[ 0 ]->Cells[ 3 ]->Value = rating;
}
String^ currentLayoutName;
void AddLabels()
{
Label^ current = dynamic_cast<Label^>(flowLayoutPanel1->Controls[ currentLayoutName ]);
if ( current == nullptr )
{
current = gcnew Label;
current->AutoSize = true;
current->Name = currentLayoutName;
current->Text = String::Concat( currentLayoutName, dataGridView1->AutoSizeRowsMode );
flowLayoutPanel1->Controls->Add( current );
}
}
void AddButtonsForAutomaticResizing()
{
AddButton( button5, "Keep Column Headers Sized", gcnew EventHandler( this, &AutoSizing::ColumnHeadersHeightSizeMode ) );
AddButton( button6, "Keep Row Headers Sized", gcnew EventHandler( this, &AutoSizing::RowHeadersWidthSizeMode ) );
AddButton( button7, "Keep Rows Sized", gcnew EventHandler( this, &AutoSizing::AutoSizeRowsMode ) );
AddButton( button8, "Keep Row Headers Sized with RowsMode", gcnew EventHandler( this, &AutoSizing::AutoSizeRowHeadersUsingAllHeadersMode ) );
AddButton( button9, "Disable AutoSizeRowsMode", gcnew EventHandler( this, &AutoSizing::DisableAutoSizeRowsMode ) );
AddButton( button10, "AutoSize third column by rows", gcnew EventHandler( this, &AutoSizing::AutoSizeOneColumn ) );
AddButton( button11, "AutoSize third column by rows and headers", gcnew EventHandler( this, &AutoSizing::AutoSizeOneColumnIncludingHeaders ) );
}
//<snippet7>
void ColumnHeadersHeightSizeMode( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode::AutoSize;
}
//</snippet7>
//<snippet8>
void RowHeadersWidthSizeMode( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders;
}
//</snippet8>
//<snippet9>
void AutoSizeRowsMode( Object^ /*sender*/, EventArgs^ /*es*/ )
{
dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::AllCells;
}
//</snippet9>
void AutoSizeRowHeadersUsingAllHeadersMode( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::AllHeaders;
}
//<snippet10>
void WatchRowsModeChanges( Object^ /*sender*/, DataGridViewAutoSizeModeEventArgs^ modeEvent )
{
Label^ label = dynamic_cast<Label^>(flowLayoutPanel1->Controls[ currentLayoutName ]);
if ( modeEvent->PreviousModeAutoSized )
{
label->Text = String::Format( "changed to a different {0}{1}", label->Name, dataGridView1->AutoSizeRowsMode );
}
else
{
label->Text = String::Concat( label->Name, dataGridView1->AutoSizeRowsMode );
}
}
//</snippet10>
void DisableAutoSizeRowsMode( Object^ /*sender*/, EventArgs^ /*modeEvent*/ )
{
dataGridView1->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::None;
}
//<snippet11>
void AutoSizeOneColumn( Object^ /*sender*/, EventArgs^ /*theEvent*/ )
{
DataGridViewColumn^ column = dataGridView1->Columns[ 2 ];
column->AutoSizeMode = DataGridViewAutoSizeColumnMode::DisplayedCellsExceptHeader;
}
//</snippet11>
void AutoSizeOneColumnIncludingHeaders( Object^ /*sender*/, EventArgs^ /*theEvent*/ )
{
DataGridViewColumn^ column = dataGridView1->Columns[ 2 ];
column->AutoSizeMode = DataGridViewAutoSizeColumnMode::AllCells;
}
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run( gcnew AutoSizing );
}
//</snippet0>
@@ -0,0 +1,328 @@
//<snippet0>
#using <System.Drawing.dll>
#using <System.dll>
#using <system.windows.forms.dll>
#using <system.drawing.dll>
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System;
using namespace System::Collections;
public ref class DataGridViewBandDemo: public Form
{
private:
#pragma region S " form setup "
public:
DataGridViewBandDemo()
{
Button1 = gcnew Button;
Button2 = gcnew Button;
Button3 = gcnew Button;
Button4 = gcnew Button;
Button5 = gcnew Button;
Button6 = gcnew Button;
Button7 = gcnew Button;
Button8 = gcnew Button;
Button9 = gcnew Button;
Button10 = gcnew Button;
FlowLayoutPanel1 = gcnew FlowLayoutPanel;
InitializeComponent();
thirdColumnHeader = L"Main Ingredients";
boringMeatloaf = L"ground beef";
boringMeatloafRanking = L"*";
AddButton( Button1, L"Reset", gcnew EventHandler( this, &DataGridViewBandDemo::Button1_Click ) );
AddButton( Button2, L"Change Column 3 Header", gcnew EventHandler( this, &DataGridViewBandDemo::Button2_Click ) );
AddButton( Button3, L"Change Meatloaf Recipe", gcnew EventHandler( this, &DataGridViewBandDemo::Button3_Click ) );
AddAdditionalButtons();
InitializeDataGridView();
}
DataGridView^ dataGridView;
Button^ Button1;
Button^ Button2;
Button^ Button3;
Button^ Button4;
Button^ Button5;
Button^ Button6;
Button^ Button7;
Button^ Button8;
Button^ Button9;
Button^ Button10;
FlowLayoutPanel^ FlowLayoutPanel1;
private:
void InitializeComponent()
{
FlowLayoutPanel1->Location = Point(454,0);
FlowLayoutPanel1->AutoSize = true;
FlowLayoutPanel1->FlowDirection = FlowDirection::TopDown;
AutoSize = true;
ClientSize = System::Drawing::Size( 614, 360 );
FlowLayoutPanel1->Name = L"flowlayoutpanel";
Controls->Add( this->FlowLayoutPanel1 );
Text = this->GetType()->Name;
}
#pragma endregion
#pragma region S " setup DataGridView "
String^ thirdColumnHeader;
String^ boringMeatloaf;
String^ boringMeatloafRanking;
bool boringRecipe;
Boolean shortMode;
void InitializeDataGridView()
{
dataGridView = gcnew System::Windows::Forms::DataGridView;
Controls->Add( dataGridView );
dataGridView->Size = System::Drawing::Size( 300, 200 );
// Create an unbound DataGridView by declaring a
// column count.
dataGridView->ColumnCount = 4;
AdjustDataGridViewSizing();
// Set the column header style.
DataGridViewCellStyle^ columnHeaderStyle = gcnew DataGridViewCellStyle;
columnHeaderStyle->BackColor = Color::Aqua;
columnHeaderStyle->Font = gcnew System::Drawing::Font( L"Verdana",10,FontStyle::Bold );
dataGridView->ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// Set the column header names.
dataGridView->Columns[ 0 ]->Name = L"Recipe";
dataGridView->Columns[ 1 ]->Name = L"Category";
dataGridView->Columns[ 2 ]->Name = thirdColumnHeader;
dataGridView->Columns[ 3 ]->Name = L"Rating";
// Populate the rows.
array<String^>^row1 = gcnew array<String^>{
L"Meatloaf",L"Main Dish",boringMeatloaf,boringMeatloafRanking
};
array<String^>^row2 = gcnew array<String^>{
L"Key Lime Pie",L"Dessert",L"lime juice, evaporated milk",L"****"
};
array<String^>^row3 = gcnew array<String^>{
L"Orange-Salsa Pork Chops",L"Main Dish",L"pork chops, salsa, orange juice",L"****"
};
array<String^>^row4 = gcnew array<String^>{
L"Black Bean and Rice Salad",L"Salad",L"black beans, brown rice",L"****"
};
array<String^>^row5 = gcnew array<String^>{
L"Chocolate Cheesecake",L"Dessert",L"cream cheese",L"***"
};
array<String^>^row6 = gcnew array<String^>{
L"Black Bean Dip",L"Appetizer",L"black beans, sour cream",L"***"
};
array<Object^>^rows = gcnew array<Object^>{
row1,row2,row3,row4,row5,row6
};
System::Collections::IEnumerator^ myEnum = rows->GetEnumerator();
while ( myEnum->MoveNext() )
{
array<String^>^rowArray = safe_cast<array<String^>^>(myEnum->Current);
dataGridView->Rows->Add( rowArray );
}
PostRowCreation();
shortMode = false;
boringRecipe = true;
}
void AddButton( Button^ button, String^ buttonLabel, EventHandler^ handler )
{
FlowLayoutPanel1->Controls->Add( button );
button->TabIndex = FlowLayoutPanel1->Controls->Count;
button->Text = buttonLabel;
button->AutoSize = true;
button->Click += handler;
}
// Reset columns to initial disorderly arrangement.
void Button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Controls->Remove( dataGridView );
dataGridView->~DataGridView();
InitializeDataGridView();
}
// Change the header in column three.
void Button2_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Toggle( &shortMode );
if ( shortMode )
{
dataGridView->Columns[ 2 ]->HeaderText = L"S";
}
else
{
dataGridView->Columns[ 2 ]->HeaderText = thirdColumnHeader;
}
}
void Toggle( interior_ptr<Boolean> toggleThis )
{
*toggleThis = ! *toggleThis;
}
// Change the meatloaf recipe.
void Button3_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Toggle( &boringRecipe );
if ( boringRecipe )
{
SetMeatloaf( boringMeatloaf, boringMeatloafRanking );
}
else
{
String^ greatMeatloafRecipe = L"1 lb. lean ground beef, "
L"1/2 cup bread crumbs, 1/4 cup ketchup,"
L"1/3 tsp onion powder, "
L"1 clove of garlic, 1/2 pack onion soup mix "
L" dash of your favorite BBQ Sauce";
SetMeatloaf( greatMeatloafRecipe, L"***" );
}
}
void SetMeatloaf( String^ recipe, String^ rating )
{
dataGridView->Rows[ 0 ]->Cells[ 2 ]->Value = recipe;
dataGridView->Rows[ 0 ]->Cells[ 3 ]->Value = rating;
}
#pragma endregion
#pragma region S " demonstration code "
void AddAdditionalButtons()
{
AddButton( Button4, L"Freeze First Row", gcnew EventHandler( this, &DataGridViewBandDemo::Button4_Click ) );
AddButton( Button5, L"Freeze Second Column", gcnew EventHandler( this, &DataGridViewBandDemo::Button5_Click ) );
AddButton( Button6, L"Hide Salad Row", gcnew EventHandler( this, &DataGridViewBandDemo::Button6_Click ) );
AddButton( Button7, L"Disable First Column Resizing", gcnew EventHandler( this, &DataGridViewBandDemo::Button7_Click ) );
AddButton( Button8, L"Make ReadOnly", gcnew EventHandler( this, &DataGridViewBandDemo::Button8_Click ) );
AddButton( Button9, L"Style Using Tag", gcnew EventHandler( this, &DataGridViewBandDemo::Button9_Click ) );
}
void AdjustDataGridViewSizing()
{
dataGridView->AutoSizeRowsMode = DataGridViewAutoSizeRowsMode::AllCells;
dataGridView->ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode::AutoSize;
}
//<snippet7>
// Freeze the first row.
void Button4_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
FreezeBand( dataGridView->Rows[ 0 ] );
}
void Button5_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
FreezeBand( dataGridView->Columns[ 1 ] );
}
void FreezeBand( DataGridViewBand^ band )
{
band->Frozen = true;
DataGridViewCellStyle^ style = gcnew DataGridViewCellStyle;
style->BackColor = Color::WhiteSmoke;
band->DefaultCellStyle = style;
}
//</snippet7>
//<snippet9>
// Hide a band of cells.
void Button6_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
DataGridViewBand^ band = dataGridView->Rows[ 3 ];
band->Visible = false;
}
//</snippet9>
//<snippet10>
// Turn off user's ability to resize a column.
void Button7_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
DataGridViewBand^ band = dataGridView->Columns[ 0 ];
band->Resizable = DataGridViewTriState::False;
}
//</snippet10>
//<snippet11>
// Make the entire DataGridView read only.
void Button8_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
System::Collections::IEnumerator^ myEnum = dataGridView->Columns->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewBand^ band = safe_cast<DataGridViewBand^>(myEnum->Current);
band->ReadOnly = true;
}
}
//</snippet11>
//<snippet12>
void PostRowCreation()
{
SetBandColor( dataGridView->Columns[ 0 ], Color::CadetBlue );
SetBandColor( dataGridView->Rows[ 1 ], Color::Coral );
SetBandColor( dataGridView->Columns[ 2 ], Color::DodgerBlue );
}
void SetBandColor( DataGridViewBand^ band, Color color )
{
band->Tag = color;
}
// Color the bands by the value stored in their tag.
void Button9_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
IEnumerator^ myEnum1 = dataGridView->Columns->GetEnumerator();
while ( myEnum1->MoveNext() )
{
DataGridViewBand^ band = static_cast<DataGridViewBand^>(myEnum1->Current);
if ( band->Tag != nullptr )
{
band->DefaultCellStyle->BackColor = *dynamic_cast<Color^>(band->Tag);
}
}
IEnumerator^ myEnum2 = safe_cast<IEnumerable^>(dataGridView->Rows)->GetEnumerator();
while ( myEnum2->MoveNext() )
{
DataGridViewBand^ band = safe_cast<DataGridViewBand^>(myEnum2->Current);
if ( band->Tag != nullptr )
{
band->DefaultCellStyle->BackColor = *dynamic_cast<Color^>(band->Tag);
}
}
}
//</snippet12>
#pragma endregion
public:
static void Main()
{
Application::Run( gcnew DataGridViewBandDemo );
}
};
int main()
{
DataGridViewBandDemo::Main();
}
//</snippet0>
@@ -0,0 +1,441 @@
//<snippet100>
#using <System.Drawing.dll>
#using <System.dll>
#using <system.windows.forms.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Collections;
public ref class DataGridViewColumnDemo: public Form
{
private:
#pragma region S "set up form"
public:
DataGridViewColumnDemo()
{
Button1 = gcnew Button;
Button2 = gcnew Button;
Button3 = gcnew Button;
Button4 = gcnew Button;
Button5 = gcnew Button;
Button6 = gcnew Button;
Button7 = gcnew Button;
Button8 = gcnew Button;
Button9 = gcnew Button;
Button10 = gcnew Button;
FlowLayoutPanel1 = gcnew FlowLayoutPanel;
thirdColumnHeader = L"Main Ingredients";
boringMeatloaf = L"ground beef";
boringMeatloafRanking = L"*";
toolStripItem1 = gcnew ToolStripMenuItem;
InitializeComponent();
AddButton( Button1, L"Reset", gcnew EventHandler( this, &DataGridViewColumnDemo::ResetToDisorder ) );
AddButton( Button2, L"Change Column 3 Header", gcnew EventHandler( this, &DataGridViewColumnDemo::ChangeColumn3Header ) );
AddButton( Button3, L"Change Meatloaf Recipe", gcnew EventHandler( this, &DataGridViewColumnDemo::ChangeMeatloafRecipe ) );
AddAdditionalButtons();
InitializeDataGridView();
}
DataGridView^ dataGridView;
Button^ Button1;
Button^ Button2;
Button^ Button3;
Button^ Button4;
Button^ Button5;
Button^ Button6;
Button^ Button7;
Button^ Button8;
Button^ Button9;
Button^ Button10;
FlowLayoutPanel^ FlowLayoutPanel1;
private:
void InitializeComponent()
{
FlowLayoutPanel1->Location = Point(454,0);
FlowLayoutPanel1->AutoSize = true;
FlowLayoutPanel1->FlowDirection = FlowDirection::TopDown;
AutoSize = true;
ClientSize = System::Drawing::Size( 614, 360 );
FlowLayoutPanel1->Name = L"flowlayoutpanel";
Controls->Add( this->FlowLayoutPanel1 );
Text = this->GetType()->Name;
}
#pragma endregion
#pragma region S " set up DataGridView "
String^ thirdColumnHeader;
String^ boringMeatloaf;
String^ boringMeatloafRanking;
bool boringRecipe;
bool shortMode;
void InitializeDataGridView()
{
dataGridView = gcnew System::Windows::Forms::DataGridView;
Controls->Add( dataGridView );
dataGridView->Size = System::Drawing::Size( 300, 200 );
// Create an unbound DataGridView by declaring a
// column count.
dataGridView->ColumnCount = 4;
AdjustDataGridViewSizing();
// Set the column header style.
DataGridViewCellStyle^ columnHeaderStyle = gcnew DataGridViewCellStyle;
columnHeaderStyle->BackColor = Color::Aqua;
columnHeaderStyle->Font = gcnew System::Drawing::Font( L"Verdana",10,FontStyle::Bold );
dataGridView->ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// Set the column header names.
dataGridView->Columns[ 0 ]->Name = L"Recipe";
dataGridView->Columns[ 1 ]->Name = L"Category";
dataGridView->Columns[ 2 ]->Name = thirdColumnHeader;
dataGridView->Columns[ 3 ]->Name = L"Rating";
criteriaLabel = L"Column 3 sizing criteria: ";
PostColumnCreation();
// Populate the rows.
array<String^>^row1 = gcnew array<String^>{
L"Meatloaf",L"Main Dish",boringMeatloaf,boringMeatloafRanking
};
array<String^>^row2 = gcnew array<String^>{
L"Key Lime Pie",L"Dessert",L"lime juice, evaporated milk",L"****"
};
array<String^>^row3 = gcnew array<String^>{
L"Orange-Salsa Pork Chops",L"Main Dish",L"pork chops, salsa, orange juice",L"****"
};
array<String^>^row4 = gcnew array<String^>{
L"Black Bean and Rice Salad",L"Salad",L"black beans, brown rice",L"****"
};
array<String^>^row5 = gcnew array<String^>{
L"Chocolate Cheesecake",L"Dessert",L"cream cheese",L"***"
};
array<String^>^row6 = gcnew array<String^>{
L"Black Bean Dip",L"Appetizer",L"black beans, sour cream",L"***"
};
array<Object^>^rows = gcnew array<Object^>{
row1,row2,row3,row4,row5,row6
};
System::Collections::IEnumerator^ myEnum = rows->GetEnumerator();
while ( myEnum->MoveNext() )
{
array<String^>^rowArray = safe_cast<array<String^>^>(myEnum->Current);
dataGridView->Rows->Add( rowArray );
}
shortMode = false;
boringRecipe = true;
}
void AddButton( Button^ button, String^ buttonLabel, EventHandler^ handler )
{
FlowLayoutPanel1->Controls->Add( button );
button->TabIndex = FlowLayoutPanel1->Controls->Count;
button->Text = buttonLabel;
button->AutoSize = true;
button->Click += handler;
}
void ResetToDisorder( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Controls->Remove( dataGridView );
dataGridView->~DataGridView();
InitializeDataGridView();
}
void ChangeColumn3Header( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Toggle( &shortMode );
if ( shortMode )
{
dataGridView->Columns[ 2 ]->HeaderText = L"S";
}
else
{
dataGridView->Columns[ 2 ]->HeaderText = thirdColumnHeader;
}
}
void Toggle( interior_ptr<Boolean> toggleThis )
{
*toggleThis = ! *toggleThis;
}
void ChangeMeatloafRecipe( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Toggle( &boringRecipe );
if ( boringRecipe )
{
SetMeatloaf( boringMeatloaf, boringMeatloafRanking );
}
else
{
String^ greatMeatloafRecipe = L"1 lb. lean ground beef, "
L"1/2 cup bread crumbs, 1/4 cup ketchup,"
L"1/3 tsp onion powder, "
L"1 clove of garlic, 1/2 pack onion soup mix "
L" dash of your favorite BBQ Sauce";
SetMeatloaf( greatMeatloafRecipe, L"***" );
}
}
void SetMeatloaf( String^ recipe, String^ rating )
{
dataGridView->Rows[ 0 ]->Cells[ 2 ]->Value = recipe;
dataGridView->Rows[ 0 ]->Cells[ 3 ]->Value = rating;
}
#pragma endregion
public:
static void Main()
{
Application::Run( gcnew DataGridViewColumnDemo );
}
#pragma region S " demonstration code "
private:
void PostColumnCreation()
{
AddContextLabel();
AddCriteriaLabel();
CustomizeCellsInThirdColumn();
AddContextMenu();
SetDefaultCellInFirstColumn();
ToolTips();
dataGridView->CellMouseEnter += gcnew DataGridViewCellEventHandler( this, &DataGridViewColumnDemo::dataGridView_CellMouseEnter );
dataGridView->AutoSizeColumnModeChanged += gcnew DataGridViewAutoSizeColumnModeEventHandler( this, &DataGridViewColumnDemo::dataGridView_AutoSizeColumnModeChanged );
}
String^ criteriaLabel;
void AddCriteriaLabel()
{
AddLabelToPanelIfNotAlreadyThere( criteriaLabel, String::Concat( criteriaLabel, dataGridView->Columns[ 2 ]->AutoSizeMode, L"." ) );
}
void AddContextLabel()
{
String^ labelName = L"label";
AddLabelToPanelIfNotAlreadyThere( labelName, L"Use shortcut menu to change cell color." );
}
void AddLabelToPanelIfNotAlreadyThere( String^ labelName, String^ labelText )
{
Label^ label;
if ( FlowLayoutPanel1->Controls[ labelName ] == nullptr )
{
label = gcnew Label;
label->AutoSize = true;
label->Name = labelName;
label->BackColor = Color::Bisque;
FlowLayoutPanel1->Controls->Add( label );
}
else
{
label = dynamic_cast<Label^>(FlowLayoutPanel1->Controls[ labelName ]);
}
label->Text = labelText;
}
//<snippet120>
void CustomizeCellsInThirdColumn()
{
int thirdColumn = 2;
DataGridViewColumn^ column = dataGridView->Columns[ thirdColumn ];
DataGridViewCell^ cell = gcnew DataGridViewTextBoxCell;
cell->Style->BackColor = Color::Wheat;
column->CellTemplate = cell;
}
//</snippet120>
//<snippet130>
ToolStripMenuItem^ toolStripItem1;
void AddContextMenu()
{
toolStripItem1->Text = L"Redden";
toolStripItem1->Click += gcnew EventHandler( this, &DataGridViewColumnDemo::toolStripItem1_Click );
System::Windows::Forms::ContextMenuStrip^ strip = gcnew System::Windows::Forms::ContextMenuStrip;
IEnumerator^ myEnum = dataGridView->Columns->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewColumn^ column = safe_cast<DataGridViewColumn^>(myEnum->Current);
column->ContextMenuStrip = strip;
column->ContextMenuStrip->Items->Add( toolStripItem1 );
}
}
DataGridViewCellEventArgs^ mouseLocation;
// Change the cell's color.
void toolStripItem1_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
dataGridView->Rows[ mouseLocation->RowIndex ]->Cells[ mouseLocation->ColumnIndex ]->Style->BackColor = Color::Red;
}
// Deal with hovering over a cell.
void dataGridView_CellMouseEnter( Object^ /*sender*/, DataGridViewCellEventArgs^ location )
{
mouseLocation = location;
}
//</snippet130>
//<snippet140>
void SetDefaultCellInFirstColumn()
{
DataGridViewColumn^ firstColumn = dataGridView->Columns[ 0 ];
DataGridViewCellStyle^ cellStyle = gcnew DataGridViewCellStyle;
cellStyle->BackColor = Color::Thistle;
firstColumn->DefaultCellStyle = cellStyle;
}
//</snippet140>
//<snippet145>
void ToolTips()
{
DataGridViewColumn^ firstColumn = dataGridView->Columns[ 0 ];
DataGridViewColumn^ thirdColumn = dataGridView->Columns[ 2 ];
firstColumn->ToolTipText = L"This column uses a default cell.";
thirdColumn->ToolTipText = L"This column uses a template cell."
L" Style changes to one cell apply to all cells.";
}
//</snippet145>
void AddAdditionalButtons()
{
AddButton( Button4, L"Set Minimum Width of Column Two", gcnew EventHandler( this, &DataGridViewColumnDemo::Button4_Click ) );
AddButton( Button5, L"Set Width of Column One", gcnew EventHandler( this, &DataGridViewColumnDemo::Button5_Click ) );
AddButton( Button6, L"Autosize Third Column", gcnew EventHandler( this, &DataGridViewColumnDemo::Button6_Click ) );
AddButton( Button7, L"Add Thick Vertical Edge", gcnew EventHandler( this, &DataGridViewColumnDemo::Button7_Click ) );
AddButton( Button8, L"Style and Number Columns", gcnew EventHandler( this, &DataGridViewColumnDemo::Button8_Click ) );
AddButton( Button9, L"Change Column Header Text", gcnew EventHandler( this, &DataGridViewColumnDemo::Button9_Click ) );
AddButton( Button10, L"Swap First and Last Columns", gcnew EventHandler( this, &DataGridViewColumnDemo::Button10_Click ) );
}
void AdjustDataGridViewSizing()
{
dataGridView->ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode::AutoSize;
}
//<snippet107>
//Set the minimum width.
void Button4_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
DataGridViewColumn^ column = dataGridView->Columns[ 1 ];
column->MinimumWidth = 40;
}
//</snippet107>
//<snippet108>
// Set the width.
void Button5_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
DataGridViewColumn^ column = dataGridView->Columns[ 0 ];
column->Width = 60;
}
//</snippet108>
//<snippet109>
// AutoSize the third column.
void Button6_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
DataGridViewColumn^ column = dataGridView->Columns[ 2 ];
column->AutoSizeMode = DataGridViewAutoSizeColumnMode::DisplayedCells;
}
//</snippet109>
//<snippet110>
// Set the vertical edge.
void Button7_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int thirdColumn = 2;
// int edgeThickness = 5;
DataGridViewColumn^ column = dataGridView->Columns[ thirdColumn ];
column->DividerWidth = 10;
}
//</snippet110>
//<snippet150>
// Style and number columns.
void Button8_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
DataGridViewCellStyle^ style = gcnew DataGridViewCellStyle;
style->Alignment = DataGridViewContentAlignment::MiddleCenter;
style->ForeColor = Color::IndianRed;
style->BackColor = Color::Ivory;
IEnumerator^ myEnum1 = dataGridView->Columns->GetEnumerator();
while ( myEnum1->MoveNext() )
{
DataGridViewColumn^ column = safe_cast<DataGridViewColumn^>(myEnum1->Current);
column->HeaderCell->Value = column->Index.ToString();
column->HeaderCell->Style = style;
}
}
//</snippet150>
//<snippet160>
// Change the text in the column header.
void Button9_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
IEnumerator^ myEnum2 = dataGridView->Columns->GetEnumerator();
while ( myEnum2->MoveNext() )
{
DataGridViewColumn^ column = safe_cast<DataGridViewColumn^>(myEnum2->Current);
column->HeaderText = String::Concat( L"Column ", column->Index.ToString() );
}
}
//</snippet160>
//<snippet170>
// Swap the last column with the first.
void Button10_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
DataGridViewColumnCollection^ columnCollection = dataGridView->Columns;
DataGridViewColumn^ firstDisplayedColumn = columnCollection->GetFirstColumn( DataGridViewElementStates::Visible );
DataGridViewColumn^ lastDisplayedColumn = columnCollection->GetLastColumn( DataGridViewElementStates::Visible, DataGridViewElementStates::None );
int firstColumn_sIndex = firstDisplayedColumn->DisplayIndex;
firstDisplayedColumn->DisplayIndex = lastDisplayedColumn->DisplayIndex;
lastDisplayedColumn->DisplayIndex = firstColumn_sIndex;
}
//</snippet170>
//<snippet180>
// Updated the criteria label.
void dataGridView_AutoSizeColumnModeChanged( Object^ /*sender*/, DataGridViewAutoSizeColumnModeEventArgs^ args )
{
args->Column->DataGridView->Parent->Controls[ L"flowlayoutpanel" ]->Controls[ criteriaLabel ]->Text = String::Concat( criteriaLabel, args->Column->AutoSizeMode );
}
//</snippet180>
#pragma endregion
};
int main()
{
DataGridViewColumnDemo::Main();
}
//</snippet100>
@@ -0,0 +1,304 @@
//<snippet200>
#using <System.Drawing.dll>
#using <System.dll>
#using <system.windows.forms.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
public ref class DataGridViewRowDemo: public Form
{
private:
#pragma region S " form setup "
public:
DataGridViewRowDemo()
{
Button1 = gcnew Button;
Button2 = gcnew Button;
Button3 = gcnew Button;
Button4 = gcnew Button;
Button5 = gcnew Button;
Button6 = gcnew Button;
Button7 = gcnew Button;
Button8 = gcnew Button;
Button9 = gcnew Button;
Button10 = gcnew Button;
FlowLayoutPanel1 = gcnew FlowLayoutPanel;
thirdColumnHeader = L"Main Ingredients";
boringMeatloaf = L"ground beef";
boringMeatloafRanking = L"*";
ratingColumn = 3;
AddButton( Button1, L"Reset", gcnew EventHandler( this, &DataGridViewRowDemo::Button1_Click ) );
AddButton( Button2, L"Change Column 3 Header", gcnew EventHandler( this, &DataGridViewRowDemo::Button2_Click ) );
AddButton( Button3, L"Change Meatloaf Recipe", gcnew EventHandler( this, &DataGridViewRowDemo::Button3_Click ) );
InitializeComponent();
InitializeDataGridView();
AddAdditionalButtons();
}
private:
DataGridView^ dataGridView;
Button^ Button1;
Button^ Button2;
Button^ Button3;
Button^ Button4;
Button^ Button5;
Button^ Button6;
Button^ Button7;
Button^ Button8;
Button^ Button9;
Button^ Button10;
FlowLayoutPanel^ FlowLayoutPanel1;
void InitializeComponent()
{
FlowLayoutPanel1->Location = Point(454,0);
FlowLayoutPanel1->AutoSize = true;
FlowLayoutPanel1->FlowDirection = FlowDirection::TopDown;
AutoSize = true;
ClientSize = System::Drawing::Size( 614, 360 );
FlowLayoutPanel1->Name = L"flowlayoutpanel";
Controls->Add( this->FlowLayoutPanel1 );
Text = this->GetType()->Name;
}
#pragma endregion
#pragma region S " setup DataGridView "
String^ thirdColumnHeader;
String^ boringMeatloaf;
String^ boringMeatloafRanking;
bool boringRecipe;
bool shortMode;
void InitializeDataGridView()
{
dataGridView = gcnew System::Windows::Forms::DataGridView;
Controls->Add( dataGridView );
dataGridView->Size = System::Drawing::Size( 300, 200 );
// Create an unbound DataGridView by declaring a
// column count.
dataGridView->ColumnCount = 4;
dataGridView->ColumnHeadersVisible = true;
AdjustDataGridViewSizing();
// Set the column header style.
DataGridViewCellStyle^ columnHeaderStyle = gcnew DataGridViewCellStyle;
columnHeaderStyle->BackColor = Color::Aqua;
columnHeaderStyle->Font = gcnew System::Drawing::Font( L"Verdana",10,FontStyle::Bold );
dataGridView->ColumnHeadersDefaultCellStyle = columnHeaderStyle;
// Set the column header names.
dataGridView->Columns[ 0 ]->Name = L"Recipe";
dataGridView->Columns[ 1 ]->Name = L"Category";
dataGridView->Columns[ 2 ]->Name = thirdColumnHeader;
dataGridView->Columns[ 3 ]->Name = L"Rating";
// Populate the rows.
array<String^>^row1 = gcnew array<String^>{
L"Meatloaf",L"Main Dish",boringMeatloaf,boringMeatloafRanking
};
array<String^>^row2 = gcnew array<String^>{
L"Key Lime Pie",L"Dessert",L"lime juice, evaporated milk",L"****"
};
array<String^>^row3 = gcnew array<String^>{
L"Orange-Salsa Pork Chops",L"Main Dish",L"pork chops, salsa, orange juice",L"****"
};
array<String^>^row4 = gcnew array<String^>{
L"Black Bean and Rice Salad",L"Salad",L"black beans, brown rice",L"****"
};
array<String^>^row5 = gcnew array<String^>{
L"Chocolate Cheesecake",L"Dessert",L"cream cheese",L"***"
};
array<String^>^row6 = gcnew array<String^>{
L"Black Bean Dip",L"Appetizer",L"black beans, sour cream",L"***"
};
array<Object^>^rows = gcnew array<Object^>{
row1,row2,row3,row4,row5,row6
};
System::Collections::IEnumerator^ myEnum = rows->GetEnumerator();
while ( myEnum->MoveNext() )
{
array<String^>^rowArray = safe_cast<array<String^>^>(myEnum->Current);
dataGridView->Rows->Add( rowArray );
}
shortMode = false;
boringRecipe = true;
}
void AddButton( Button^ button, String^ buttonLabel, EventHandler^ handler )
{
FlowLayoutPanel1->Controls->Add( button );
button->TabIndex = FlowLayoutPanel1->Controls->Count;
button->Text = buttonLabel;
button->AutoSize = true;
button->Click += handler;
}
// Reset columns to initial disorderly arrangement.
void Button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Controls->Remove( dataGridView );
dataGridView->~DataGridView();
InitializeDataGridView();
}
// Change column 3 header.
void Button2_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Toggle( &shortMode );
if ( shortMode )
{
dataGridView->Columns[ 2 ]->HeaderText = L"S";
}
else
{
dataGridView->Columns[ 2 ]->HeaderText = thirdColumnHeader;
}
}
void Toggle( interior_ptr<Boolean> toggleThis )
{
*toggleThis = ! *toggleThis;
}
// Change meatloaf recipe.
void Button3_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
Toggle( &boringRecipe );
if ( boringRecipe )
{
SetMeatloaf( boringMeatloaf, boringMeatloafRanking );
}
else
{
String^ greatMeatloafRecipe = L"1 lb. lean ground beef, "
L"1/2 cup bread crumbs, 1/4 cup ketchup,"
L"1/3 tsp onion powder, "
L"1 clove of garlic, 1/2 pack onion soup mix "
L" dash of your favorite BBQ Sauce";
SetMeatloaf( greatMeatloafRecipe, L"***" );
}
}
void SetMeatloaf( String^ recipe, String^ rating )
{
dataGridView->Rows[ 0 ]->Cells[ 2 ]->Value = recipe;
dataGridView->Rows[ 0 ]->Cells[ 3 ]->Value = rating;
}
#pragma endregion
#pragma region S " demonstration code "
void AddAdditionalButtons()
{
AddButton( Button4, L"Set Row Two Minimum Height", gcnew EventHandler( this, &DataGridViewRowDemo::Button4_Click ) );
AddButton( Button5, L"Set Row One Height", gcnew EventHandler( this, &DataGridViewRowDemo::Button5_Click ) );
AddButton( Button6, L"Label Rows", gcnew EventHandler( this, &DataGridViewRowDemo::Button6_Click ) );
AddButton( Button7, L"Turn on Extra Edge", gcnew EventHandler( this, &DataGridViewRowDemo::Button7_Click ) );
AddButton( Button8, L"Give Cheesecake an Excellent Rating", gcnew EventHandler( this, &DataGridViewRowDemo::Button8_Click ) );
}
void AdjustDataGridViewSizing()
{
dataGridView->ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode::AutoSize;
dataGridView->Columns[ ratingColumn ]->Width = 50;
}
//<snippet207>
// Set minimum height.
void Button4_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int secondRow = 1;
DataGridViewRow^ row = dataGridView->Rows[ secondRow ];
row->MinimumHeight = 40;
}
//</snippet207>
//<snippet208>
// Set height.
void Button5_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
DataGridViewRow^ row = dataGridView->Rows[ 0 ];
row->Height = 15;
}
//</snippet208>
//<snippet209>
// Set row labels.
void Button6_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int rowNumber = 1;
System::Collections::IEnumerator^ myEnum = safe_cast<System::Collections::IEnumerable^>(dataGridView->Rows)->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewRow^ row = safe_cast<DataGridViewRow^>(myEnum->Current);
if ( row->IsNewRow )
continue;
row->HeaderCell->Value = String::Format( L"Row {0}", rowNumber );
rowNumber = rowNumber + 1;
}
dataGridView->AutoResizeRowHeadersWidth( DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders );
}
//</snippet209>
//<snippet210>
// Set a thick horizontal edge.
void Button7_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
int secondRow = 1;
int edgeThickness = 3;
DataGridViewRow^ row = dataGridView->Rows[ secondRow ];
row->DividerHeight = 10;
}
//</snippet210>
//<snippet211>
// Give cheescake excellent rating.
void Button8_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
UpdateStars( dataGridView->Rows[ 4 ], L"******************" );
}
int ratingColumn;
void UpdateStars( DataGridViewRow^ row, String^ stars )
{
row->Cells[ ratingColumn ]->Value = stars;
// Resize the column width to account for the new value.
row->DataGridView->AutoResizeColumn( ratingColumn, DataGridViewAutoSizeColumnMode::DisplayedCells );
}
//</snippet211>
#pragma endregion
public:
static void Main()
{
Application::Run( gcnew DataGridViewRowDemo );
}
};
int main()
{
DataGridViewRowDemo::Main();
}
//</snippet200>
@@ -0,0 +1,10 @@
all: DataGridViewBandDemo.exe DataGridViewColumnDemo.exe DataGridViewRowDemo.exe
DataGridViewBandDemo.exe: DataGridViewBandDemo.cpp
cl /clr:pure DataGridViewBandDemo.cpp
DataGridViewColumnDemo.exe: DataGridViewColumnDemo.cpp
cl /clr:pure DataGridViewColumnDemo.cpp
DataGridViewRowDemo.exe: DataGridViewRowDemo.cpp
cl /clr:pure DataGridViewRowDemo.cpp
@@ -0,0 +1,480 @@
// This example demonstrates using images to create a
// TicTacToe game.
//<snippet0>
#using <System.Drawing.dll>
#using <System.dll>
#using <system.windows.forms.dll>
using namespace System::IO;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System;
public ref class TicTacToe: public System::Windows::Forms::Form
{
public:
TicTacToe()
: Form()
{
oBytes = gcnew array<Byte>{
0x42, 0x4D, 0xC6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x76,
0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xB, 0x0, 0x0, 0x0, 0xA,
0x0, 0x0, 0x0, 0x1, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x50,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10,
0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x80, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x80, 0x80, 0x0,
0x80, 0x0, 0x0, 0x0, 0x80, 0x0, 0x80, 0x0, 0x80, 0x80, 0x0,
0x0, 0xC0, 0xC0, 0xC0, 0x0, 0x80, 0x80, 0x80, 0x0, 0x0, 0x0,
0xFF, 0x0, 0x0, 0xFF, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0x0, 0xFF,
0x0, 0x0, 0x0, 0xFF, 0x0, 0xFF, 0x0, 0xFF, 0xFF, 0x0, 0x0,
0xFF, 0xFF, 0xFF, 0x0, 0xFF, 0xFF, 0x0, 0xF, 0xFF, 0xF0,
0x0, 0x0, 0xFF, 0x0, 0xFF, 0xF0, 0xF, 0xF0, 0x0, 0x0, 0xF0,
0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0x0, 0x0, 0xF0, 0xFF, 0xFF,
0xFF, 0xF0, 0xF0, 0x0, 0x0, 0xF, 0xFF, 0xFF, 0xFF, 0xFF,
0x0, 0x0, 0x0, 0xF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0, 0x0, 0x0,
0xF0, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0x0, 0x0, 0xF0, 0xFF,
0xFF, 0xFF, 0xF0, 0xF0, 0x0, 0x0, 0xFF, 0x0, 0xFF, 0xF0,
0xF, 0xF0, 0x0, 0x0, 0xFF, 0xFF, 0x0, 0xF, 0xFF, 0xF0, 0x0,
0x0};
xBytes = gcnew array<Byte>{
0x42, 0x4D, 0xC6, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x76, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0,
0xB, 0x0, 0x0, 0x0, 0xA, 0x0, 0x0, 0x0, 0x1, 0x0, 0x4, 0x0,
0x0, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x80,
0x0, 0x0, 0x0, 0x80, 0x80, 0x0, 0x80, 0x0, 0x0, 0x0, 0x80,
0x0, 0x80, 0x0, 0x80, 0x80, 0x0, 0x0, 0xC0, 0xC0, 0xC0, 0x0,
0x80, 0x80, 0x80, 0x0, 0x0, 0x0, 0xFF, 0x0, 0x0, 0xFF, 0x0,
0x0, 0x0, 0xFF, 0xFF, 0x0, 0xFF, 0x0, 0x0, 0x0, 0xFF, 0x0,
0xFF, 0x0, 0xFF, 0xFF, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0x0,
0xF0, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0x0, 0x0, 0xFF, 0xF,
0xFF, 0xFF, 0xF, 0xF0, 0x0, 0x0, 0xFF, 0xF0, 0xFF, 0xF0,
0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF, 0xF, 0xF, 0xFF, 0xF0, 0x0,
0x0, 0xFF, 0xFF, 0xF, 0xF, 0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF,
0xF, 0xF, 0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xF0, 0xFF, 0xF0,
0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xF, 0xFF, 0xFF, 0xF, 0xF0, 0x0,
0x0, 0xF0, 0xFF, 0xFF, 0xFF, 0xF0, 0xF0, 0x0, 0x0, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0};
blankBytes = gcnew array<Byte>{
0x42, 0x4D, 0xC6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x76,
0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xB, 0x0, 0x0, 0x0, 0xA,
0x0, 0x0, 0x0, 0x1, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x50,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10,
0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x80, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x80, 0x80, 0x0,
0x80, 0x0, 0x0, 0x0, 0x80, 0x0, 0x80, 0x0, 0x80, 0x80, 0x0,
0x0, 0xC0, 0xC0, 0xC0, 0x0, 0x80, 0x80, 0x80, 0x0, 0x0, 0x0,
0xFF, 0x0, 0x0, 0xFF, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0x0, 0xFF,
0x0, 0x0, 0x0, 0xFF, 0x0, 0xFF, 0x0, 0xFF, 0xFF, 0x0, 0x0,
0xFF, 0xFF, 0xFF, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0,
0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0,
0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xF0, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xF0, 0x0, 0x0};
blank = gcnew Bitmap( gcnew MemoryStream( blankBytes ) );
x = gcnew Bitmap( gcnew MemoryStream( xBytes ) );
o = gcnew Bitmap( gcnew MemoryStream( oBytes ) );
this->AutoSize = true;
turn = gcnew Label;
Button1 = gcnew Button;
Button2 = gcnew Button;
Button3 = gcnew Button;
Button4 = gcnew Button;
Button5 = gcnew Button;
Panel1 = gcnew FlowLayoutPanel;
SetupButtons();
InitializeDataGridView( nullptr, nullptr );
xString = L"X's turn";
oString = L"O's turn";
gameOverString = L"Game Over";
bitmapPadding = 6;
}
private:
DataGridView^ dataGridView1;
Button^ Button1;
Label^ turn;
Button^ Button2;
Button^ Button3;
Button^ Button4;
Button^ Button5;
FlowLayoutPanel^ Panel1;
#pragma region S " bitmaps "
array<Byte>^oBytes;
array<Byte>^xBytes;
array<Byte>^blankBytes;
#pragma endregion
Bitmap^ blank;
Bitmap^ x;
Bitmap^ o;
String^ xString;
String^ oString;
String^ gameOverString;
int bitmapPadding;
void InitializeDataGridView( Object^ ignored, EventArgs^ e )
{
this->Panel1->SuspendLayout();
this->SuspendLayout();
ConfigureForm();
SizeGrid();
CreateColumns();
CreateRows();
this->Panel1->ResumeLayout( false );
this->ResumeLayout( false );
}
void ConfigureForm()
{
AutoSize = true;
turn->Size = System::Drawing::Size( 75, 34 );
turn->TextAlign = ContentAlignment::MiddleLeft;
Panel1->Location = System::Drawing::Point( 0, 8 );
Panel1->Size = System::Drawing::Size( 120, 196 );
Panel1->FlowDirection = FlowDirection::TopDown;
ClientSize = System::Drawing::Size( 355, 200 );
Controls->Add( this->Panel1 );
Text = L"TicTacToe";
dataGridView1 = gcnew System::Windows::Forms::DataGridView;
dataGridView1->Location = Point(120,0);
dataGridView1->AllowUserToAddRows = false;
dataGridView1->CellClick += gcnew DataGridViewCellEventHandler( this, &TicTacToe::dataGridView1_CellClick );
dataGridView1->CellMouseEnter += gcnew DataGridViewCellEventHandler( this, &TicTacToe::dataGridView1_CellMouseEnter );
dataGridView1->CellMouseLeave += gcnew DataGridViewCellEventHandler( this, &TicTacToe::dataGridView1_CellMouseLeave );
Controls->Add( dataGridView1 );
turn->Text = xString;
turn->AutoSize = true;
}
void SetupButtons()
{
Button1->AutoSize = true;
SetupButton( Button1, L"Restart", gcnew EventHandler( this, &TicTacToe::Reset ) );
Panel1->Controls->Add( turn );
SetupButton( Button2, L"Increase Cell Size", gcnew EventHandler( this, &TicTacToe::MakeCellsLarger ) );
SetupButton( Button3, L"Stretch Images", gcnew EventHandler( this, &TicTacToe::Stretch ) );
SetupButton( Button4, L"Zoom Images", gcnew EventHandler( this, &TicTacToe::ZoomToImage ) );
SetupButton( Button5, L"Normal Images", gcnew EventHandler( this, &TicTacToe::NormalImage ) );
}
void SetupButton( Button^ button, String^ buttonLabel, EventHandler^ handler )
{
Panel1->Controls->Add( button );
button->Text = buttonLabel;
button->AutoSize = true;
button->Click += handler;
}
//<snippet5>
void CreateColumns()
{
DataGridViewImageColumn^ imageColumn;
int columnCount = 0;
do
{
Bitmap^ unMarked = blank;
imageColumn = gcnew DataGridViewImageColumn;
//Add twice the padding for the left and
//right sides of the cell.
imageColumn->Width = x->Width + 2 * bitmapPadding + 1;
imageColumn->Image = unMarked;
dataGridView1->Columns->Add( imageColumn );
columnCount = columnCount + 1;
}
while ( columnCount < 3 );
}
//</snippet5>
void CreateRows()
{
dataGridView1->Rows->Add();
dataGridView1->Rows->Add();
dataGridView1->Rows->Add();
}
//<snippet7>
void SizeGrid()
{
dataGridView1->ColumnHeadersVisible = false;
dataGridView1->RowHeadersVisible = false;
dataGridView1->AllowUserToResizeColumns = false;
dataGridView1->AllowUserToResizeRows = false;
dataGridView1->BorderStyle = BorderStyle::None;
//Add twice the padding for the top of the cell
//and the bottom.
dataGridView1->RowTemplate->Height = x->Height + 2 * bitmapPadding + 1;
dataGridView1->AutoSize = true;
}
//</snippet7>
void Reset( Object^ sender, System::EventArgs^ e )
{
dataGridView1->~DataGridView();
InitializeDataGridView( nullptr, nullptr );
}
//<snippet10>
void dataGridView1_CellClick( Object^ sender, DataGridViewCellEventArgs^ e )
{
if ( turn->Equals( gameOverString ) )
{
return;
}
DataGridViewImageCell^ cell = dynamic_cast<DataGridViewImageCell^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]);
if ( cell->Value == blank )
{
if ( IsOsTurn() )
{
cell->Value = o;
}
else
{
cell->Value = x;
}
ToggleTurn();
}
if ( IsAWin( cell ) )
{
turn->Text = gameOverString;
}
}
//</snippet10>
//<snippet15>
void dataGridView1_CellMouseEnter( Object^ sender, DataGridViewCellEventArgs^ e )
{
Bitmap^ markingUnderMouse = dynamic_cast<Bitmap^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]->Value);
if ( markingUnderMouse == blank )
{
dataGridView1->Cursor = Cursors::Default;
}
else
if ( markingUnderMouse == o || markingUnderMouse == x )
{
dataGridView1->Cursor = Cursors::No;
ToolTip(e,true);
}
}
void ToolTip( DataGridViewCellEventArgs^ e, bool showTip )
{
DataGridViewImageCell^ cell = dynamic_cast<DataGridViewImageCell^>(dataGridView1->Rows[ e->RowIndex ]->Cells[ e->ColumnIndex ]);
DataGridViewImageColumn^ imageColumn = dynamic_cast<DataGridViewImageColumn^>(dataGridView1->Columns[ cell->ColumnIndex ]);
if ( showTip )
cell->ToolTipText = imageColumn->Description;
else
{
cell->ToolTipText = String::Empty;
}
}
void dataGridView1_CellMouseLeave( Object^ sender, DataGridViewCellEventArgs^ e )
{
ToolTip( e, false );
dataGridView1->Cursor = Cursors::Default;
}
//</snippet15>
//<snippet20>
void Stretch( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum = dataGridView1->Columns->GetEnumerator();
while ( myEnum->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum->Current);
column->ImageLayout = DataGridViewImageCellLayout::Stretch;
column->Description = L"Stretched";
}
}
void ZoomToImage( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum1 = dataGridView1->Columns->GetEnumerator();
while ( myEnum1->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum1->Current);
column->ImageLayout = DataGridViewImageCellLayout::Zoom;
column->Description = L"Zoomed";
}
}
void NormalImage( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum2 = dataGridView1->Columns->GetEnumerator();
while ( myEnum2->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum2->Current);
column->ImageLayout = DataGridViewImageCellLayout::Normal;
column->Description = L"Normal";
}
}
//</snippet20>
void MakeCellsLarger( Object^ sender, EventArgs^ e )
{
System::Collections::IEnumerator^ myEnum3 = dataGridView1->Columns->GetEnumerator();
while ( myEnum3->MoveNext() )
{
DataGridViewImageColumn^ column = safe_cast<DataGridViewImageColumn^>(myEnum3->Current);
column->Width = column->Width * 2;
}
System::Collections::IEnumerable^ temp = safe_cast<System::Collections::IEnumerable^>(dataGridView1->Rows);
System::Collections::IEnumerator^ myEnum4 = temp->GetEnumerator();
//System::Collections::IEnumerator^ myEnum4 = dataGridView1->Rows->GetEnumerator();
while ( myEnum4->MoveNext() )
{
DataGridViewRow^ row = safe_cast<DataGridViewRow^>(myEnum4->Current);
if ( row->IsNewRow )
break;
row->Height = (int)(row->Height * 1.5);
}
}
bool IsAWin( DataGridViewCell^ cell )
{
if ( ARowIsSame() || AColumnIsSame() || ADiagonalIsSame() )
return true;
else
return false;
}
bool ARowIsSame()
{
Bitmap^ marking = nullptr;
System::Collections::IEnumerable^ temp = safe_cast<System::Collections::IEnumerable^>(dataGridView1->Rows);
System::Collections::IEnumerator^ myEnum5 = temp->GetEnumerator();
//System::Collections::IEnumerator^ myEnum5 = dataGridView1->Rows->GetEnumerator();
while ( myEnum5->MoveNext() )
{
DataGridViewRow^ row = safe_cast<DataGridViewRow^>(myEnum5->Current);
if ( row->IsNewRow )
break;
marking = dynamic_cast<Bitmap^>(row->Cells[ 0 ]->Value);
if ( marking != blank )
{
if ( marking == row->Cells[ 1 ]->Value && marking == row->Cells[ 2 ]->Value )
return true;
}
}
return false;
}
bool AColumnIsSame()
{
int columnIndex = 0;
Bitmap^ marking;
do
{
marking = dynamic_cast<Bitmap^>(dataGridView1->Rows[ 0 ]->Cells[ columnIndex ]->Value);
if ( marking != blank )
{
if ( marking == dynamic_cast<Bitmap^>(dataGridView1->Rows[ 1 ]->Cells[ columnIndex ]->Value) && marking == dynamic_cast<Bitmap^>(dataGridView1->Rows[ 2 ]->Cells[ columnIndex ]->Value) )
return true;
}
columnIndex = columnIndex + 1;
}
while ( columnIndex < dataGridView1->Columns->GetColumnCount( DataGridViewElementStates::Visible ) );
return false;
}
bool ADiagonalIsSame()
{
if ( LeftToRightDiagonalIsSame() )
{
return true;
}
if ( RightToLeftDiagonalIsSame() )
{
return true;
}
return false;
}
bool LeftToRightDiagonalIsSame()
{
return IsDiagonalSame( 0, 2 );
}
bool RightToLeftDiagonalIsSame()
{
return IsDiagonalSame( 2, 0 );
}
bool IsDiagonalSame( int startingColumn, int lastColumn )
{
Bitmap^ marking = dynamic_cast<Bitmap^>(dataGridView1->Rows[ 0 ]->Cells[ startingColumn ]->Value);
if ( marking == blank )
return false;
if ( marking == dataGridView1->Rows[ 1 ]->Cells[ 1 ]->Value && marking == dataGridView1->Rows[ 2 ]->Cells[ lastColumn ]->Value )
return true;
return false;
}
void ToggleTurn()
{
if ( turn->Text->Equals( xString ) )
{
turn->Text = oString;
}
else
{
turn->Text = xString;
}
}
bool IsOsTurn()
{
if ( turn->Text->Equals( oString ) )
return true;
return false;
}
public:
[STAThread]
static void Main()
{
Application::Run( gcnew TicTacToe );
}
};
int main()
{
TicTacToe::Main();
}
//</snippet0>
@@ -0,0 +1,281 @@
//<snippet0>
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
public ref class ProgrammaticSizing: public System::Windows::Forms::Form
{
private:
FlowLayoutPanel^ flowLayoutPanel1;
Button^ button1;
Button^ button2;
Button^ button3;
Button^ button4;
Button^ button5;
Button^ button6;
Button^ button7;
Button^ button8;
Button^ button9;
Button^ button10;
Button^ button11;
public:
ProgrammaticSizing()
{
button1 = gcnew Button;
button2 = gcnew Button;
button3 = gcnew Button;
button4 = gcnew Button;
button5 = gcnew Button;
button6 = gcnew Button;
button7 = gcnew Button;
button8 = gcnew Button;
button9 = gcnew Button;
button10 = gcnew Button;
button11 = gcnew Button;
thirdColumnHeader = "Main Ingredients";
boringMeatloaf = "ground beef";
boringMeatloafRanking = "*";
otherResturant = "Gomes's Saharan Sushi";
InitializeComponent();
AddDirections();
this->Load += gcnew EventHandler( this, &ProgrammaticSizing::InitializeDataGridView );
AddButton( button1, "Reset", gcnew EventHandler( this, &ProgrammaticSizing::ResetToDisorder ) );
AddButton( button2, "Change Column 3 Header", gcnew EventHandler( this, &ProgrammaticSizing::ChangeColumn3Header ) );
AddButton( button3, "Change Meatloaf Recipe", gcnew EventHandler( this, &ProgrammaticSizing::ChangeMeatloafRecipe ) );
AddButton( button10, "Change Resturant 2", gcnew EventHandler( this, &ProgrammaticSizing::ChangeResturant ) );
AddButtonsForProgrammaticResizing();
}
private:
void InitializeComponent()
{
this->flowLayoutPanel1 = gcnew FlowLayoutPanel;
this->flowLayoutPanel1->FlowDirection = FlowDirection::TopDown;
this->flowLayoutPanel1->Location = Point(492,0);
this->flowLayoutPanel1->AutoSize = true;
this->AutoSize = true;
this->Controls->Add( this->flowLayoutPanel1 );
this->Text = this->GetType()->Name;
}
void AddDirections()
{
Label^ directions = gcnew Label;
directions->AutoSize = true;
String^ newLine = Environment::NewLine;
directions->Text = String::Format( "Press the buttons that start {0}with 'Change' to see how different sizing {1}modes deal with content changes.", newLine, newLine );
flowLayoutPanel1->Controls->Add( directions );
}
System::Drawing::Size startingSize;
String^ thirdColumnHeader;
String^ boringMeatloaf;
String^ boringMeatloafRanking;
bool boringRecipe;
bool shortMode;
DataGridView^ dataGridView1;
String^ otherResturant;
void InitializeDataGridView( Object^ /*sender*/, EventArgs^ /*ignoredToo*/ )
{
this->dataGridView1 = gcnew DataGridView;
this->dataGridView1->Location = Point(0,0);
this->dataGridView1->Size = System::Drawing::Size( 292, 266 );
this->Controls->Add( this->dataGridView1 );
startingSize = System::Drawing::Size( 450, 400 );
dataGridView1->Size = startingSize;
AddColumns();
PopulateRows();
shortMode = false;
boringRecipe = true;
}
void AddColumns()
{
dataGridView1->ColumnCount = 4;
dataGridView1->ColumnHeadersVisible = true;
DataGridViewCellStyle ^ columnHeaderStyle = gcnew DataGridViewCellStyle;
columnHeaderStyle->BackColor = Color::Aqua;
columnHeaderStyle->Font = gcnew System::Drawing::Font( "Verdana",10,FontStyle::Bold );
dataGridView1->ColumnHeadersDefaultCellStyle = columnHeaderStyle;
dataGridView1->Columns[ 0 ]->Name = "Recipe";
dataGridView1->Columns[ 1 ]->Name = "Category";
dataGridView1->Columns[ 2 ]->Name = thirdColumnHeader;
dataGridView1->Columns[ 3 ]->Name = "Rating";
}
void PopulateRows()
{
array<String^>^row1 = {"Meatloaf","Main Dish",boringMeatloaf,boringMeatloafRanking};
array<String^>^row2 = {"Key Lime Pie","Dessert","lime juice, evaporated milk","****"};
array<String^>^row3 = {"Orange-Salsa Pork Chops","Main Dish","pork chops, salsa, orange juice","****"};
array<String^>^row4 = {"Black Bean and Rice Salad","Salad","black beans, brown rice","****"};
array<String^>^row5 = {"Chocolate Cheesecake","Dessert","cream cheese","***"};
array<String^>^row6 = {"Black Bean Dip","Appetizer","black beans, sour cream","***"};
array<Object^>^rows = {row1,row2,row3,row4,row5,row6};
IEnumerator^ myEnum = rows->GetEnumerator();
while ( myEnum->MoveNext() )
{
array<String^>^row = safe_cast<array<String^>^>(myEnum->Current);
dataGridView1->Rows->Add( row );
}
IEnumerator^ myEnum1 = safe_cast<IEnumerable^>(dataGridView1->Rows)->GetEnumerator();
while ( myEnum1->MoveNext() )
{
DataGridViewRow ^ row = safe_cast<DataGridViewRow ^>(myEnum1->Current);
if ( row->IsNewRow )
break;
row->HeaderCell->Value = String::Format( "Resturant {0}", row->Index );
}
}
void AddButton( Button^ button, String^ buttonLabel, EventHandler^ handler )
{
button->Text = buttonLabel;
button->AutoSize = true;
flowLayoutPanel1->Controls->Add( button );
button->Click += handler;
}
void ResetToDisorder( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Controls->Remove( dataGridView1 );
dataGridView1->Size = startingSize;
dataGridView1->DataGridView::~DataGridView();
InitializeDataGridView( nullptr, nullptr );
}
void ChangeColumn3Header( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Toggle( &shortMode );
if ( shortMode )
dataGridView1->Columns[ 2 ]->HeaderText = "S";
else
dataGridView1->Columns[ 2 ]->HeaderText = thirdColumnHeader;
}
void Toggle( interior_ptr<Boolean> toggleThis )
{
*toggleThis = ! *toggleThis;
}
void ChangeMeatloafRecipe( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Toggle( &boringRecipe );
if ( boringRecipe )
SetMeatloaf( boringMeatloaf, boringMeatloafRanking );
else
{
String^ greatMeatloafRecipe = "1 lb. lean ground beef, "
"1/2 cup bread crumbs, 1/4 cup ketchup,"
"1/3 tsp onion powder, "
"1 clove of garlic, 1/2 pack onion soup mix "
" dash of your favorite BBQ Sauce";
SetMeatloaf( greatMeatloafRecipe, "***" );
}
}
void SetMeatloaf( String^ recipe, String^ rating )
{
dataGridView1->Rows[ 0 ]->Cells[ 2 ]->Value = recipe;
dataGridView1->Rows[ 0 ]->Cells[ 3 ]->Value = rating;
}
void ChangeResturant( Object^ /*sender*/, EventArgs^ /*ignored*/ )
{
if ( dataGridView1->Rows[ 2 ]->HeaderCell->Value == otherResturant )
dataGridView1->Rows[ 2 ]->HeaderCell->Value = "Resturant 2";
else
dataGridView1->Rows[ 2 ]->HeaderCell->Value = otherResturant;
}
void AddButtonsForProgrammaticResizing()
{
AddButton( button4, "Size Third Column", gcnew EventHandler( this, &ProgrammaticSizing::SizeThirdColumnHeader ) );
AddButton( button5, "Size Column Headers", gcnew EventHandler( this, &ProgrammaticSizing::SizeColumnHeaders ) );
AddButton( button6, "Size All Columns", gcnew EventHandler( this, &ProgrammaticSizing::SizeAllColumns ) );
AddButton( button7, "Size Third Row", gcnew EventHandler( this, &ProgrammaticSizing::SizeThirdRow ) );
AddButton( button8, "Size First Row Header Using All Headers", gcnew EventHandler( this, &ProgrammaticSizing::SizeFirstRowHeaderToAllHeaders ) );
AddButton( button9, "Size All Rows and Row Headers", gcnew EventHandler( this, &ProgrammaticSizing::SizeAllRowsAndTheirHeaders ) );
AddButton( button11, "Size All Rows ", gcnew EventHandler( this, &ProgrammaticSizing::SizeAllRows ) );
}
//<snippet1>
void SizeThirdColumnHeader( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeColumn(2, DataGridViewAutoSizeColumnMode::ColumnHeader);
}
//</snippet1>
//<snippet2>
void SizeColumnHeaders( Object^ /*sender*/, EventArgs^ /*e*/ )
{
int columnNumber;
bool dontChangeColumnWidth;
bool dontChangeRowHeadersWidth;
dataGridView1->AutoResizeColumnHeadersHeight(2);
}
//</snippet2>
//<snippet3>
void SizeAllColumns( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeColumns( DataGridViewAutoSizeColumnsMode::AllCells );
}
//</snippet3>
//<snippet4>
void SizeThirdRow( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeRow(2, DataGridViewAutoSizeRowMode::AllCellsExceptHeader);
}
//</snippet4>
//<snippet5>
void SizeFirstRowHeaderToAllHeaders( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeRowHeadersWidth(0, DataGridViewRowHeadersWidthSizeMode::AutoSizeToAllHeaders);
}
//</snippet5>
//<snippet6>
void SizeAllRowsAndTheirHeaders( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeRows(DataGridViewAutoSizeRowsMode::AllCells);
}
//</snippet6>
//<snippet7>
void SizeAllRows( Object^ /*sender*/, EventArgs^ /*e*/ )
{
dataGridView1->AutoResizeRows(DataGridViewAutoSizeRowsMode::AllCellsExceptHeaders);
}
//</snippet7>
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run( gcnew ProgrammaticSizing );
}
//</snippet0>
@@ -0,0 +1,48 @@
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
ref class Form1: public Form
{
private:
DataGridView^ dataGridView1;
public:
static void Main()
{
Application::Run( gcnew Form1 );
}
Form1()
{
this->dataGridView1->Dock = DockStyle::Fill;
this->Controls->Add( this->dataGridView1 );
this->Load += gcnew EventHandler( this, &Form1::Form1_Load );
dataGridView1 = gcnew DataGridView;
}
void Form1_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
{
//<Snippet1>
DataGridViewRow^ row = this->dataGridView1->RowTemplate;
row->DefaultCellStyle->BackColor = Color::Bisque;
row->Height = 35;
row->MinimumHeight = 20;
//</Snippet1>
this->dataGridView1->ColumnCount = 5;
this->dataGridView1->RowCount = 10;
}
};
int main()
{
Form1::Main();
}
@@ -0,0 +1,355 @@
//<Snippet000>
//<Snippet001>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Windows::Forms;
//<Snippet200>
public ref class Customer
{
private:
String^ companyNameValue;
String^ contactNameValue;
public:
Customer()
{
// Leave fields empty.
}
Customer( String^ companyName, String^ contactName )
{
companyNameValue = companyName;
contactNameValue = contactName;
}
property String^ CompanyName
{
String^ get()
{
return companyNameValue;
}
void set( String^ value )
{
companyNameValue = value;
}
}
property String^ ContactName
{
String^ get()
{
return contactNameValue;
}
void set( String^ value )
{
contactNameValue = value;
}
}
};
//</Snippet200>
//<Snippet100>
public ref class Form1: public Form
{
private:
DataGridView^ dataGridView1;
// Declare an ArrayList to serve as the data store.
System::Collections::ArrayList^ customers;
// Declare a Customer object to store data for a row being edited.
Customer^ customerInEdit;
// Declare a variable to store the index of a row being edited.
// A value of -1 indicates that there is no row currently in edit.
int rowInEdit;
// Declare a variable to indicate the commit scope.
// Set this value to false to use cell-level commit scope.
bool rowScopeCommit;
public:
static void Main()
{
Application::Run( gcnew Form1 );
}
Form1()
{
dataGridView1 = gcnew DataGridView;
customers = gcnew System::Collections::ArrayList;
rowInEdit = -1;
rowScopeCommit = true;
// Initialize the form.
this->dataGridView1->Dock = DockStyle::Fill;
this->Controls->Add( this->dataGridView1 );
this->Load += gcnew EventHandler( this, &Form1::Form1_Load );
}
private:
//</Snippet001>
//<Snippet110>
void Form1_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
{
// Enable virtual mode.
this->dataGridView1->VirtualMode = true;
// Connect the virtual-mode events to event handlers.
this->dataGridView1->CellValueNeeded += gcnew
DataGridViewCellValueEventHandler( this, &Form1::dataGridView1_CellValueNeeded );
this->dataGridView1->CellValuePushed += gcnew
DataGridViewCellValueEventHandler( this, &Form1::dataGridView1_CellValuePushed );
this->dataGridView1->NewRowNeeded += gcnew
DataGridViewRowEventHandler( this, &Form1::dataGridView1_NewRowNeeded );
this->dataGridView1->RowValidated += gcnew
DataGridViewCellEventHandler( this, &Form1::dataGridView1_RowValidated );
this->dataGridView1->RowDirtyStateNeeded += gcnew
QuestionEventHandler( this, &Form1::dataGridView1_RowDirtyStateNeeded );
this->dataGridView1->CancelRowEdit += gcnew
QuestionEventHandler( this, &Form1::dataGridView1_CancelRowEdit );
this->dataGridView1->UserDeletingRow += gcnew
DataGridViewRowCancelEventHandler( this, &Form1::dataGridView1_UserDeletingRow );
// Add columns to the DataGridView.
DataGridViewTextBoxColumn^ companyNameColumn = gcnew DataGridViewTextBoxColumn;
companyNameColumn->HeaderText = L"Company Name";
companyNameColumn->Name = L"Company Name";
DataGridViewTextBoxColumn^ contactNameColumn = gcnew DataGridViewTextBoxColumn;
contactNameColumn->HeaderText = L"Contact Name";
contactNameColumn->Name = L"Contact Name";
this->dataGridView1->Columns->Add( companyNameColumn );
this->dataGridView1->Columns->Add( contactNameColumn );
this->dataGridView1->AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode::AllCells;
// Add some sample entries to the data store.
this->customers->Add( gcnew Customer( L"Bon app'",L"Laurence Lebihan" ) );
this->customers->Add( gcnew Customer( L"Bottom-Dollar Markets",L"Elizabeth Lincoln" ) );
this->customers->Add( gcnew Customer( L"B's Beverages",L"Victoria Ashworth" ) );
// Set the row count, including the row for new records.
this->dataGridView1->RowCount = 4;
}
//</Snippet110>
//<Snippet120>
void dataGridView1_CellValueNeeded( Object^ /*sender*/,
System::Windows::Forms::DataGridViewCellValueEventArgs^ e )
{
Customer^ customerTmp = nullptr;
// Store a reference to the Customer object for the row being painted.
if ( e->RowIndex == rowInEdit )
{
customerTmp = this->customerInEdit;
}
else
{
customerTmp = dynamic_cast<Customer^>(this->customers[ e->RowIndex ]);
}
// Set the cell value to paint using the Customer object retrieved.
int switchcase = 0;
if ( (this->dataGridView1->Columns[ e->ColumnIndex ]->Name)->Equals( L"Company Name" ) )
switchcase = 1;
else
if ( (this->dataGridView1->Columns[ e->ColumnIndex ]->Name)->Equals( L"Contact Name" ) )
switchcase = 2;
switch ( switchcase )
{
case 1:
e->Value = customerTmp->CompanyName;
break;
case 2:
e->Value = customerTmp->ContactName;
break;
}
}
//</Snippet120>
//<Snippet130>
void dataGridView1_CellValuePushed( Object^ /*sender*/,
System::Windows::Forms::DataGridViewCellValueEventArgs^ e )
{
Customer^ customerTmp = nullptr;
// Store a reference to the Customer object for the row being edited.
if ( e->RowIndex < this->customers->Count )
{
// If the user is editing a new row, create a new Customer object.
if ( this->customerInEdit == nullptr )
{
this->customerInEdit = gcnew Customer(
(dynamic_cast<Customer^>(this->customers[ e->RowIndex ]))->CompanyName,
(dynamic_cast<Customer^>(this->customers[ e->RowIndex ])->ContactName) );
}
customerTmp = this->customerInEdit;
this->rowInEdit = e->RowIndex;
}
else
{
customerTmp = this->customerInEdit;
}
// Set the appropriate Customer property to the cell value entered.
int switchcase = 0;
if ( (this->dataGridView1->Columns[ e->ColumnIndex ]->Name)->Equals( L"Company Name" ) )
switchcase = 1;
else
if ( (this->dataGridView1->Columns[ e->ColumnIndex ]->Name)->Equals( L"Contact Name" ) )
switchcase = 2;
switch ( switchcase )
{
case 1:
customerTmp->CompanyName = dynamic_cast<String^>(e->Value);
break;
case 2:
customerTmp->ContactName = dynamic_cast<String^>(e->Value);
break;
}
}
//</Snippet130>
//<Snippet140>
void dataGridView1_NewRowNeeded( Object^ /*sender*/,
System::Windows::Forms::DataGridViewRowEventArgs^ /*e*/ )
{
// Create a new Customer object when the user edits
// the row for new records.
this->customerInEdit = gcnew Customer;
this->rowInEdit = this->dataGridView1->Rows->Count - 1;
}
//</Snippet140>
//<Snippet150>
void dataGridView1_RowValidated( Object^ /*sender*/,
System::Windows::Forms::DataGridViewCellEventArgs^ e )
{
// Save row changes if any were made and release the edited
// Customer object if there is one.
if ( e->RowIndex >= this->customers->Count && e->RowIndex != this->dataGridView1->Rows->Count - 1 )
{
// Add the new Customer object to the data store.
this->customers->Add( this->customerInEdit );
this->customerInEdit = nullptr;
this->rowInEdit = -1;
}
else
if ( this->customerInEdit != nullptr && e->RowIndex < this->customers->Count )
{
// Save the modified Customer object in the data store.
this->customers[ e->RowIndex ] = this->customerInEdit;
this->customerInEdit = nullptr;
this->rowInEdit = -1;
}
else
if ( this->dataGridView1->ContainsFocus )
{
this->customerInEdit = nullptr;
this->rowInEdit = -1;
}
}
//</Snippet150>
//<Snippet160>
void dataGridView1_RowDirtyStateNeeded( Object^ /*sender*/,
System::Windows::Forms::QuestionEventArgs^ e )
{
if ( !rowScopeCommit )
{
// In cell-level commit scope, indicate whether the value
// of the current cell has been modified.
e->Response = this->dataGridView1->IsCurrentCellDirty;
}
}
//</Snippet160>
//<Snippet170>
void dataGridView1_CancelRowEdit( Object^ /*sender*/,
System::Windows::Forms::QuestionEventArgs^ /*e*/ )
{
if ( this->rowInEdit == this->dataGridView1->Rows->Count - 2 &&
this->rowInEdit == this->customers->Count )
{
// If the user has canceled the edit of a newly created row,
// replace the corresponding Customer object with a new, empty one.
this->customerInEdit = gcnew Customer;
}
else
{
// If the user has canceled the edit of an existing row,
// release the corresponding Customer object.
this->customerInEdit = nullptr;
this->rowInEdit = -1;
}
}
//</Snippet170>
//<Snippet180>
void dataGridView1_UserDeletingRow( Object^ /*sender*/,
System::Windows::Forms::DataGridViewRowCancelEventArgs^ e )
{
if ( e->Row->Index < this->customers->Count )
{
// If the user has deleted an existing row, remove the
// corresponding Customer object from the data store.
this->customers->RemoveAt( e->Row->Index );
}
if ( e->Row->Index == this->rowInEdit )
{
// If the user has deleted a newly created row, release
// the corresponding Customer object.
this->rowInEdit = -1;
this->customerInEdit = nullptr;
}
}
//</Snippet180>
//<Snippet002>
};
//</Snippet100>
int main()
{
Form1::Main();
}
//</Snippet002>
//</Snippet000>
@@ -0,0 +1,89 @@
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Windows::Forms;
ref class Form1 : public Form
{
private:
DataGridView^ dataGridView1;
public:
static void Main()
{
Application::Run(gcnew Form1());
}
public:
Form1()
{
dataGridView1 = gcnew DataGridView();
this->dataGridView1->Dock = DockStyle::Fill;
// Set the column header names.
this->dataGridView1->ColumnCount = 5;
this->dataGridView1->Columns[0]->Name = "Recipe";
this->dataGridView1->Columns[1]->Name = "Category";
this->dataGridView1->Columns[2]->Name = "Main Ingredients";
this->dataGridView1->Columns[3]->Name = "Last Fixed";
this->dataGridView1->Columns[4]->Name = "Rating";
// Populate the rows.
array<Object^>^ row1 = gcnew array<Object^>{"Meatloaf",
"Main Dish", "ground beef", gcnew DateTime(2000, 3, 23), "*"};
array<Object^>^ row2 = gcnew array<Object^>{"Key Lime Pie",
"Dessert", "lime juice, evaporated milk", gcnew DateTime(2002, 4, 12), "****"};
array<Object^>^ row3 = gcnew array<Object^>{"Orange-Salsa Pork Chops",
"Main Dish", "pork chops, salsa, orange juice", gcnew DateTime(2000, 8, 9), "****"};
array<Object^>^ row4 = gcnew array<Object^>{"Black Bean and Rice Salad",
"Salad", "black beans, brown rice", gcnew DateTime(1999, 5, 7), "****"};
array<Object^>^ row5 = gcnew array<Object^>{"Chocolate Cheesecake",
"Dessert", "cream cheese", gcnew DateTime(2003, 3, 12), "***"};
array<Object^>^ row6 = gcnew array<Object^>{"Black Bean Dip", "Appetizer",
"black beans, sour cream", gcnew DateTime(2003, 12, 23), "***"};
array<Object^>^ rows = gcnew array<Object^> { row1, row2, row3, row4, row5, row6 };
for each (array<Object^>^ rowArray in rows)
{
this->dataGridView1->Rows->Add(rowArray);
}
this->Controls->Add(this->dataGridView1);
this->dataGridView1->CellFormatting += gcnew DataGridViewCellFormattingEventHandler(this, &Form1::dataGridView1_CellFormatting);
}
//<Snippet1>
// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(Object^ /*sender*/,
DataGridViewCellFormattingEventArgs^ e)
{
if ( (e->ColumnIndex == this->dataGridView1->Columns["Rating"]->Index)
&& e->Value != nullptr )
{
DataGridViewCell^ cell =
this->dataGridView1->Rows[e->RowIndex]->Cells[e->ColumnIndex];
if (e->Value->Equals("*"))
{
cell->ToolTipText = "very bad";
}
else if (e->Value->Equals("**"))
{
cell->ToolTipText = "bad";
}
else if (e->Value->Equals("***"))
{
cell->ToolTipText = "good";
}
else if (e->Value->Equals("****"))
{
cell->ToolTipText = "very good";
}
}
}
//</Snippet1>
};
int main(){
Form1::Main();
}
@@ -0,0 +1,45 @@
// <Snippet0>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace DetermineModifierKey
{
public ref class Form1 : public Form
{
private:
TextBox^ textBox1;
public:
Form1()
{
textBox1 = gcnew TextBox();
textBox1->KeyPress +=
gcnew KeyPressEventHandler(this, &Form1::textBox1_KeyPress);
this->Controls->Add(textBox1);
}
// <Snippet5>
private:
void textBox1_KeyPress(Object^ sender, KeyPressEventArgs^ e)
{
if ((Control::ModifierKeys & Keys::Shift) == Keys::Shift)
{
MessageBox::Show("Pressed " + Keys::Shift.ToString());
}
}
// </Snippet5>
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew DetermineModifierKey::Form1());
}
// </Snippet0>
@@ -0,0 +1,2 @@
System.Windows.Forms.DetermineModifierKey.exe : form1.cpp
cl /clr:pure /FeSystem.Windows.Forms.DetermineModifierKey.exe form1.cpp
@@ -0,0 +1,139 @@
// This sample compiles a set of miscellaneous code snippets that demonstrate
// different levels of user input control.
// <Snippet0>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Security::Permissions;
namespace KeyboardInputForm
{
public ref class Form1 sealed: public Form, public IMessageFilter
{
// The following Windows message value is defined in Winuser.h.
private:
static const int WM_KEYDOWN = 0x100;
private:
TextBox^ inputTextBox;
public:
Form1()
{
inputTextBox = gcnew TextBox();
this->AutoSize = true;
Application::AddMessageFilter(this);
FlowLayoutPanel^ panel = gcnew FlowLayoutPanel();
panel->AutoSize = true;
panel->FlowDirection = FlowDirection::TopDown;
panel->Controls->Add(gcnew Button());
panel->Controls->Add(gcnew RadioButton());
panel->Controls->Add(inputTextBox);
this->Controls->Add(panel);
this->KeyPreview = true;
this->KeyPress +=
gcnew KeyPressEventHandler(this, &Form1::Form1_KeyPress);
inputTextBox->KeyPress +=
gcnew KeyPressEventHandler(this,
&Form1::inputTextBox_KeyPress);
}
// <Snippet5>
// Detect all numeric characters at the
// application level and consume 0.
[SecurityPermission(SecurityAction::LinkDemand,
Flags=SecurityPermissionFlag::UnmanagedCode)]
virtual bool PreFilterMessage(Message% m)
{
// Detect key down messages.
if (m.Msg == WM_KEYDOWN)
{
Keys keyCode = (Keys)((int)m.WParam) & Keys::KeyCode;
// Determine whether the keystroke is a number from the top of
// the keyboard, or a number from the keypad.
if (((keyCode >= Keys::D0) && (keyCode <= Keys::D9))
||((keyCode >= Keys::NumPad0)
&& (keyCode <= Keys::NumPad9)))
{
MessageBox::Show(
"IMessageFilter.PreFilterMessage: '" +
keyCode.ToString() + "' pressed.");
if ((keyCode == Keys::D0) || (keyCode == Keys::NumPad0))
{
MessageBox::Show(
"IMessageFilter.PreFilterMessage: '" +
keyCode.ToString() + "' consumed.");
return true;
}
}
}
// Forward all other messages.
return false;
}
// </Snippet5>
// <Snippet10>
// Detect all numeric characters at the form level and consume 1,
// 4, and 7. Note that Form.KeyPreview must be set to true for this
// event handler to be called.
private:
void Form1_KeyPress(Object^ sender, KeyPressEventArgs^ e)
{
if ((e->KeyChar >= '0') && (e->KeyChar <= '9'))
{
MessageBox::Show("Form.KeyPress: '" +
e->KeyChar.ToString() + "' pressed.");
switch (e->KeyChar)
{
case '1':
case '4':
case '7':
MessageBox::Show("Form.KeyPress: '" +
e->KeyChar.ToString() + "' consumed.");
e->Handled = true;
break;
}
}
}
// </Snippet10>
// <Snippet15>
// Detect all numeric characters at the TextBox level and consume
// 2, 5, and 8.
private:
void inputTextBox_KeyPress(Object^ sender, KeyPressEventArgs^ e)
{
if ((e->KeyChar >= '0') && (e->KeyChar <= '9'))
{
MessageBox::Show("Control.KeyPress: '" +
e->KeyChar.ToString() + "' pressed.");
switch (e->KeyChar)
{
case '2':
case '5':
case '8':
MessageBox::Show("Control.KeyPress: '" +
e->KeyChar.ToString() + "' consumed.");
e->Handled = true;
break;
}
}
}
// </Snippet15>
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew KeyboardInputForm::Form1());
}
// </Snippet0>
@@ -0,0 +1,2 @@
System.Windows.Forms.KeyboardInputForm.exe: form1.cpp
cl /FeSystem.Windows.Forms.KeyboardInputForm.exe /clr:pure form1.cpp
@@ -0,0 +1,134 @@
// <snippet1>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Layout;
// <snippet3>
// This class demonstrates a simple custom layout engine.
public ref class DemoFlowLayout : public LayoutEngine
{
// <snippet4>
public:
virtual bool Layout(Object^ container,
LayoutEventArgs^ layoutEventArgs) override
{
Control^ parent = nullptr;
try
{
parent = (Control ^) container;
}
catch (InvalidCastException^ ex)
{
throw gcnew ArgumentException(
"The parameter 'container' must be a control", "container", ex);
}
// Use DisplayRectangle so that parent.Padding is honored.
Rectangle parentDisplayRectangle = parent->DisplayRectangle;
Point nextControlLocation = parentDisplayRectangle.Location;
for each (Control^ currentControl in parent->Controls)
{
// Only apply layout to visible controls.
if (!currentControl->Visible)
{
continue;
}
// Respect the margin of the control:
// shift over the left and the top.
nextControlLocation.Offset(currentControl->Margin.Left,
currentControl->Margin.Top);
// Set the location of the control.
currentControl->Location = nextControlLocation;
// Set the autosized controls to their
// autosized heights.
if (currentControl->AutoSize)
{
currentControl->Size = currentControl->GetPreferredSize(
parentDisplayRectangle.Size);
}
// Move X back to the display rectangle origin.
nextControlLocation.X = parentDisplayRectangle.X;
// Increment Y by the height of the control
// and the bottom margin.
nextControlLocation.Y += currentControl->Height +
currentControl->Margin.Bottom;
}
// Optional: Return whether or not the container's
// parent should perform layout as a result of this
// layout. Some layout engines return the value of
// the container's AutoSize property.
return false;
}
// </snippet4>
};
// </snippet3>
// <snippet2>
// This class demonstrates a simple custom layout panel.
// It overrides the LayoutEngine property of the Panel
// control to provide a custom layout engine.
public ref class DemoFlowPanel : public Panel
{
private:
DemoFlowLayout^ layoutEngine;
public:
DemoFlowPanel()
{
layoutEngine = gcnew DemoFlowLayout();
}
public:
virtual property System::Windows::Forms::Layout::LayoutEngine^ LayoutEngine
{
System::Windows::Forms::Layout::LayoutEngine^ get() override
{
if (layoutEngine == nullptr)
{
layoutEngine = gcnew DemoFlowLayout();
}
return layoutEngine;
}
}
};
// </snippet2>
// </snippet1>
public ref class TestForm : public Form
{
public:
TestForm()
{
Panel^ testPanel = gcnew DemoFlowPanel();
for (int i = 0; i < 10; i ++)
{
Button^ b = gcnew Button();
testPanel->Controls->Add(b);
b->Text = i.ToString(
System::Globalization::CultureInfo::CurrentCulture);
}
this->Controls->Add(testPanel);
}
};
[STAThread]
int main()
{
Application::Run(gcnew TestForm());
}
@@ -0,0 +1,2 @@
System.Windows.Forms.Layout.LayoutEngine.dll: DemoFlowLayout.cpp
cl /FeSystem.Windows.Forms.Layout.LayoutEngine.exe /clr:pure DemoFlowLayout.cpp
@@ -0,0 +1,160 @@
//<Snippet1>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class ListViewInsertionMarkExample: public Form
{
private:
ListView^ myListView;
public:
//<Snippet2>
ListViewInsertionMarkExample()
{
// Initialize myListView.
myListView = gcnew ListView;
myListView->Dock = DockStyle::Fill;
myListView->View = View::LargeIcon;
myListView->MultiSelect = false;
myListView->ListViewItemSorter = gcnew ListViewIndexComparer;
// Initialize the insertion mark.
myListView->InsertionMark->Color = Color::Green;
// Add items to myListView.
myListView->Items->Add( "zero" );
myListView->Items->Add( "one" );
myListView->Items->Add( "two" );
myListView->Items->Add( "three" );
myListView->Items->Add( "four" );
myListView->Items->Add( "five" );
// Initialize the drag-and-drop operation when running
// under Windows XP or a later operating system.
if ( System::Environment::OSVersion->Version->Major > 5 || (System::Environment::OSVersion->Version->Major == 5 && System::Environment::OSVersion->Version->Minor >= 1) )
{
myListView->AllowDrop = true;
myListView->ItemDrag += gcnew ItemDragEventHandler( this, &ListViewInsertionMarkExample::myListView_ItemDrag );
myListView->DragEnter += gcnew DragEventHandler( this, &ListViewInsertionMarkExample::myListView_DragEnter );
myListView->DragOver += gcnew DragEventHandler( this, &ListViewInsertionMarkExample::myListView_DragOver );
myListView->DragLeave += gcnew EventHandler( this, &ListViewInsertionMarkExample::myListView_DragLeave );
myListView->DragDrop += gcnew DragEventHandler( this, &ListViewInsertionMarkExample::myListView_DragDrop );
}
// Initialize the form.
this->Text = "ListView Insertion Mark Example";
this->Controls->Add( myListView );
}
private:
//</Snippet2>
// Starts the drag-and-drop operation when an item is dragged.
void myListView_ItemDrag( Object^ /*sender*/, ItemDragEventArgs^ e )
{
myListView->DoDragDrop( e->Item, DragDropEffects::Move );
}
// Sets the target drop effect.
void myListView_DragEnter( Object^ /*sender*/, DragEventArgs^ e )
{
e->Effect = e->AllowedEffect;
}
//<Snippet3>
// Moves the insertion mark as the item is dragged.
void myListView_DragOver( Object^ /*sender*/, DragEventArgs^ e )
{
// Retrieve the client coordinates of the mouse pointer.
Point targetPoint = myListView->PointToClient( Point(e->X,e->Y) );
// Retrieve the index of the item closest to the mouse pointer.
int targetIndex = myListView->InsertionMark->NearestIndex( targetPoint );
// Confirm that the mouse pointer is not over the dragged item.
if ( targetIndex > -1 )
{
// Determine whether the mouse pointer is to the left or
// the right of the midpoint of the closest item and set
// the InsertionMark.AppearsAfterItem property accordingly.
Rectangle itemBounds = myListView->GetItemRect( targetIndex );
if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) )
{
myListView->InsertionMark->AppearsAfterItem = true;
}
else
{
myListView->InsertionMark->AppearsAfterItem = false;
}
}
// Set the location of the insertion mark. If the mouse is
// over the dragged item, the targetIndex value is -1 and
// the insertion mark disappears.
myListView->InsertionMark->Index = targetIndex;
}
//</Snippet3>
// Removes the insertion mark when the mouse leaves the control.
void myListView_DragLeave( Object^ /*sender*/, EventArgs^ /*e*/ )
{
myListView->InsertionMark->Index = -1;
}
// Moves the item to the location of the insertion mark.
void myListView_DragDrop( Object^ /*sender*/, DragEventArgs^ e )
{
// Retrieve the index of the insertion mark;
int targetIndex = myListView->InsertionMark->Index;
// If the insertion mark is not visible, exit the method.
if ( targetIndex == -1 )
{
return;
}
// If the insertion mark is to the right of the item with
// the corresponding index, increment the target index.
if ( myListView->InsertionMark->AppearsAfterItem )
{
targetIndex++;
}
// Retrieve the dragged item.
ListViewItem^ draggedItem = dynamic_cast<ListViewItem^>(e->Data->GetData( ListViewItem::typeid ));
// Insert a copy of the dragged item at the target index.
// A copy must be inserted before the original item is removed
// to preserve item index values.
myListView->Items->Insert( targetIndex, dynamic_cast<ListViewItem^>(draggedItem->Clone()) );
// Remove the original copy of the dragged item.
myListView->Items->Remove( draggedItem );
}
// Sorts ListViewItem objects by index.
ref class ListViewIndexComparer: public System::Collections::IComparer
{
public:
virtual int Compare( Object^ x, Object^ y )
{
return (dynamic_cast<ListViewItem^>(x))->Index - (dynamic_cast<ListViewItem^>(y))->Index;
}
};
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run( gcnew ListViewInsertionMarkExample );
}
//</Snippet1>
@@ -0,0 +1,88 @@
//<Snippet1>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class ListViewTilingExample: public Form
{
private:
ImageList^ myImageList;
public:
ListViewTilingExample()
{
// Initialize myListView.
ListView^ myListView = gcnew ListView;
myListView->Dock = DockStyle::Fill;
myListView->View = View::Tile;
// Initialize the tile size.
myListView->TileSize = System::Drawing::Size( 400, 45 );
// Initialize the item icons.
myImageList = gcnew ImageList;
System::Drawing::Icon^ myIcon = gcnew System::Drawing::Icon( "book.ico" );
try
{
myImageList->Images->Add( myIcon );
}
finally
{
if ( myIcon )
delete safe_cast<IDisposable^>(myIcon);
}
myImageList->ImageSize = System::Drawing::Size( 32, 32 );
myListView->LargeImageList = myImageList;
// Add column headers so the subitems will appear.
array<ColumnHeader^>^temp0 = {gcnew ColumnHeader,gcnew ColumnHeader,gcnew ColumnHeader};
myListView->Columns->AddRange( temp0 );
// Create items and add them to myListView.
array<String^>^temp1 = {"Programming Windows","Petzold, Charles","1998"};
ListViewItem^ item0 = gcnew ListViewItem( temp1,0 );
array<String^>^temp2 = {"Code: The Hidden Language of Computer Hardware and Software","Petzold, Charles","2000"};
ListViewItem^ item1 = gcnew ListViewItem( temp2,0 );
array<String^>^temp3 = {"Programming Windows with C#","Petzold, Charles","2001"};
ListViewItem^ item2 = gcnew ListViewItem( temp3,0 );
array<String^>^temp4 = {"Coding Techniques for Microsoft Visual Basic .NET","Connell, John","2001"};
ListViewItem^ item3 = gcnew ListViewItem( temp4,0 );
array<String^>^temp5 = {"C# for Java Developers","Jones, Allen & Freeman, Adam","2002"};
ListViewItem^ item4 = gcnew ListViewItem( temp5,0 );
array<String^>^temp6 = {"Microsoft .NET XML Web Services Step by Step","Jones, Allen & Freeman, Adam","2002"};
ListViewItem^ item5 = gcnew ListViewItem( temp6,0 );
array<ListViewItem^>^temp7 = {item0,item1,item2,item3,item4,item5};
myListView->Items->AddRange( temp7 );
// Initialize the form.
this->Controls->Add( myListView );
this->Size = System::Drawing::Size( 430, 330 );
this->Text = "ListView Tiling Example";
}
protected:
// Clean up any resources being used.
~ListViewTilingExample()
{
if ( myImageList != nullptr )
{
delete myImageList;
}
}
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run( gcnew ListViewTilingExample );
}
//</Snippet1>
@@ -0,0 +1,188 @@
#pragma region Using directives
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Windows::Forms;
#pragma endregion
namespace ListViewFindItemWithTextHowTo
{
public ref class Form1 : public Form
{
public:
Form1()
{
InitializeComponent();
//InitializeTextSearchListView();
InitializeLocationSearchListView();
}
/// <summary>
/// Required designer variable.
/// </summary>
private:
System::ComponentModel::IContainer^ components;
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected:
~Form1()
{
if (components != nullptr)
{
delete components;
}
}
#pragma region^ Windows Form^ Designer generated^ code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private:
void InitializeComponent()
{
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = "Form1";
this->Text = "Form1";
}
#pragma endregion
//<snippet1>
private:
ListView^ textListView;
TextBox^ searchBox;
private:
void InitializeTextSearchListView()
{
textListView = gcnew ListView();
searchBox = gcnew TextBox();
searchBox->Location = Point(150, 20);
textListView->Scrollable = true;
textListView->Width = 100;
// Set the View to list to use the FindItemWithText method.
textListView->View = View::List;
// Populate the ListViewWithItems
textListView->Items->AddRange(gcnew array<ListViewItem^>{
gcnew ListViewItem("Amy Alberts"),
gcnew ListViewItem("Amy Recker"),
gcnew ListViewItem("Erin Hagens"),
gcnew ListViewItem("Barry Johnson"),
gcnew ListViewItem("Jay Hamlin"),
gcnew ListViewItem("Brian Valentine"),
gcnew ListViewItem("Brian Welker"),
gcnew ListViewItem("Daniel Weisman") });
// Handle the TextChanged to get the text for our search.
searchBox->TextChanged += gcnew EventHandler(this,
&Form1::searchBox_TextChanged);
// Add the controls to the form.
this->Controls->Add(textListView);
this->Controls->Add(searchBox);
}
//<snippet11>
private:
void searchBox_TextChanged(Object^ sender, EventArgs^ e)
{
// Call FindItemWithText with the contents of the textbox.
ListViewItem^ foundItem =
textListView->FindItemWithText(searchBox->Text, false, 0, true);
if (foundItem != nullptr)
{
textListView->TopItem = foundItem;
}
}
//</snippet11>
//</snippet1>
//<snippet2>
ListView^ iconListView;
TextBox^ previousItemBox;
private:
void InitializeLocationSearchListView()
{
previousItemBox = gcnew TextBox();
iconListView = gcnew ListView();
previousItemBox->Location = Point(150, 20);
// Create an image list for the icon ListView.
iconListView->SmallImageList = gcnew ImageList();
// Add an image to the ListView small icon list.
iconListView->SmallImageList->Images->Add(
gcnew Bitmap(Control::typeid, "Edit.bmp"));
// Set the view to small icon and add some items with the image
// in the image list.
iconListView->View = View::SmallIcon;
iconListView->Items->AddRange(gcnew array<ListViewItem^>{
gcnew ListViewItem("Amy Alberts", 0),
gcnew ListViewItem("Amy Recker", 0),
gcnew ListViewItem("Erin Hagens", 0),
gcnew ListViewItem("Barry Johnson", 0),
gcnew ListViewItem("Jay Hamlin", 0),
gcnew ListViewItem("Brian Valentine", 0),
gcnew ListViewItem("Brian Welker", 0),
gcnew ListViewItem("Daniel Weisman", 0) });
this->Controls->Add(iconListView);
this->Controls->Add(previousItemBox);
// Handle the MouseDown event to capture user input.
iconListView->MouseDown += gcnew MouseEventHandler(
this, &Form1::iconListView_MouseDown);
}
//<snippet21>
void iconListView_MouseDown(Object^ sender, MouseEventArgs^ e)
{
// Find the next item up from where the user clicked.
ListViewItem^ foundItem = iconListView->FindNearestItem(
SearchDirectionHint::Up, e->X, e->Y);
// Display the results in a textbox..
if (foundItem != nullptr)
{
previousItemBox->Text = foundItem->Text;
}
else
{
previousItemBox->Text = "No item found";
}
}
//</snippet21>
//</snippet2>
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew ListViewFindItemWithTextHowTo::Form1());
}
@@ -0,0 +1,2 @@
System.Windows.Forms.ListViewFindItems.exe: form1.cpp
cl /FeSystem.Windows.Forms.ListViewFindItems.exe /clr:pure form1.cpp
@@ -0,0 +1,88 @@
// <Snippet0>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace SimulateKeyPress
{
public ref class Form1 : public Form
{
public:
Form1()
{
Button^ button1 = gcnew Button();
button1->Location = Point(10, 10);
button1->TabIndex = 0;
button1->Text = "Click to automate Calculator";
button1->AutoSize = true;
button1->Click += gcnew EventHandler(this, &Form1::button1_Click);
this->DoubleClick += gcnew EventHandler(this,
&Form1::Form1_DoubleClick);
this->Controls->Add(button1);
}
// <Snippet5>
// Get a handle to an application window.
public:
[DllImport("USER32.DLL", CharSet = CharSet::Unicode)]
static IntPtr FindWindow(String^ lpClassName, String^ lpWindowName);
public:
// Activate an application window.
[DllImport("USER32.DLL")]
static bool SetForegroundWindow(IntPtr hWnd);
// Send a series of key presses to the Calculator application.
private:
void button1_Click(Object^ sender, EventArgs^ e)
{
// Get a handle to the Calculator application. The window class
// and window name were obtained using the Spy++ tool.
IntPtr calculatorHandle = FindWindow("CalcFrame", "Calculator");
// Verify that Calculator is a running process.
if (calculatorHandle == IntPtr::Zero)
{
MessageBox::Show("Calculator is not running.");
return;
}
// Make Calculator the foreground application and send it
// a set of calculations.
SetForegroundWindow(calculatorHandle);
SendKeys::SendWait("111");
SendKeys::SendWait("*");
SendKeys::SendWait("11");
SendKeys::SendWait("=");
}
// </Snippet5>
// <Snippet10>
// Send a key to the button when the user double-clicks anywhere
// on the form.
private:
void Form1_DoubleClick(Object^ sender, EventArgs^ e)
{
// Send the enter key to the button, which triggers the click
// event for the button. This works because the tab stop of
// the button is 0.
SendKeys::Send("{ENTER}");
}
// </Snippet10>
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew SimulateKeyPress::Form1());
}
// </Snippet0>
@@ -0,0 +1,2 @@
System.Windows.Forms.SimulateKeyPress.exe: form1.cpp
cl /clr:pure /FeSystem.Windows.Forms.SimulateKeyPress.exe form1.cpp
@@ -0,0 +1,175 @@
// <Snippet0>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace SingleVersusDoubleClick
{
public ref class Form1 : public Form
{
private:
Rectangle hitTestRectangle;
private:
Rectangle doubleClickRectangle;
private:
TextBox^ outputBox;
private:
Timer^ doubleClickTimer;
private:
ProgressBar^ doubleClickBar;
private:
Label^ hitTestLabel;
private:
Label^ timerLabel;
private:
bool isFirstClick;
private:
bool isDoubleClick;
private:
int milliseconds;
public:
Form1()
{
hitTestRectangle = Rectangle();
hitTestRectangle.Location = Point(30, 20);
hitTestRectangle.Size = System::Drawing::Size(100, 40);
doubleClickRectangle = Rectangle();
outputBox = gcnew TextBox();
outputBox->Location = Point(30, 120);
outputBox->Size = System::Drawing::Size(200, 100);
outputBox->AutoSize = false;
outputBox->Multiline = true;
doubleClickTimer = gcnew Timer();
doubleClickTimer->Interval = 100;
doubleClickTimer->Tick +=
gcnew EventHandler(this, &Form1::doubleClickTimer_Tick);
doubleClickBar = gcnew ProgressBar();
doubleClickBar->Location = Point(30, 85);
doubleClickBar->Minimum = 0;
doubleClickBar->Maximum = SystemInformation::DoubleClickTime;
hitTestLabel = gcnew Label();
hitTestLabel->Location = Point(30, 5);
hitTestLabel->Size = System::Drawing::Size(100, 15);
hitTestLabel->Text = "Hit test rectangle:";
timerLabel = gcnew Label();
timerLabel->Location = Point(30, 70);
timerLabel->Size = System::Drawing::Size(100, 15);
timerLabel->Text = "Double click timer:";
isFirstClick = true;
this->Paint += gcnew PaintEventHandler(this, &Form1::Form1_Paint);
this->MouseDown +=
gcnew MouseEventHandler(this, &Form1::Form1_MouseDown);
this->Controls->
AddRange(gcnew array<Control^> { doubleClickBar, outputBox,
hitTestLabel, timerLabel });
}
// <Snippet10>
// Detect a valid single click or double click.
private:
void Form1_MouseDown(Object^ sender, MouseEventArgs^ e)
{
// Verify that the mouse click is in the main hit
// test rectangle.
if (!hitTestRectangle.Contains(e->Location))
{
return;
}
// This is the first mouse click.
if (isFirstClick)
{
isFirstClick = false;
// Determine the location and size of the double click
// rectangle area to draw around the cursor point.
doubleClickRectangle = Rectangle(
e->X - (SystemInformation::DoubleClickSize.Width / 2),
e->Y - (SystemInformation::DoubleClickSize.Height / 2),
SystemInformation::DoubleClickSize.Width,
SystemInformation::DoubleClickSize.Height);
Invalidate();
// Start the double click timer.
doubleClickTimer->Start();
}
// This is the second mouse click.
else
{
// Verify that the mouse click is within the double click
// rectangle and is within the system-defined double
// click period.
if (doubleClickRectangle.Contains(e->Location) &&
milliseconds < SystemInformation::DoubleClickTime)
{
isDoubleClick = true;
}
}
}
// </Snippet10>
private:
void doubleClickTimer_Tick(Object^ sender, EventArgs^ e)
{
milliseconds += 100;
doubleClickBar->Increment(100);
// The timer has reached the double click time limit.
if (milliseconds >= SystemInformation::DoubleClickTime)
{
doubleClickTimer->Stop();
if (isDoubleClick)
{
outputBox->AppendText("Perform double click action");
outputBox->AppendText(Environment::NewLine);
}
else
{
outputBox->AppendText("Perform single click action");
outputBox->AppendText(Environment::NewLine);
}
// Allow the MouseDown event handler to process clicks again.
isFirstClick = true;
isDoubleClick = false;
milliseconds = 0;
doubleClickBar->Value = 0;
}
}
// Paint the hit test and double click rectangles.
private:
void Form1_Paint(Object^ sender, PaintEventArgs^ e)
{
// Draw the border of the main hit test rectangle.
e->Graphics->DrawRectangle(Pens::Black, hitTestRectangle);
// Fill in the double click rectangle.
e->Graphics->FillRectangle(Brushes::Blue, doubleClickRectangle);
}
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew SingleVersusDoubleClick::Form1);
}
// </Snippet0>
@@ -0,0 +1,2 @@
System.Windows.Forms.ScrollBarRenderer.exe : form1.cpp
cl /clr:pure /FeSystem.Windows.Forms.ScrollBarRenderer.exe form1.cpp
@@ -0,0 +1,416 @@
// <snippet1>
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Text;
using namespace System::Windows::Forms;
// This form demonstrates how to build a form layout that adjusts well
// when the user resizes the form. It also demonstrates a layout that
// responds well to localization.
ref class BasicDataEntryForm : public System::Windows::Forms::Form
{
public:
BasicDataEntryForm()
{
InitializeComponent();
components = nullptr;
}
private:
System::ComponentModel::IContainer^ components;
protected:
~BasicDataEntryForm()
{
if (components != nullptr)
{
delete components;
}
}
public:
virtual String^ ToString() override
{
return "Basic Data Entry Form";
}
private:
void okBtn_Click(Object^ sender, EventArgs^ e)
{
this->Close();
}
private:
void cancelBtn_Click(Object^ sender, EventArgs^ e)
{
this->Close();
}
private:
void InitializeComponent()
{
this->tableLayoutPanel1 = gcnew
System::Windows::Forms::TableLayoutPanel();
this->lblFirstName = gcnew System::Windows::Forms::Label();
this->lblLastName = gcnew System::Windows::Forms::Label();
this->lblAddress1 = gcnew System::Windows::Forms::Label();
this->lblAddress2 = gcnew System::Windows::Forms::Label();
this->lblCity = gcnew System::Windows::Forms::Label();
this->lblState = gcnew System::Windows::Forms::Label();
this->lblPhoneH = gcnew System::Windows::Forms::Label();
this->txtAddress1 = gcnew System::Windows::Forms::TextBox();
this->txtAddress2 = gcnew System::Windows::Forms::TextBox();
this->txtCity = gcnew System::Windows::Forms::TextBox();
this->txtLastName = gcnew System::Windows::Forms::TextBox();
this->maskedTxtPhoneW = gcnew System::Windows::Forms::MaskedTextBox();
this->maskedTxtPhoneH = gcnew System::Windows::Forms::MaskedTextBox();
this->cboState = gcnew System::Windows::Forms::ComboBox();
this->txtFirstName = gcnew System::Windows::Forms::TextBox();
this->lblNotes = gcnew System::Windows::Forms::Label();
this->lblPhoneW = gcnew System::Windows::Forms::Label();
this->richTxtNotes = gcnew System::Windows::Forms::RichTextBox();
this->cancelBtn = gcnew System::Windows::Forms::Button();
this->okBtn = gcnew System::Windows::Forms::Button();
this->tableLayoutPanel1->SuspendLayout();
this->SuspendLayout();
//
// tableLayoutPanel1
//
this->tableLayoutPanel1->Anchor =
System::Windows::Forms::AnchorStyles::Top |
System::Windows::Forms::AnchorStyles::Bottom|
System::Windows::Forms::AnchorStyles::Left |
System::Windows::Forms::AnchorStyles::Right;
this->tableLayoutPanel1->ColumnCount = 4;
this->tableLayoutPanel1->ColumnStyles->Add(gcnew
System::Windows::Forms::ColumnStyle());
this->tableLayoutPanel1->ColumnStyles->Add(gcnew
System::Windows::Forms::ColumnStyle(
System::Windows::Forms::SizeType::Percent, 50.0));
this->tableLayoutPanel1->ColumnStyles->Add(gcnew
System::Windows::Forms::ColumnStyle());
this->tableLayoutPanel1->ColumnStyles->Add(gcnew
System::Windows::Forms::ColumnStyle(
System::Windows::Forms::SizeType::Percent, 50.0));
this->tableLayoutPanel1->Controls->Add(this->lblFirstName, 0, 0);
this->tableLayoutPanel1->Controls->Add(this->lblLastName, 2, 0);
this->tableLayoutPanel1->Controls->Add(this->lblAddress1, 0, 1);
this->tableLayoutPanel1->Controls->Add(this->lblAddress2, 0, 2);
this->tableLayoutPanel1->Controls->Add(this->lblCity, 0, 3);
this->tableLayoutPanel1->Controls->Add(this->lblState, 2, 3);
this->tableLayoutPanel1->Controls->Add(this->lblPhoneH, 2, 4);
this->tableLayoutPanel1->Controls->Add(this->txtAddress1, 1, 1);
this->tableLayoutPanel1->Controls->Add(this->txtAddress2, 1, 2);
this->tableLayoutPanel1->Controls->Add(this->txtCity, 1, 3);
this->tableLayoutPanel1->Controls->Add(this->txtLastName, 3, 0);
this->tableLayoutPanel1->Controls->Add(this->maskedTxtPhoneW, 1, 4);
this->tableLayoutPanel1->Controls->Add(this->maskedTxtPhoneH, 3, 4);
this->tableLayoutPanel1->Controls->Add(this->cboState, 3, 3);
this->tableLayoutPanel1->Controls->Add(this->txtFirstName, 1, 0);
this->tableLayoutPanel1->Controls->Add(this->lblNotes, 0, 5);
this->tableLayoutPanel1->Controls->Add(this->lblPhoneW, 0, 4);
this->tableLayoutPanel1->Controls->Add(this->richTxtNotes, 1, 5);
this->tableLayoutPanel1->Location = System::Drawing::Point(13, 13);
this->tableLayoutPanel1->Name = "tableLayoutPanel1";
this->tableLayoutPanel1->RowCount = 6;
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Absolute, 28.0));
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Absolute, 28.0));
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Absolute, 28.0));
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Absolute, 28.0));
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Absolute, 28.0));
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Percent, 80.0));
this->tableLayoutPanel1->RowStyles->Add(gcnew
System::Windows::Forms::RowStyle(
System::Windows::Forms::SizeType::Absolute, 20.0));
this->tableLayoutPanel1->Size = System::Drawing::Size(623, 286);
this->tableLayoutPanel1->TabIndex = 0;
//
// lblFirstName
//
this->lblFirstName->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblFirstName->AutoSize = true;
this->lblFirstName->Location = System::Drawing::Point(3, 7);
this->lblFirstName->Name = "lblFirstName";
this->lblFirstName->Size = System::Drawing::Size(59, 14);
this->lblFirstName->TabIndex = 20;
this->lblFirstName->Text = "First Name";
//
// lblLastName
//
this->lblLastName->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblLastName->AutoSize = true;
this->lblLastName->Location = System::Drawing::Point(323, 7);
this->lblLastName->Name = "lblLastName";
this->lblLastName->Size = System::Drawing::Size(59, 14);
this->lblLastName->TabIndex = 21;
this->lblLastName->Text = "Last Name";
//
// lblAddress1
//
this->lblAddress1->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblAddress1->AutoSize = true;
this->lblAddress1->Location = System::Drawing::Point(10, 35);
this->lblAddress1->Name = "lblAddress1";
this->lblAddress1->Size = System::Drawing::Size(52, 14);
this->lblAddress1->TabIndex = 22;
this->lblAddress1->Text = "Address1";
//
// lblAddress2
//
this->lblAddress2->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblAddress2->AutoSize = true;
this->lblAddress2->Location = System::Drawing::Point(7, 63);
this->lblAddress2->Name = "lblAddress2";
this->lblAddress2->Size = System::Drawing::Size(55, 14);
this->lblAddress2->TabIndex = 23;
this->lblAddress2->Text = "Address 2";
//
// lblCity
//
this->lblCity->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblCity->AutoSize = true;
this->lblCity->Location = System::Drawing::Point(38, 91);
this->lblCity->Name = "lblCity";
this->lblCity->Size = System::Drawing::Size(24, 14);
this->lblCity->TabIndex = 24;
this->lblCity->Text = "City";
//
// lblState
//
this->lblState->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblState->AutoSize = true;
this->lblState->Location = System::Drawing::Point(351, 91);
this->lblState->Name = "lblState";
this->lblState->Size = System::Drawing::Size(31, 14);
this->lblState->TabIndex = 25;
this->lblState->Text = "State";
//
// lblPhoneH
//
this->lblPhoneH->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblPhoneH->AutoSize = true;
this->lblPhoneH->Location = System::Drawing::Point(326, 119);
this->lblPhoneH->Name = "lblPhoneH";
this->lblPhoneH->Size = System::Drawing::Size(56, 14);
this->lblPhoneH->TabIndex = 33;
this->lblPhoneH->Text = "Phone (H)";
//
// txtAddress1
//
this->txtAddress1->Anchor =
System::Windows::Forms::AnchorStyles::Left |
System::Windows::Forms::AnchorStyles::Right;
this->tableLayoutPanel1->SetColumnSpan(this->txtAddress1, 3);
this->txtAddress1->Location = System::Drawing::Point(68, 32);
this->txtAddress1->Name = "txtAddress1";
this->txtAddress1->Size = System::Drawing::Size(552, 20);
this->txtAddress1->TabIndex = 2;
//
// txtAddress2
//
this->txtAddress2->Anchor =
System::Windows::Forms::AnchorStyles::Left |
System::Windows::Forms::AnchorStyles::Right;
this->tableLayoutPanel1->SetColumnSpan(this->txtAddress2, 3);
this->txtAddress2->Location = System::Drawing::Point(68, 60);
this->txtAddress2->Name = "txtAddress2";
this->txtAddress2->Size = System::Drawing::Size(552, 20);
this->txtAddress2->TabIndex = 3;
//
// txtCity
//
this->txtCity->Anchor =
System::Windows::Forms::AnchorStyles::Left |
System::Windows::Forms::AnchorStyles::Right;
this->txtCity->Location = System::Drawing::Point(68, 88);
this->txtCity->Name = "txtCity";
this->txtCity->Size = System::Drawing::Size(249, 20);
this->txtCity->TabIndex = 4;
//
// txtLastName
//
this->txtLastName->Anchor =
System::Windows::Forms::AnchorStyles::Left |
System::Windows::Forms::AnchorStyles::Right;
this->txtLastName->Location = System::Drawing::Point(388, 4);
this->txtLastName->Name = "txtLastName";
this->txtLastName->Size = System::Drawing::Size(232, 20);
this->txtLastName->TabIndex = 1;
//
// maskedTxtPhoneW
//
this->maskedTxtPhoneW->Anchor =
System::Windows::Forms::AnchorStyles::Left;
this->maskedTxtPhoneW->Location = System::Drawing::Point(68, 116);
this->maskedTxtPhoneW->Mask = "(999)000-0000";
this->maskedTxtPhoneW->Name = "maskedTxtPhoneW";
this->maskedTxtPhoneW->TabIndex = 6;
//
// maskedTxtPhoneH
//
this->maskedTxtPhoneH->Anchor =
System::Windows::Forms::AnchorStyles::Left;
this->maskedTxtPhoneH->Location = System::Drawing::Point(388, 116);
this->maskedTxtPhoneH->Mask = "(999)000-0000";
this->maskedTxtPhoneH->Name = "maskedTxtPhoneH";
this->maskedTxtPhoneH->TabIndex = 7;
//
// cboState
//
this->cboState->Anchor = System::Windows::Forms::AnchorStyles::Left;
this->cboState->FormattingEnabled = true;
this->cboState->Items->AddRange(gcnew array<Object^> {
"AK - Alaska",
"WA - Washington"});
this->cboState->Location = System::Drawing::Point(388, 87);
this->cboState->Name = "cboState";
this->cboState->Size = System::Drawing::Size(100, 21);
this->cboState->TabIndex = 5;
//
// txtFirstName
//
this->txtFirstName->Anchor =
System::Windows::Forms::AnchorStyles::Left |
System::Windows::Forms::AnchorStyles::Right;
this->txtFirstName->Location = System::Drawing::Point(68, 4);
this->txtFirstName->Name = "txtFirstName";
this->txtFirstName->Size = System::Drawing::Size(249, 20);
this->txtFirstName->TabIndex = 0;
//
// lblNotes
//
this->lblNotes->Anchor =
System::Windows::Forms::AnchorStyles::Top |
System::Windows::Forms::AnchorStyles::Right;
this->lblNotes->AutoSize = true;
this->lblNotes->Location = System::Drawing::Point(28, 143);
this->lblNotes->Name = "lblNotes";
this->lblNotes->Size = System::Drawing::Size(34, 14);
this->lblNotes->TabIndex = 26;
this->lblNotes->Text = "Notes";
//
// lblPhoneW
//
this->lblPhoneW->Anchor =
System::Windows::Forms::AnchorStyles::Right;
this->lblPhoneW->AutoSize = true;
this->lblPhoneW->Location = System::Drawing::Point(4, 119);
this->lblPhoneW->Name = "lblPhoneW";
this->lblPhoneW->Size = System::Drawing::Size(58, 14);
this->lblPhoneW->TabIndex = 32;
this->lblPhoneW->Text = "Phone (W)";
//
// richTxtNotes
//
this->tableLayoutPanel1->SetColumnSpan(this->richTxtNotes, 3);
this->richTxtNotes->Dock = System::Windows::Forms::DockStyle::Fill;
this->richTxtNotes->Location = System::Drawing::Point(68, 143);
this->richTxtNotes->Name = "richTxtNotes";
this->richTxtNotes->Size = System::Drawing::Size(552, 140);
this->richTxtNotes->TabIndex = 8;
this->richTxtNotes->Text = "";
//
// cancelBtn
//
this->cancelBtn->Anchor =
System::Windows::Forms::AnchorStyles::Bottom |
System::Windows::Forms::AnchorStyles::Right;
this->cancelBtn->DialogResult =
System::Windows::Forms::DialogResult::Cancel;
this->cancelBtn->Location = System::Drawing::Point(558, 306);
this->cancelBtn->Name = "cancelBtn";
this->cancelBtn->TabIndex = 1;
this->cancelBtn->Text = "Cancel";
this->cancelBtn->Click += gcnew System::EventHandler(
this, &BasicDataEntryForm::cancelBtn_Click);
//
// okBtn
//
this->okBtn->Anchor =
System::Windows::Forms::AnchorStyles::Bottom |
System::Windows::Forms::AnchorStyles::Right;
this->okBtn->DialogResult =
System::Windows::Forms::DialogResult::OK;
this->okBtn->Location = System::Drawing::Point(476, 306);
this->okBtn->Name = "okBtn";
this->okBtn->TabIndex = 0;
this->okBtn->Text = "OK";
this->okBtn->Click += gcnew System::EventHandler(
this, &BasicDataEntryForm::okBtn_Click);
//
// BasicDataEntryForm
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(642, 338);
this->Controls->Add(this->okBtn);
this->Controls->Add(this->cancelBtn);
this->Controls->Add(this->tableLayoutPanel1);
this->Name = "BasicDataEntryForm";
this->Padding = System::Windows::Forms::Padding(9);
this->StartPosition =
System::Windows::Forms::FormStartPosition::Manual;
this->Text = "Basic Data Entry";
this->tableLayoutPanel1->ResumeLayout(false);
this->tableLayoutPanel1->PerformLayout();
this->ResumeLayout(false);
}
private:
System::Windows::Forms::TableLayoutPanel^ tableLayoutPanel1;
System::Windows::Forms::Label^ lblFirstName;
System::Windows::Forms::Label^ lblLastName;
System::Windows::Forms::Label^ lblAddress1;
System::Windows::Forms::Label^ lblAddress2;
System::Windows::Forms::Label^ lblCity;
System::Windows::Forms::Label^ lblState;
System::Windows::Forms::Label^ lblNotes;
System::Windows::Forms::Label^ lblPhoneW;
System::Windows::Forms::Label^ lblPhoneH;
System::Windows::Forms::Button^ cancelBtn;
System::Windows::Forms::Button^ okBtn;
System::Windows::Forms::TextBox^ txtFirstName;
System::Windows::Forms::TextBox^ txtAddress1;
System::Windows::Forms::TextBox^ txtAddress2;
System::Windows::Forms::TextBox^ txtCity;
System::Windows::Forms::TextBox^ txtLastName;
System::Windows::Forms::MaskedTextBox^ maskedTxtPhoneW;
System::Windows::Forms::MaskedTextBox^ maskedTxtPhoneH;
System::Windows::Forms::ComboBox^ cboState;
System::Windows::Forms::RichTextBox^ richTxtNotes;
};
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew BasicDataEntryForm());
}
// </snippet1>
@@ -0,0 +1,2 @@
System.Windows.Forms.TableLayoutPanel.DataEntryForm.exe : basicdataentryform.cpp
cl /W4 /clr:pure /FeSystem.Windows.Forms.TableLayoutPanel.DataEntryForm.exe basicdataentryform.cpp
@@ -0,0 +1,332 @@
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Windows::Forms;
/// <summary>
/// Summary description for form.
/// </summary>
// The following example shows how to wrap a control
// using ToolStripControlHost.
//<snippet13>
//Declare a class that inherits from ToolStripControlHost.
public ref class ToolStripMonthCalendar: public ToolStripControlHost
{
public:
//<snippet10>
// Call the base constructor passing in a MonthCalendar instance.
ToolStripMonthCalendar() : ToolStripControlHost( gcnew MonthCalendar ) {}
//</snippet10>
//<snippet11>
property MonthCalendar^ MonthCalendarControl
{
MonthCalendar^ get()
{
return static_cast<MonthCalendar^>(Control);
}
}
//</snippet11>
//<snippet12>
property Day FirstDayOfWeek
{
// Expose the MonthCalendar.FirstDayOfWeek as a property.
Day get()
{
return MonthCalendarControl->FirstDayOfWeek;
}
void set( Day value )
{
MonthCalendarControl->FirstDayOfWeek = value;
}
}
// Expose the AddBoldedDate method.
void AddBoldedDate( DateTime dateToBold )
{
MonthCalendarControl->AddBoldedDate( dateToBold );
}
//</snippet12>
protected:
// Subscribe and unsubscribe the control events you wish to expose.
//<snippet16>
//<snippet14>
void OnSubscribeControlEvents( System::Windows::Forms::Control^ c )
{
// Call the base so the base events are connected.
__super::OnSubscribeControlEvents( c );
// Cast the control to a MonthCalendar control.
MonthCalendar^ monthCalendarControl = (MonthCalendar^)c;
// Add the event.
monthCalendarControl->DateChanged += gcnew DateRangeEventHandler( this, &ToolStripMonthCalendar::HandleDateChanged );
}
//</snippet14>
//<snippet15>
void OnUnsubscribeControlEvents( System::Windows::Forms::Control^ c )
{
// Call the base method so the basic events are unsubscribed.
__super::OnUnsubscribeControlEvents( c );
// Cast the control to a MonthCalendar control.
MonthCalendar^ monthCalendarControl = (MonthCalendar^)c;
// Remove the event.
monthCalendarControl->DateChanged -= gcnew DateRangeEventHandler( this, &ToolStripMonthCalendar::HandleDateChanged );
}
//</snippet15>
//</snippet16>
public:
event DateRangeEventHandler^ DateChanged;
private:
//<snippet17>
// Declare the DateChanged event.
// Raise the DateChanged event.
void HandleDateChanged( Object^ sender, DateRangeEventArgs^ e )
{
if ( DateChanged != nullptr )
{
DateChanged( this, e );
}
}
//</snippet17>
};
//</snippet13>
public ref class Form1: public System::Windows::Forms::Form
{
private:
/// <summary>
/// Required designer variable.
/// </summary>
static System::ComponentModel::IContainer^ components = nullptr;
static ToolStripTextBox^ textbox1;
public:
Form1()
{
InitializeComponent();
InitializeDropDownMonthCalendar();
textbox1 = gcnew ToolStripTextBox;
textbox1->Width = 70;
toolStrip1->Items->Add( textbox1 );
InitializeDateTimePickerHost();
}
static void Main()
{
Application::Run( gcnew Form1 );
}
private:
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent()
{
this->toolStrip1 = gcnew System::Windows::Forms::ToolStrip;
this->raftingContainer1 = gcnew System::Windows::Forms::RaftingContainer;
this->raftingContainer2 = gcnew System::Windows::Forms::RaftingContainer;
this->raftingContainer3 = gcnew System::Windows::Forms::RaftingContainer;
this->raftingContainer4 = gcnew System::Windows::Forms::RaftingContainer;
this->SuspendLayout();
//
// toolStrip1
//
this->toolStrip1->Anchor = System::Windows::Forms::AnchorStyles::Right;
this->toolStrip1->Dock = System::Windows::Forms::DockStyle::None;
this->toolStrip1->Location = System::Drawing::Point( 0, 0 );
this->toolStrip1->Name = L"toolStrip1";
this->toolStrip1->Raft = System::Windows::Forms::RaftingSides::Top;
this->toolStrip1->TabIndex = 1;
this->toolStrip1->Text = L"toolStrip1";
this->toolStrip1->Visible = true;
//
// raftingContainer1
//
this->raftingContainer1->AutoSize = true;
this->raftingContainer1->Dock = System::Windows::Forms::DockStyle::Top;
this->raftingContainer1->Location = System::Drawing::Point( 9, 9 );
this->raftingContainer1->Name = L"raftingContainer1";
this->raftingContainer1->Orientation = System::Windows::Forms::Orientation::Horizontal;
this->raftingContainer1->RowMargin = System::Windows::Forms::Padding( 0 );
this->raftingContainer1->Size = System::Drawing::Size( 274, 25 );
this->raftingContainer1->TabIndex = 0;
this->raftingContainer1->Text = L"RaftingContainerRaftingContainerTop";
this->raftingContainer1->Join( this->toolStrip1 );
//
// raftingContainer2
//
this->raftingContainer2->AutoSize = true;
this->raftingContainer2->Dock = System::Windows::Forms::DockStyle::Bottom;
this->raftingContainer2->Location = System::Drawing::Point( 9, 257 );
this->raftingContainer2->Name = L"raftingContainer2";
this->raftingContainer2->Orientation = System::Windows::Forms::Orientation::Horizontal;
this->raftingContainer2->RowMargin = System::Windows::Forms::Padding( 0 );
this->raftingContainer2->Size = System::Drawing::Size( 274, 0 );
this->raftingContainer2->TabIndex = 1;
this->raftingContainer2->Text = L"RaftingContainerRaftingContainerBottom";
//
// raftingContainer3
//
this->raftingContainer3->AutoSize = true;
this->raftingContainer3->Dock = System::Windows::Forms::DockStyle::Left;
this->raftingContainer3->Location = System::Drawing::Point( 9, 9 );
this->raftingContainer3->Name = L"raftingContainer3";
this->raftingContainer3->Orientation = System::Windows::Forms::Orientation::Vertical;
this->raftingContainer3->RowMargin = System::Windows::Forms::Padding( 0 );
this->raftingContainer3->Size = System::Drawing::Size( 0, 248 );
this->raftingContainer3->TabIndex = 2;
this->raftingContainer3->Text = L"RaftingContainerRaftingContainerLeft";
//
// raftingContainer4
//
this->raftingContainer4->AutoSize = true;
this->raftingContainer4->Dock = System::Windows::Forms::DockStyle::Right;
this->raftingContainer4->Location = System::Drawing::Point( 283, 9 );
this->raftingContainer4->Name = L"raftingContainer4";
this->raftingContainer4->Orientation = System::Windows::Forms::Orientation::Vertical;
this->raftingContainer4->RowMargin = System::Windows::Forms::Padding( 0 );
this->raftingContainer4->Size = System::Drawing::Size( 0, 248 );
this->raftingContainer4->TabIndex = 3;
this->raftingContainer4->Text = L"RaftingContainerRaftingContainerRight";
//
// Form1
//
this->AutoSize = true;
this->ClientSize = System::Drawing::Size( 292, 266 );
this->Controls->Add( this->raftingContainer1 );
this->Controls->Add( this->raftingContainer2 );
this->Controls->Add( this->raftingContainer3 );
this->Controls->Add( this->raftingContainer4 );
this->Name = L"Form1";
this->Padding = System::Windows::Forms::Padding( 9 );
this->Text = L"Form1";
this->ResumeLayout( false );
this->PerformLayout();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
void Dispose( bool disposing )
{
if ( disposing )
{
if ( components != nullptr )
{
delete components;
}
}
__super::Dispose( disposing );
}
private:
System::Windows::Forms::ToolStrip^ toolStrip1;
System::Windows::Forms::RaftingContainer^ raftingContainer1;
System::Windows::Forms::RaftingContainer^ raftingContainer2;
System::Windows::Forms::RaftingContainer^ raftingContainer3;
System::Windows::Forms::RaftingContainer^ raftingContainer4;
// The following snippet demonstrates the ToolStripControlHost(Control)
// consturctor, the ToolStripControlHost.Font, Width, DisplayStyle,
// Text properties.
//<snippet1>
ToolStripControlHost^ dateTimePickerHost;
void InitializeDateTimePickerHost()
{
// Create a new ToolStripControlHost, passing in a control.
dateTimePickerHost = gcnew ToolStripControlHost( gcnew DateTimePicker );
// Set the font on the ToolStripControlHost, this will affect the hosted control.
dateTimePickerHost->Font =
gcnew System::Drawing::Font( L"Arial",7.0F,FontStyle::Italic );
// Set the Width property, this will also affect the hosted control.
dateTimePickerHost->Width = 100;
dateTimePickerHost->DisplayStyle = ToolStripItemDisplayStyle::Text;
// Setting the Text property requires a string that converts to a
// DateTime type since that is what the hosted control requires.
dateTimePickerHost->Text = L"12/23/2005";
// Cast the Control property back to the original type to set a
// type-specific property.
(dynamic_cast<DateTimePicker^>(dateTimePickerHost->Control))->Format =
DateTimePickerFormat::Short;
// Add the control host to the ToolStrip.
toolStrip1->Items->Add( dateTimePickerHost );
}
//</snippet1>
// The following example shows how to set the custom
// ToolStripMonthCalendar control.
//<snippet2>
void InitializeDropDownMonthCalendar()
{
// Declare the drop-down button and the drop-down.
ToolStripDropDownButton^ dropDownButton2 = gcnew ToolStripDropDownButton;
// Set the image to the MonthCalendar embedded bitmap
// image.
dropDownButton2->Image =
gcnew Bitmap( MonthCalendar::typeid,L"MonthCalendar.bmp" );
// Add the button to the ToolStrip.
toolStrip1->Items->Add( dropDownButton2 );
// Construct a new drop-down.
ToolStripDropDown^ dropDown = gcnew ToolStripDropDown;
// Construct a new wrapped MonthCalendar control.
ToolStripMonthCalendar^ monthCalendar = gcnew ToolStripMonthCalendar;
// Set a date in boldface.
monthCalendar->AddBoldedDate( DateTime::Today.AddDays( 7 ) );
monthCalendar->DateChanged += gcnew DateRangeEventHandler(
this, &Form1::monthCalendar_DateChanged );
//Add the calendar to the drop-down.
dropDown->Items->Add( monthCalendar );
//Set the drop-down on the DropDownButton.
dropDownButton2->DropDown = dropDown;
}
private:
void monthCalendar_DateChanged( Object^ /*sender*/, DateRangeEventArgs^ e )
{
textbox1->Text = e->Start.ToShortDateString();
}
};
int main()
{
Form1::Main();
}
//</snippet2>
@@ -0,0 +1,775 @@
// User Input Test Application for new Windows Forms user input conceptual topics
// in Visual Studio 2005 documentation.
// <Snippet0>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
namespace UserInputWalkthrough
{
public ref class Form1 : public Form
{
Label^ lblEvent;
Label^ lblInput;
TextBox^ TextBoxOutput;
TextBox^ TextBoxInput;
GroupBox^ GroupBoxEvents;
Button^ ButtonClear;
LinkLabel^ LinkLabelDrag;
CheckBox^ CheckBoxToggleAll;
CheckBox^ CheckBoxMouse;
CheckBox^ CheckBoxMouseEnter;
CheckBox^ CheckBoxMouseMove;
CheckBox^ CheckBoxMousePoints;
CheckBox^ CheckBoxMouseDrag;
CheckBox^ CheckBoxMouseDragOver;
CheckBox^ CheckBoxKeyboard;
CheckBox^ CheckBoxKeyUpDown;
CheckBox^ CheckBoxFocus;
CheckBox^ CheckBoxValidation;
public:
Form1() : Form()
{
this->Load += gcnew EventHandler(this, &Form1::Form1_Load);
lblEvent = gcnew Label();
lblInput = gcnew Label();
TextBoxOutput = gcnew TextBox();
TextBoxInput = gcnew TextBox();
GroupBoxEvents = gcnew GroupBox();
ButtonClear = gcnew Button();
LinkLabelDrag = gcnew LinkLabel();
CheckBoxToggleAll = gcnew CheckBox();
CheckBoxMouse = gcnew CheckBox();
CheckBoxMouseEnter = gcnew CheckBox();
CheckBoxMouseMove = gcnew CheckBox();
CheckBoxMousePoints = gcnew CheckBox();
CheckBoxMouseDrag = gcnew CheckBox();
CheckBoxMouseDragOver = gcnew CheckBox();
CheckBoxKeyboard = gcnew CheckBox();
CheckBoxKeyUpDown = gcnew CheckBox();
CheckBoxFocus = gcnew CheckBox();
CheckBoxValidation = gcnew CheckBox();
}
private:
void Form1_Load(Object^ sender, EventArgs^ e)
{
this->GroupBoxEvents->SuspendLayout();
this->SuspendLayout();
lblEvent->Location = Point(232, 12);
lblEvent->Size = System::Drawing::Size(98, 14);
lblEvent->AutoSize = true;
lblEvent->Text = "Generated Events:";
lblInput->Location = Point(13, 12);
lblInput->Size = System::Drawing::Size(95, 14);
lblInput->AutoSize = true;
lblInput->Text = "User Input Target:";
TextBoxInput->Location = Point(13, 34);
TextBoxInput->Size = System::Drawing::Size(200, 200);
TextBoxInput->AllowDrop = true;
TextBoxInput->AutoSize = false;
TextBoxInput->Cursor = Cursors::Cross;
TextBoxInput->Multiline = true;
TextBoxInput->TabIndex = 1;
LinkLabelDrag->AllowDrop = true;
LinkLabelDrag->AutoSize = true;
LinkLabelDrag->Location = Point(13, 240);
LinkLabelDrag->Size = System::Drawing::Size(175, 14);
LinkLabelDrag->TabIndex = 2;
LinkLabelDrag->TabStop = true;
LinkLabelDrag->Text = "Click here to use as a drag source";
LinkLabelDrag->Links->Add(gcnew LinkLabel::Link(0,
LinkLabelDrag->Text->Length));
GroupBoxEvents->Location = Point(13, 281);
GroupBoxEvents->Size = System::Drawing::Size(200, 302);
GroupBoxEvents->Text = "Event Filter:";
GroupBoxEvents->TabStop = true;
GroupBoxEvents->TabIndex = 3;
GroupBoxEvents->Controls->Add(CheckBoxMouseEnter);
GroupBoxEvents->Controls->Add(CheckBoxToggleAll);
GroupBoxEvents->Controls->Add(CheckBoxMousePoints);
GroupBoxEvents->Controls->Add(CheckBoxKeyUpDown);
GroupBoxEvents->Controls->Add(CheckBoxMouseDragOver);
GroupBoxEvents->Controls->Add(CheckBoxMouseDrag);
GroupBoxEvents->Controls->Add(CheckBoxValidation);
GroupBoxEvents->Controls->Add(CheckBoxMouseMove);
GroupBoxEvents->Controls->Add(CheckBoxFocus);
GroupBoxEvents->Controls->Add(CheckBoxKeyboard);
GroupBoxEvents->Controls->Add(CheckBoxMouse);
CheckBoxToggleAll->AutoSize = true;
CheckBoxToggleAll->Location = Point(7, 20);
CheckBoxToggleAll->Size = System::Drawing::Size(122, 17);
CheckBoxToggleAll->TabIndex = 4;
CheckBoxToggleAll->Text = "Toggle All Events";
CheckBoxMouse->AutoSize = true;
CheckBoxMouse->Location = Point(7, 45);
CheckBoxMouse->Size = System::Drawing::Size(137, 17);
CheckBoxMouse->TabIndex = 5;
CheckBoxMouse->Text = "Mouse and Click Events";
CheckBoxMouseEnter->AutoSize = true;
CheckBoxMouseEnter->Location = Point(26, 69);
CheckBoxMouseEnter->Margin =
System::Windows::Forms::Padding(3, 3, 3, 1);
CheckBoxMouseEnter->Size = System::Drawing::Size(151, 17);
CheckBoxMouseEnter->TabIndex = 6;
CheckBoxMouseEnter->Text = "Mouse Enter/Hover/Leave";
CheckBoxMouseMove->AutoSize = true;
CheckBoxMouseMove->Location = Point(26, 89);
CheckBoxMouseMove->Margin =
System::Windows::Forms::Padding(3, 2, 3, 3);
CheckBoxMouseMove->Size = System::Drawing::Size(120, 17);
CheckBoxMouseMove->TabIndex = 7;
CheckBoxMouseMove->Text = "Mouse Move Events";
CheckBoxMousePoints->AutoSize = true;
CheckBoxMousePoints->Location = Point(26, 112);
CheckBoxMousePoints->Margin =
System::Windows::Forms::Padding(3, 3, 3, 1);
CheckBoxMousePoints->Size = System::Drawing::Size(141, 17);
CheckBoxMousePoints->TabIndex = 8;
CheckBoxMousePoints->Text = "Draw Mouse Points";
CheckBoxMouseDrag->AutoSize = true;
CheckBoxMouseDrag->Location = Point(26, 135);
CheckBoxMouseDrag->Margin =
System::Windows::Forms::Padding(3, 1, 3, 3);
CheckBoxMouseDrag->Size = System::Drawing::Size(151, 17);
CheckBoxMouseDrag->TabIndex = 9;
CheckBoxMouseDrag->Text = "Mouse Drag && Drop Events";
CheckBoxMouseDragOver->AutoSize = true;
CheckBoxMouseDragOver->Location = Point(44, 159);
CheckBoxMouseDragOver->Size = System::Drawing::Size(142, 17);
CheckBoxMouseDragOver->TabIndex = 10;
CheckBoxMouseDragOver->Text = "Mouse Drag Over Events";
CheckBoxKeyboard->AutoSize = true;
CheckBoxKeyboard->Location = Point(8, 184);
CheckBoxKeyboard->Size = System::Drawing::Size(103, 17);
CheckBoxKeyboard->TabIndex = 11;
CheckBoxKeyboard->Text = "Keyboard Events";
CheckBoxKeyUpDown->AutoSize = true;
CheckBoxKeyUpDown->Location = Point(26, 207);
CheckBoxKeyUpDown->Margin =
System::Windows::Forms::Padding(3, 3, 3, 1);
CheckBoxKeyUpDown->Size = System::Drawing::Size(133, 17);
CheckBoxKeyUpDown->TabIndex = 12;
CheckBoxKeyUpDown->Text = "Key Up && Down Events";
CheckBoxFocus->AutoSize = true;
CheckBoxFocus->Location = Point(8, 233);
CheckBoxFocus->Margin =
System::Windows::Forms::Padding(3, 2, 3, 3);
CheckBoxFocus->Size = System::Drawing::Size(146, 17);
CheckBoxFocus->TabIndex = 13;
CheckBoxFocus->Text = "Focus && Activation Events";
CheckBoxValidation->AutoSize = true;
CheckBoxValidation->Location = Point(8, 257);
CheckBoxValidation->Size = System::Drawing::Size(104, 17);
CheckBoxValidation->TabIndex = 14;
CheckBoxValidation->Text = "Validation Events";
TextBoxOutput->Location = Point(232, 34);
TextBoxOutput->Size = System::Drawing::Size(308, 510);
TextBoxOutput->Multiline = true;
TextBoxOutput->CausesValidation = false;
TextBoxOutput->ReadOnly = true;
TextBoxOutput->ScrollBars = ScrollBars::Vertical;
TextBoxOutput->TabIndex = 15;
TextBoxOutput->WordWrap = false;
ButtonClear->Location = Point(232, 560);
ButtonClear->Size = System::Drawing::Size(308, 23);
ButtonClear->TabIndex = 16;
ButtonClear->Text = "Clear Event List";
this->ClientSize = System::Drawing::Size(552, 595);
this->Controls->Add(LinkLabelDrag);
this->Controls->Add(ButtonClear);
this->Controls->Add(GroupBoxEvents);
this->Controls->Add(lblEvent);
this->Controls->Add(lblInput);
this->Controls->Add(TextBoxInput);
this->Controls->Add(TextBoxOutput);
this->Text = "User Input Events";
ButtonClear->Click +=
gcnew EventHandler(this, &Form1::ButtonClear_Click);
TextBoxInput->KeyDown +=
gcnew KeyEventHandler(this, &Form1::TextBoxInput_KeyDown);
TextBoxInput->KeyPress +=
gcnew KeyPressEventHandler(this,
&Form1::TextBoxInput_KeyPress);
TextBoxInput->KeyUp +=
gcnew KeyEventHandler(this, &Form1::TextBoxInput_KeyUp);
TextBoxInput->Click +=
gcnew EventHandler(this, &Form1::TextBoxInput_Click);
TextBoxInput->DoubleClick +=
gcnew EventHandler(this, &Form1::TextBoxInput_DoubleClick);
TextBoxInput->MouseClick +=
gcnew MouseEventHandler(this, &Form1::TextBoxInput_MouseClick);
TextBoxInput->MouseDoubleClick +=
gcnew MouseEventHandler(this,
&Form1::TextBoxInput_MouseDoubleClick);
TextBoxInput->MouseDown +=
gcnew MouseEventHandler(this, &Form1::TextBoxInput_MouseDown);
TextBoxInput->MouseUp +=
gcnew MouseEventHandler(this, &Form1::TextBoxInput_MouseUp);
TextBoxInput->MouseEnter +=
gcnew EventHandler(this, &Form1::TextBoxInput_MouseEnter);
TextBoxInput->MouseHover +=
gcnew EventHandler(this, &Form1::TextBoxInput_MouseHover);
TextBoxInput->MouseLeave +=
gcnew EventHandler(this, &Form1::TextBoxInput_MouseLeave);
TextBoxInput->MouseWheel +=
gcnew MouseEventHandler(this, &Form1::TextBoxInput_MouseWheel);
TextBoxInput->MouseMove +=
gcnew MouseEventHandler(this, &Form1::TextBoxInput_MouseMove);
TextBoxInput->MouseCaptureChanged +=
gcnew EventHandler(this,
&Form1::TextBoxInput_MouseCaptureChanged);
TextBoxInput->DragEnter +=
gcnew DragEventHandler(this, &Form1::TextBoxInput_DragEnter);
TextBoxInput->DragDrop +=
gcnew DragEventHandler(this, &Form1::TextBoxInput_DragDrop);
TextBoxInput->DragOver +=
gcnew DragEventHandler(this, &Form1::TextBoxInput_DragOver);
TextBoxInput->DragLeave +=
gcnew EventHandler(this, &Form1::TextBoxInput_DragLeave);
TextBoxInput->Enter +=
gcnew EventHandler(this, &Form1::TextBoxInput_Enter);
TextBoxInput->Leave +=
gcnew EventHandler(this, &Form1::TextBoxInput_Leave);
TextBoxInput->GotFocus +=
gcnew EventHandler(this, &Form1::TextBoxInput_GotFocus);
TextBoxInput->LostFocus +=
gcnew EventHandler(this, &Form1::TextBoxInput_LostFocus);
TextBoxInput->Validated +=
gcnew EventHandler(this, &Form1::TextBoxInput_Validated);
TextBoxInput->Validating +=
gcnew CancelEventHandler(this,
&Form1::TextBoxInput_Validating);
LinkLabelDrag->MouseDown +=
gcnew MouseEventHandler(this, &Form1::LinkLabelDrag_MouseDown);
LinkLabelDrag->GiveFeedback +=
gcnew GiveFeedbackEventHandler(this,
&Form1::LinkLabelDrag_GiveFeedback);
CheckBoxToggleAll->CheckedChanged +=
gcnew EventHandler(this,
&Form1::CheckBoxToggleAll_CheckedChanged);
CheckBoxMouse->CheckedChanged +=
gcnew EventHandler(this, &Form1::CheckBoxMouse_CheckedChanged);
CheckBoxMouseDrag->CheckedChanged +=
gcnew EventHandler(this,
&Form1::CheckBoxMouseDrag_CheckedChanged);
CheckBoxMouseEnter->CheckedChanged +=
gcnew EventHandler(this,
&Form1::CheckBoxMouseMove_CheckedChanged);
CheckBoxMouseMove->CheckedChanged +=
gcnew EventHandler(this,
&Form1::CheckBoxMouseMove_CheckedChanged);
CheckBoxKeyboard->CheckedChanged +=
gcnew EventHandler(this,
&Form1::CheckBoxKeyboard_CheckedChanged);
this->GroupBoxEvents->ResumeLayout(false);
this->GroupBoxEvents->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
CheckAllChildCheckBoxes(this, true);
}
// Recursively search the form for all contained checkboxes and
// initially check them
private:
void CheckAllChildCheckBoxes(Control^ parent, bool value)
{
CheckBox^ box;
for each (Control^ currentControl in parent->Controls)
{
if (dynamic_cast<CheckBox^>(currentControl))
{
box = (CheckBox^)currentControl;
box->Checked = value;
}
// Recurse if control contains other controls
if (currentControl->Controls->Count > 0)
{
CheckAllChildCheckBoxes(currentControl, value);
}
}
}
// All-purpose method for displaying a line of text in one of the
// text boxes.
private:
void DisplayLine(String^ line)
{
TextBoxOutput->AppendText(line);
TextBoxOutput->AppendText(Environment::NewLine);
}
// Click event handler for the button that clears the text box.
private:
void ButtonClear_Click(Object^ sender, EventArgs^ e)
{
TextBoxOutput->Invalidate();
TextBoxOutput->Clear();
}
private:
void TextBoxInput_KeyDown(Object^ sender, KeyEventArgs^ e)
{
if (CheckBoxKeyUpDown->Checked)
{
DisplayLine("KeyDown: " + e->KeyData.ToString());
}
}
private:
void TextBoxInput_KeyUp(Object^ sender, KeyEventArgs^ e)
{
if (CheckBoxKeyUpDown->Checked)
{
DisplayLine("KeyUp: " + e->KeyData.ToString());
}
}
private:
void TextBoxInput_KeyPress(Object^ sender,
KeyPressEventArgs^ e)
{
if (CheckBoxKeyboard->Checked)
{
if (Char::IsWhiteSpace(e->KeyChar))
{
DisplayLine("KeyPress: WS");
}
else
{
DisplayLine("KeyPress: " + e->KeyChar.ToString());
}
}
}
private:
void TextBoxInput_Click(Object^ sender, EventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("Click event");
}
}
private:
void TextBoxInput_DoubleClick(Object^ sender, EventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("DoubleClick event");
}
}
private:
void TextBoxInput_MouseClick(Object^ sender, MouseEventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("MouseClick: " + e->Button.ToString() +
" " + e->Location.ToString());
}
}
private:
void TextBoxInput_MouseDoubleClick(Object^ sender,
MouseEventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("MouseDoubleClick: " + e->Button.ToString() +
" " + e->Location.ToString());
}
}
private:
void TextBoxInput_MouseDown(Object^ sender,
MouseEventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("MouseDown: " + e->Button.ToString() +
" " + e->Location.ToString());
}
}
private:
void TextBoxInput_MouseUp(Object^ sender,
MouseEventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("MouseUp: " + e->Button.ToString() +
" " + e->Location.ToString());
}
// The TextBox control was designed to change focus only on
// the primary click, so force focus to avoid user confusion.
if (!TextBoxInput->Focused)
{
TextBoxInput->Focus();
}
}
private:
void TextBoxInput_MouseEnter(Object^ sender, EventArgs^ e)
{
if (CheckBoxMouseEnter->Checked)
{
DisplayLine("MouseEnter event");
}
}
private:
void TextBoxInput_MouseHover(Object^ sender, EventArgs^ e)
{
if (CheckBoxMouseEnter->Checked)
{
DisplayLine("MouseHover event");
}
}
private:
void TextBoxInput_MouseLeave(Object^ sender, EventArgs^ e)
{
if (CheckBoxMouseEnter->Checked)
{
DisplayLine("MouseLeave event");
}
}
private:
void TextBoxInput_MouseWheel(Object^ sender,
MouseEventArgs^ e)
{
if (CheckBoxMouse->Checked)
{
DisplayLine("MouseWheel: " + e->Delta.ToString() +
" detents at " + e->Location.ToString());
}
}
private:
void TextBoxInput_MouseMove(Object^ sender,
MouseEventArgs^ e)
{
if (CheckBoxMouseMove->Checked)
{
DisplayLine("MouseMove: " + e->Button.ToString() + " " +
e->Location.ToString());
}
if (CheckBoxMousePoints->Checked)
{
Graphics^ g = TextBoxInput->CreateGraphics();
g->FillRectangle(Brushes::Black, e->Location.X,
e->Location.Y, 1, 1);
delete g;
}
}
private:
void TextBoxInput_MouseCaptureChanged(Object^ sender,
EventArgs^ e)
{
if (CheckBoxMouseDrag->Checked)
{
DisplayLine("MouseCaptureChanged event");
}
}
private:
void TextBoxInput_DragEnter(Object^ sender, DragEventArgs^ e)
{
if (CheckBoxMouseDrag->Checked)
{
Point^ pt = gcnew Point(e->X, e->Y);
DisplayLine("DragEnter: " +
CovertKeyStateToString(e->KeyState)
+ " at " + pt->ToString());
}
}
private:
void TextBoxInput_DragDrop(Object^ sender, DragEventArgs^ e)
{
if (CheckBoxMouseDrag->Checked)
{
Point^ pt = gcnew Point(e->X, e->Y);
DisplayLine("DragDrop: " +
CovertKeyStateToString(e->KeyState)
+ " at " + pt->ToString());
}
}
private:
void TextBoxInput_DragOver(Object^ sender, DragEventArgs^ e)
{
if (CheckBoxMouseDragOver->Checked)
{
Point^ pt = gcnew Point(e->X, e->Y);
DisplayLine("DragOver: " +
CovertKeyStateToString(e->KeyState)
+ " at " + pt->ToString());
}
// Allow if drop data is of type string.
if (!e->Data->GetDataPresent(String::typeid))
{
e->Effect = DragDropEffects::None;
}
else
{
e->Effect = DragDropEffects::Copy;
}
}
private:
void TextBoxInput_DragLeave(Object^ sender,
EventArgs^ e)
{
if (CheckBoxMouseDrag->Checked)
{
DisplayLine("DragLeave event");
}
}
private:
static String^ CovertKeyStateToString(int keyState)
{
String^ keyString = "None";
// Which button was pressed?
if ((keyState & 1) == 1)
{
keyString = "Left";
}
else if ((keyState & 2) == 2)
{
keyString = "Right";
}
else if ((keyState & 16) == 16)
{
keyString = "Middle";
}
// Are one or more modifier keys also pressed?
if ((keyState & 4) == 4)
{
keyString += "+SHIFT";
}
if ((keyState & 8) == 8)
{
keyString += "+CTRL";
}
if ((keyState & 32) == 32)
{
keyString += "+ALT";
}
return keyString;
}
private:
void TextBoxInput_Enter(Object^ sender, EventArgs^ e)
{
if (CheckBoxFocus->Checked)
{
DisplayLine("Enter event");
}
}
private:
void TextBoxInput_Leave(Object^ sender, EventArgs^ e)
{
if (CheckBoxFocus->Checked)
{
DisplayLine("Leave event");
}
}
private:
void TextBoxInput_GotFocus(Object^ sender, EventArgs^ e)
{
if (CheckBoxFocus->Checked)
{
DisplayLine("GotFocus event");
}
}
private:
void TextBoxInput_LostFocus(Object^ sender, EventArgs^ e)
{
if (CheckBoxFocus->Checked)
{
DisplayLine("LostFocus event");
}
}
private:
void TextBoxInput_Validated(Object^ sender, EventArgs^ e)
{
if (CheckBoxValidation->Checked)
{
DisplayLine("Validated event");
}
}
private:
void TextBoxInput_Validating(
Object^ sender, CancelEventArgs^ e)
{
if (CheckBoxValidation->Checked)
{
DisplayLine("Validating event");
}
}
private:
void CheckBoxToggleAll_CheckedChanged(
Object^ sender, EventArgs^ e)
{
if (dynamic_cast<CheckBox^>(sender))
{
CheckAllChildCheckBoxes(this, ((CheckBox^)sender)->Checked);
}
}
private:
void CheckBoxMouse_CheckedChanged(
Object^ sender, EventArgs^ e)
{
ConfigureCheckBoxSettings();
}
private:
void CheckBoxMouseDrag_CheckedChanged(
Object^ sender, EventArgs^ e)
{
ConfigureCheckBoxSettings();
}
private:
void CheckBoxKeyboard_CheckedChanged(
Object^ sender, EventArgs^ e)
{
ConfigureCheckBoxSettings();
}
private:
void CheckBoxMouseMove_CheckedChanged(
Object^ sender, EventArgs^ e)
{
ConfigureCheckBoxSettings();
}
// Reconcile dependencies between the check box
// selection choices.
private:
void ConfigureCheckBoxSettings()
{
// CheckBoxMouse is a top-level check box.
if (!CheckBoxMouse->Checked)
{
CheckBoxMouseEnter->Enabled = false;
CheckBoxMouseMove->Enabled = false;
CheckBoxMouseDrag->Enabled = false;
CheckBoxMouseDragOver->Enabled = false;
CheckBoxMousePoints->Enabled = false;
}
else
{
CheckBoxMouseEnter->Enabled = true;
CheckBoxMouseMove->Enabled = true;
CheckBoxMouseDrag->Enabled = true;
CheckBoxMousePoints->Enabled = true;
// Enable children depending on the state of the parent.
if (!CheckBoxMouseDrag->Checked)
{
CheckBoxMouseDragOver->Enabled = false;
}
else
{
CheckBoxMouseDragOver->Enabled = true;
}
}
if (!CheckBoxKeyboard->Checked)
{
CheckBoxKeyUpDown->Enabled = false;
}
else
{
CheckBoxKeyUpDown->Enabled = true;
}
}
private:
void LinkLabelDrag_MouseDown(Object^ sender, MouseEventArgs^ e)
{
String^ data = "Sample Data";
LinkLabelDrag->DoDragDrop(data, DragDropEffects::All);
}
private:
void LinkLabelDrag_GiveFeedback(Object^ sender,
GiveFeedbackEventArgs^ e)
{
if ((e->Effect & DragDropEffects::Copy) ==
DragDropEffects::Copy)
{
LinkLabelDrag->Cursor = Cursors::HSplit;
}
else
{
LinkLabelDrag->Cursor = Cursors::Default;
}
}
};
}
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew UserInputWalkthrough::Form1());
}
// </Snippet0>
@@ -0,0 +1,2 @@
System.Windows.Forms.UserInputWalkthrough.exe: form1.cpp
cl /clr:pure /FeSystem.Windows.Forms.UserInputWalkthrough.exe form1.cpp
@@ -0,0 +1,76 @@
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;
namespace SimpleVisualStyleRendererSample
{
public ref class CustomControl : public Control
{
// <Snippet4>
private:
VisualStyleRenderer^ renderer;
VisualStyleElement^ element;
public:
CustomControl()
{
this->Location = Point(50, 50);
this->Size = System::Drawing::Size(200, 200);
this->BackColor = SystemColors::ActiveBorder;
this->element =
VisualStyleElement::StartPanel::LogOffButtons::Normal;
if (Application::RenderWithVisualStyles &&
VisualStyleRenderer::IsElementDefined(element))
{
renderer = gcnew VisualStyleRenderer(element);
}
}
// </Snippet4>
// <Snippet6>
protected:
virtual void OnPaint(PaintEventArgs^ e) override
{
// Draw the element if the renderer has been set.
if (renderer != nullptr)
{
renderer->DrawBackground(e->Graphics, this->ClientRectangle);
}
// Visual styles are disabled or the element is undefined,
// so just draw a message.
else
{
this->Text = "Visual styles are disabled.";
TextRenderer::DrawText(e->Graphics, this->Text, this->Font,
Point(0, 0), this->ForeColor);
}
}
// </Snippet6>
};
public ref class SimpleVisualStyleRendererForm : public Form
{
public:
SimpleVisualStyleRendererForm()
{
this->Size = System::Drawing::Size(400, 400);
this->BackColor = Color::WhiteSmoke;
this->Controls->Add(gcnew CustomControl());
}
};
}
using namespace SimpleVisualStyleRendererSample;
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew SimpleVisualStyleRendererForm());
}
@@ -0,0 +1,2 @@
System.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple.exe : form1.cpp
cl /W4 /clr:pure /FeSystem.Windows.Forms.VisualStyles.VisualStyleRenderer_Simple.exe form1.cpp
@@ -0,0 +1,502 @@
//<Snippet0>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Security::Permissions;
public ref class Form1: public System::Windows::Forms::Form
{
public:
Form1()
{
//This call is required by the Windows Form Designer.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
private:
//NOTE: The following procedure is required by the Windows Form Designer
//It can be modified using the Windows Form Designer.
//Do not modify it using the code editor.
System::Windows::Forms::MainMenu^ MainMenu1;
System::Windows::Forms::MenuItem^ MenuItemFile;
System::Windows::Forms::MenuItem^ MenuItemFileSaveAs;
System::Windows::Forms::MenuItem^ MenuItemFilePageSetup;
System::Windows::Forms::MenuItem^ MenuItemFilePrint;
System::Windows::Forms::MenuItem^ MenuItemFilePrintPreview;
System::Windows::Forms::MenuItem^ MenuItemFileProperties;
System::Windows::Forms::TextBox^ TextBoxAddress;
System::Windows::Forms::Button^ ButtonGo;
System::Windows::Forms::Button^ backButton;
System::Windows::Forms::Button^ ButtonForward;
System::Windows::Forms::Button^ ButtonStop;
System::Windows::Forms::Button^ ButtonRefresh;
System::Windows::Forms::Button^ ButtonHome;
System::Windows::Forms::Button^ ButtonSearch;
System::Windows::Forms::Panel^ Panel1;
System::Windows::Forms::WebBrowser ^ WebBrowser1;
System::Windows::Forms::StatusBar^ StatusBar1;
System::Windows::Forms::MenuItem^ MenuItem1;
System::Windows::Forms::MenuItem^ MenuItem2;
System::Windows::Forms::Button^ ButtonPrint;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
[SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
void InitializeComponent()
{
this->MainMenu1 = gcnew System::Windows::Forms::MainMenu;
this->MenuItemFile = gcnew System::Windows::Forms::MenuItem;
this->MenuItemFileSaveAs = gcnew System::Windows::Forms::MenuItem;
this->MenuItem1 = gcnew System::Windows::Forms::MenuItem;
this->MenuItemFilePageSetup = gcnew System::Windows::Forms::MenuItem;
this->MenuItemFilePrint = gcnew System::Windows::Forms::MenuItem;
this->MenuItemFilePrintPreview = gcnew System::Windows::Forms::MenuItem;
this->MenuItem2 = gcnew System::Windows::Forms::MenuItem;
this->MenuItemFileProperties = gcnew System::Windows::Forms::MenuItem;
this->TextBoxAddress = gcnew System::Windows::Forms::TextBox;
this->ButtonGo = gcnew System::Windows::Forms::Button;
this->backButton = gcnew System::Windows::Forms::Button;
this->ButtonForward = gcnew System::Windows::Forms::Button;
this->ButtonStop = gcnew System::Windows::Forms::Button;
this->ButtonRefresh = gcnew System::Windows::Forms::Button;
this->ButtonHome = gcnew System::Windows::Forms::Button;
this->ButtonSearch = gcnew System::Windows::Forms::Button;
this->ButtonPrint = gcnew System::Windows::Forms::Button;
this->Panel1 = gcnew System::Windows::Forms::Panel;
this->WebBrowser1 = gcnew System::Windows::Forms::WebBrowser;
this->StatusBar1 = gcnew System::Windows::Forms::StatusBar;
this->Panel1->SuspendLayout();
this->SuspendLayout();
//
// MainMenu1
//
array<System::Windows::Forms::MenuItem^>^temp0 = {this->MenuItemFile};
this->MainMenu1->MenuItems->AddRange( temp0 );
this->MainMenu1->Name = "MainMenu1";
//
// MenuItemFile
//
this->MenuItemFile->Index = 0;
array<System::Windows::Forms::MenuItem^>^temp1 = {this->MenuItemFileSaveAs,this->MenuItem1,this->MenuItemFilePageSetup,this->MenuItemFilePrint,this->MenuItemFilePrintPreview,this->MenuItem2,this->MenuItemFileProperties};
this->MenuItemFile->MenuItems->AddRange( temp1 );
this->MenuItemFile->Name = "MenuItemFile";
this->MenuItemFile->Text = "&File";
//
// MenuItemFileSaveAs
//
this->MenuItemFileSaveAs->Index = 0;
this->MenuItemFileSaveAs->Name = "MenuItemFileSaveAs";
this->MenuItemFileSaveAs->Text = " Save &As";
this->MenuItemFileSaveAs->Click += gcnew System::EventHandler( this, &Form1::MenuItemFileSaveAs_Click );
//
// MenuItem1
//
this->MenuItem1->Index = 1;
this->MenuItem1->Name = "MenuItem1";
this->MenuItem1->Text = "-";
//
// MenuItemFilePageSetup
//
this->MenuItemFilePageSetup->Index = 2;
this->MenuItemFilePageSetup->Name = "MenuItemFilePageSetup";
this->MenuItemFilePageSetup->Text = "Page Set&up...";
this->MenuItemFilePageSetup->Click += gcnew System::EventHandler( this, &Form1::MenuItemFilePageSetup_Click );
//
// MenuItemFilePrint
//
this->MenuItemFilePrint->Index = 3;
this->MenuItemFilePrint->Name = "MenuItemFilePrint";
this->MenuItemFilePrint->Text = "&Print...";
this->MenuItemFilePrint->Click += gcnew System::EventHandler( this, &Form1::MenuItemFilePrint_Click );
//
// MenuItemFilePrintPreview
//
this->MenuItemFilePrintPreview->Index = 4;
this->MenuItemFilePrintPreview->Name = "MenuItemFilePrintPreview";
this->MenuItemFilePrintPreview->Text = "Print Pre&view...";
this->MenuItemFilePrintPreview->Click += gcnew System::EventHandler( this, &Form1::MenuItemFilePrintPreview_Click );
//
// MenuItem2
//
this->MenuItem2->Index = 5;
this->MenuItem2->Name = "MenuItem2";
this->MenuItem2->Text = "-";
//
// MenuItemFileProperties
//
this->MenuItemFileProperties->Index = 6;
this->MenuItemFileProperties->Name = "MenuItemFileProperties";
this->MenuItemFileProperties->Text = "P&roperties";
this->MenuItemFileProperties->Click += gcnew System::EventHandler( this, &Form1::MenuItemFileProperties_Click );
//
// TextBoxAddress
//
this->TextBoxAddress->Location = System::Drawing::Point( 0, 0 );
this->TextBoxAddress->Name = "TextBoxAddress";
this->TextBoxAddress->Size = System::Drawing::Size( 240, 20 );
this->TextBoxAddress->TabIndex = 1;
this->TextBoxAddress->Text = "";
this->TextBoxAddress->KeyDown += gcnew System::Windows::Forms::KeyEventHandler( this, &Form1::TextBoxAddress_KeyDown );
//
// ButtonGo
//
this->ButtonGo->Location = System::Drawing::Point( 240, 0 );
this->ButtonGo->Name = "ButtonGo";
this->ButtonGo->Size = System::Drawing::Size( 48, 24 );
this->ButtonGo->TabIndex = 2;
this->ButtonGo->Text = "Go";
this->ButtonGo->Click += gcnew System::EventHandler( this, &Form1::ButtonGo_Click );
//
// backButton
//
this->backButton->Location = System::Drawing::Point( 288, 0 );
this->backButton->Name = "backButton";
this->backButton->Size = System::Drawing::Size( 48, 24 );
this->backButton->TabIndex = 3;
this->backButton->Text = "Back";
this->backButton->Click += gcnew System::EventHandler( this, &Form1::backButton_Click );
//
// ButtonForward
//
this->ButtonForward->Location = System::Drawing::Point( 336, 0 );
this->ButtonForward->Name = "ButtonForward";
this->ButtonForward->Size = System::Drawing::Size( 48, 24 );
this->ButtonForward->TabIndex = 4;
this->ButtonForward->Text = "Forward";
this->ButtonForward->Click += gcnew System::EventHandler( this, &Form1::ButtonForward_Click );
//
// ButtonStop
//
this->ButtonStop->Location = System::Drawing::Point( 384, 0 );
this->ButtonStop->Name = "ButtonStop";
this->ButtonStop->Size = System::Drawing::Size( 48, 24 );
this->ButtonStop->TabIndex = 5;
this->ButtonStop->Text = "Stop";
this->ButtonStop->Click += gcnew System::EventHandler( this, &Form1::ButtonStop_Click );
//
// ButtonRefresh
//
this->ButtonRefresh->Location = System::Drawing::Point( 432, 0 );
this->ButtonRefresh->Name = "ButtonRefresh";
this->ButtonRefresh->Size = System::Drawing::Size( 48, 24 );
this->ButtonRefresh->TabIndex = 6;
this->ButtonRefresh->Text = "Refresh";
this->ButtonRefresh->Click += gcnew System::EventHandler( this, &Form1::ButtonRefresh_Click );
//
// ButtonHome
//
this->ButtonHome->Location = System::Drawing::Point( 480, 0 );
this->ButtonHome->Name = "ButtonHome";
this->ButtonHome->Size = System::Drawing::Size( 48, 24 );
this->ButtonHome->TabIndex = 7;
this->ButtonHome->Text = "Home";
this->ButtonHome->Click += gcnew System::EventHandler( this, &Form1::ButtonHome_Click );
//
// ButtonSearch
//
this->ButtonSearch->Location = System::Drawing::Point( 528, 0 );
this->ButtonSearch->Name = "ButtonSearch";
this->ButtonSearch->Size = System::Drawing::Size( 48, 24 );
this->ButtonSearch->TabIndex = 8;
this->ButtonSearch->Text = "Search";
this->ButtonSearch->Click += gcnew System::EventHandler( this, &Form1::ButtonSearch_Click );
//
// ButtonPrint
//
this->ButtonPrint->Location = System::Drawing::Point( 576, 0 );
this->ButtonPrint->Name = "ButtonPrint";
this->ButtonPrint->Size = System::Drawing::Size( 48, 24 );
this->ButtonPrint->TabIndex = 9;
this->ButtonPrint->Text = "Print";
this->ButtonPrint->Click += gcnew System::EventHandler( this, &Form1::ButtonPrint_Click );
//
// Panel1
//
this->Panel1->Controls->Add( this->ButtonPrint );
this->Panel1->Controls->Add( this->TextBoxAddress );
this->Panel1->Controls->Add( this->ButtonGo );
this->Panel1->Controls->Add( this->backButton );
this->Panel1->Controls->Add( this->ButtonForward );
this->Panel1->Controls->Add( this->ButtonStop );
this->Panel1->Controls->Add( this->ButtonRefresh );
this->Panel1->Controls->Add( this->ButtonHome );
this->Panel1->Controls->Add( this->ButtonSearch );
this->Panel1->Dock = System::Windows::Forms::DockStyle::Top;
this->Panel1->Location = System::Drawing::Point( 0, 0 );
this->Panel1->Name = "Panel1";
this->Panel1->Size = System::Drawing::Size( 624, 24 );
this->Panel1->TabIndex = 11;
//
// WebBrowser1
//
//<Snippet17>
this->WebBrowser1->AllowWebBrowserDrop = false;
this->WebBrowser1->ScriptErrorsSuppressed = true;
this->WebBrowser1->WebBrowserShortcutsEnabled = false;
this->WebBrowser1->Dock = System::Windows::Forms::DockStyle::Fill;
this->WebBrowser1->IsWebBrowserContextMenuEnabled = false;
//</Snippet17>
this->WebBrowser1->Location = System::Drawing::Point( 0, 24 );
this->WebBrowser1->Name = "WebBrowser1";
this->WebBrowser1->Size = System::Drawing::Size( 624, 389 );
this->WebBrowser1->TabIndex = 10;
this->WebBrowser1->StatusTextChanged += gcnew System::EventHandler( this, &Form1::WebBrowser1_StatusTextChanged );
this->WebBrowser1->CanGoBackChanged += gcnew System::EventHandler( this, &Form1::WebBrowser1_CanGoBackChanged );
this->WebBrowser1->Navigated += gcnew System::Windows::Forms::WebBrowserNavigatedEventHandler( this, &Form1::WebBrowser1_Navigated );
this->WebBrowser1->CanGoForwardChanged += gcnew System::EventHandler( this, &Form1::WebBrowser1_CanGoForwardChanged );
this->WebBrowser1->DocumentTitleChanged += gcnew System::EventHandler( this, &Form1::WebBrowser1_DocumentTitleChanged );
//
// StatusBar1
//
this->StatusBar1->Location = System::Drawing::Point( 0, 413 );
this->StatusBar1->Name = "StatusBar1";
this->StatusBar1->Size = System::Drawing::Size( 624, 16 );
this->StatusBar1->TabIndex = 12;
//
// Form1
//
this->ClientSize = System::Drawing::Size( 624, 429 );
this->Controls->Add( this->WebBrowser1 );
this->Controls->Add( this->Panel1 );
this->Controls->Add( this->StatusBar1 );
this->Menu = this->MainMenu1;
this->Name = "Form1";
this->Text = "WebBrowser Example";
this->Panel1->ResumeLayout( false );
this->ResumeLayout( false );
}
internal:
static property Form1^ GetInstance
{
Form1^ get()
{
if ( m_DefaultInstance == nullptr || m_DefaultInstance->IsDisposed )
{
System::Threading::Monitor::Enter( Form1::typeid );
try
{
if ( m_DefaultInstance == nullptr || m_DefaultInstance->IsDisposed )
{
m_DefaultInstance = gcnew Form1;
}
}
finally
{
System::Threading::Monitor::Exit( Form1::typeid );
}
}
return m_DefaultInstance;
}
}
private:
static Form1^ m_DefaultInstance;
//<Snippet1>
// Displays the Save dialog box.
void MenuItemFileSaveAs_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->ShowSaveAsDialog();
}
//</Snippet1>
//<Snippet2>
// Displays the Page Setup dialog box.
void MenuItemFilePageSetup_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->ShowPageSetupDialog();
}
//</Snippet2>
//<Snippet3>
// Displays the Print dialog box.
void MenuItemFilePrint_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->ShowPrintDialog();
}
//</Snippet3>
//<Snippet4>
// Displays the Print Preview dialog box.
void MenuItemFilePrintPreview_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->ShowPrintPreviewDialog();
}
//</Snippet4>
//<Snippet5>
// Displays the Properties dialog box.
void MenuItemFileProperties_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->ShowPropertiesDialog();
}
//</Snippet5>
//<Snippet6>
// Navigates to the URL in the address text box when
// the ENTER key is pressed while the text box has focus.
void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
if ( e->KeyCode == System::Windows::Forms::Keys::Enter && !this->TextBoxAddress->Text->Equals( "" ) )
{
this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
}
}
// Navigates to the URL in the address text box when
// the Go button is clicked.
void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
if ( !this->TextBoxAddress->Text->Equals( "" ) )
{
this->WebBrowser1->Navigate( this->TextBoxAddress->Text );
}
}
// Updates the URL in TextBoxAddress upon navigation.
void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^ /*e*/ )
{
this->TextBoxAddress->Text = this->WebBrowser1->Url->ToString();
}
//</Snippet6>
//<Snippet7>
// Navigates WebBrowser1 to the previous page in the history.
void backButton_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->GoBack();
}
// Disables the Back button at the beginning of the navigation history.
void WebBrowser1_CanGoBackChanged( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->backButton->Enabled = this->WebBrowser1->CanGoBack;
}
//</Snippet7>
//<Snippet8>
// Navigates WebBrowser1 to the next page in history.
void ButtonForward_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->GoForward();
}
// Disables the Forward button at the end of navigation history.
void WebBrowser1_CanGoForwardChanged( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->ButtonForward->Enabled = this->WebBrowser1->CanGoForward;
}
//</Snippet8>
//<Snippet9>
// Halts the current navigation and any sounds or animations on
// the page.
void ButtonStop_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->Stop();
}
//</Snippet9>
//<Snippet10>
// Reloads the current page.
void ButtonRefresh_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Skip refresh if about:blank is loaded to avoid removing
// content specified by the DocumentText property.
if ( !this->WebBrowser1->Url->Equals( "about:blank" ) )
{
this->WebBrowser1->Refresh();
}
}
//</Snippet10>
//<Snippet11>
// Navigates WebBrowser1 to the home page of the current user.
void ButtonHome_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->GoHome();
}
//</Snippet11>
//<Snippet12>
// Navigates WebBrowser1 to the search page of the current user.
void ButtonSearch_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->GoSearch();
}
//</Snippet12>
//<Snippet13>
// Prints the current document using the current print settings.
void ButtonPrint_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->WebBrowser1->Print();
}
//</Snippet13>
//<Snippet14>
// Updates StatusBar1 with the current browser status text.
void WebBrowser1_StatusTextChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->StatusBar1->Text = WebBrowser1->StatusText;
}
//</Snippet14>
//<Snippet15>
// Updates the title bar with the current document title.
void WebBrowser1_DocumentTitleChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
this->Text = WebBrowser1->DocumentTitle;
}
//</Snippet15>
};
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
int main()
{
System::Windows::Forms::Application::Run( gcnew Form1 );
}
//</Snippet0>
@@ -0,0 +1,63 @@
//<Snippet0>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;
namespace SimpleControlRenderingSample
{
public ref class CustomComboBoxArrow : Control
{
public:
CustomComboBoxArrow() : Control()
{
this->Location = Point(50, 50);
this->Size = System::Drawing::Size(40, 40);
}
//<Snippet10>
// Render the drop-down arrow with or without visual styles.
protected:
virtual void OnPaint(PaintEventArgs^ e) override
{
__super::OnPaint(e);
if (!ComboBoxRenderer::IsSupported)
{
ControlPaint::DrawComboButton(e->Graphics,
this->ClientRectangle, ButtonState::Normal);
}
else
{
ComboBoxRenderer::DrawDropDownButton(e->Graphics,
this->ClientRectangle, ComboBoxState::Normal);
}
}
//</Snippet10>
};
public ref class SimpleControlRenderingForm : public Form
{
public:
SimpleControlRenderingForm() : Form()
{
this->Size = System::Drawing::Size(300, 300);
CustomComboBoxArrow^ testComboBox = gcnew CustomComboBoxArrow();
Controls->Add(testComboBox);
}
};
}
using namespace SimpleControlRenderingSample;
[STAThread]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew SimpleControlRenderingForm());
}
//</Snippet0>
@@ -0,0 +1,2 @@
System.Windows.Forms_ControlRenderer.exe: form1.cpp
cl /clr:pure /FeSystem.Windows.Forms_ControlRenderer.exe form1.cpp
@@ -0,0 +1,86 @@
#using <System.Windows.Forms.dll>
#using <System.dll>
#using <System.Drawing.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Collections;
//Create a Class that inherits from System.Windows.Forms.Form.
ref class myForm : public Form
{
public:
myForm()
{
InitializeComponent();
InitializeMenuTreeView();
}
//<snippet1>
// Declare the TreeView and ContextMenuStrip
private:
TreeView^ menuTreeView;
private:
System::Windows::Forms::ContextMenuStrip^ docMenu;
public:
void InitializeMenuTreeView()
{
// Create the TreeView.
menuTreeView = gcnew TreeView();
menuTreeView->Size = System::Drawing::Size(200, 200);
// Create the root node.
TreeNode^ docNode = gcnew TreeNode("Documents");
// Add some additional nodes.
docNode->Nodes->Add("phoneList.doc");
docNode->Nodes->Add("resume.doc");
// Add the root nodes to the TreeView.
menuTreeView->Nodes->Add(docNode);
// Create the ContextMenuStrip.
docMenu = gcnew System::Windows::Forms::ContextMenuStrip();
//Create some menu items.
ToolStripMenuItem^ openLabel = gcnew ToolStripMenuItem();
openLabel->Text = "Open";
ToolStripMenuItem^ deleteLabel = gcnew ToolStripMenuItem();
deleteLabel->Text = "Delete";
ToolStripMenuItem^ renameLabel = gcnew ToolStripMenuItem();
renameLabel->Text = "Rename";
//Add the menu items to the menu.
docMenu->Items->AddRange(gcnew array<ToolStripMenuItem^>{openLabel,
deleteLabel, renameLabel});
// Set the ContextMenuStrip property to the ContextMenuStrip.
docNode->ContextMenuStrip = docMenu;
// Add the TreeView to the form.
this->Controls->Add(menuTreeView);
}
//</snippet1>
private:
void InitializeComponent()
{
this->SuspendLayout();
//
// myForm
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 266);
this->Name = "myForm";
this->ResumeLayout(false);
}
};
[STAThreadAttribute]
int main()
{
Application::EnableVisualStyles();
Application::Run(gcnew myForm());
}
@@ -0,0 +1,2 @@
system.windows.forms.TreeNodeContextMenuStrip.exe: Form1.cpp
cl /clr:pure /Fesystem.windows.forms.TreeNodeContextMenuStrip.exe Form1.cpp
@@ -0,0 +1,28 @@
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
private:
public:
Form1()
{
TabPage^ tabPage1;
tabPage1 = gcnew TabPage;
// <snippet1>
tabPage1->Controls->Add(gcnew Button);
// </snippet1>
}
};
int main()
{
Application::Run( gcnew Form1 );
}
@@ -0,0 +1,61 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{267B4A3D-A09F-4067-A39A-F3BE7108AC65}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>AccessHTMLDOMControlCSharp</RootNamespace>
<AssemblyName>AccessHTMLDOMControlCSharp</AssemblyName>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>.\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>.\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="UserControl1.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UserControl1.Designer.cs">
<DependentUpon>UserControl1.cs</DependentUpon>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<EmbeddedResource Include="Configuration\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.cs</LastGenOutput>
</EmbeddedResource>
<Compile Include="Configuration\Resources.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Configuration\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.cs</LastGenOutput>
</None>
<Compile Include="Configuration\Settings.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>
@@ -0,0 +1,31 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AccessHTMLDOMControlCSharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MS")]
[assembly: AssemblyProduct("AccessHTMLDOMControlCSharp")]
[assembly: AssemblyCopyright("Copyright @ MS 2004")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
/// Setting ComVisible to false makes the types in this assembly not visible
/// to COM componenets. If you need to access a type in this assembly from
/// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
@@ -0,0 +1,70 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version:2.0.41021.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace AccessHTMLDOMControlCSharp.Configuration
{
using System;
using System.IO;
using System.Resources;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the Strongly Typed Resource Builder
// class via a tool like ResGen or Visual Studio.NET.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
class Resources
{
private static System.Resources.ResourceManager _resMgr;
private static System.Globalization.CultureInfo _resCulture;
/*FamANDAssem*/
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static System.Resources.ResourceManager ResourceManager
{
get
{
if ((_resMgr == null))
{
System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Resources", typeof(Resources).Assembly);
_resMgr = temp;
}
return _resMgr;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static System.Globalization.CultureInfo Culture
{
get
{
return _resCulture;
}
set
{
_resCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version:2.0.41021.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace AccessHTMLDOMControlCSharp.Configuration
{
public partial class Settings : System.Configuration.ApplicationSettingsBase
{
private static Settings m_Value;
private static object m_SyncObject = new object();
public static Settings Value
{
get
{
if ((Settings.m_Value == null))
{
System.Threading.Monitor.Enter(Settings.m_SyncObject);
if ((Settings.m_Value == null))
{
try
{
Settings.m_Value = new Settings();
}
finally
{
System.Threading.Monitor.Exit(Settings.m_SyncObject);
}
}
}
return Settings.m_Value;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,44 @@
namespace AccessHTMLDOMControlCSharp
{
partial class UserControl1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// UserControl1
//
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(435, 401);
this.Load += new System.EventHandler(this.UserControl1_Load);
this.ResumeLayout(false);
}
#endregion
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace AccessHTMLDOMControlCSharp
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
//<SNIPPET1>
HtmlDocument doc = null;
private void UserControl1_Load(object sender, EventArgs e)
{
if (this.Site != null)
{
doc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));
}
}
//</SNIPPET1>
}
}
@@ -0,0 +1,236 @@
//<Snippet1>
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text;
using System.IO;
namespace MyApplication
{
// A simple form that represents a window in our application
public class AppForm2 : System.Windows.Forms.Form
{
public AppForm2()
{
this.Size = new System.Drawing.Size(300, 300);
this.Text = "AppForm2";
}
}
// A simple form that represents a window in our application
public class AppForm1 : System.Windows.Forms.Form
{
public AppForm1()
{
this.Size = new System.Drawing.Size(300, 300);
this.Text = "AppForm1";
}
}
//<Snippet2>
// The class that handles the creation of the application windows
class MyApplicationContext : ApplicationContext
{
private int _formCount;
private AppForm1 _form1;
private AppForm2 _form2;
private Rectangle _form1Position;
private Rectangle _form2Position;
private FileStream _userData;
//<Snippet5>
private MyApplicationContext()
{
_formCount = 0;
// Handle the ApplicationExit event to know when the application is exiting.
Application.ApplicationExit += new EventHandler(this.OnApplicationExit);
try
{
// Create a file that the application will store user specific data in.
_userData = new FileStream(Application.UserAppDataPath + "\\appdata.txt", FileMode.OpenOrCreate);
}
catch (IOException e)
{
// Inform the user that an error occurred.
MessageBox.Show("An error occurred while attempting to show the application." +
"The error is:" + e.ToString());
// Exit the current thread instead of showing the windows.
ExitThread();
}
// Create both application forms and handle the Closed event
// to know when both forms are closed.
_form1 = new AppForm1();
_form1.Closed += new EventHandler(OnFormClosed);
_form1.Closing += new CancelEventHandler(OnFormClosing);
_formCount++;
_form2 = new AppForm2();
_form2.Closed += new EventHandler(OnFormClosed);
_form2.Closing += new CancelEventHandler(OnFormClosing);
_formCount++;
// Get the form positions based upon the user specific data.
if (ReadFormDataFromFile())
{
// If the data was read from the file, set the form
// positions manually.
_form1.StartPosition = FormStartPosition.Manual;
_form2.StartPosition = FormStartPosition.Manual;
_form1.Bounds = _form1Position;
_form2.Bounds = _form2Position;
}
// Show both forms.
_form1.Show();
_form2.Show();
}
private void OnApplicationExit(object sender, EventArgs e)
{
// When the application is exiting, write the application data to the
// user file and close it.
WriteFormDataToFile();
try
{
// Ignore any errors that might occur while closing the file handle.
_userData.Close();
}
catch { }
}
//</Snippet5>
private void OnFormClosing(object sender, CancelEventArgs e)
{
// When a form is closing, remember the form position so it
// can be saved in the user data file.
if (sender is AppForm1)
_form1Position = ((Form)sender).Bounds;
else if (sender is AppForm2)
_form2Position = ((Form)sender).Bounds;
}
//<Snippet3>
private void OnFormClosed(object sender, EventArgs e)
{
// When a form is closed, decrement the count of open forms.
// When the count gets to 0, exit the app by calling
// ExitThread().
_formCount--;
if (_formCount == 0)
{
ExitThread();
}
}
//</Snippet3>
private bool WriteFormDataToFile()
{
// Write the form positions to the file.
UTF8Encoding encoding = new UTF8Encoding();
RectangleConverter rectConv = new RectangleConverter();
string form1pos = rectConv.ConvertToString(_form1Position);
string form2pos = rectConv.ConvertToString(_form2Position);
byte[] dataToWrite = encoding.GetBytes("~" + form1pos + "~" + form2pos);
try
{
// Set the write position to the start of the file and write
_userData.Seek(0, SeekOrigin.Begin);
_userData.Write(dataToWrite, 0, dataToWrite.Length);
_userData.Flush();
_userData.SetLength(dataToWrite.Length);
return true;
}
catch
{
// An error occurred while attempting to write, return false.
return false;
}
}
private bool ReadFormDataFromFile()
{
// Read the form positions from the file.
UTF8Encoding encoding = new UTF8Encoding();
string data;
if (_userData.Length != 0)
{
byte[] dataToRead = new byte[_userData.Length];
try
{
// Set the read position to the start of the file and read.
_userData.Seek(0, SeekOrigin.Begin);
_userData.Read(dataToRead, 0, dataToRead.Length);
}
catch (IOException e)
{
string errorInfo = e.ToString();
// An error occurred while attempt to read, return false.
return false;
}
// Parse out the data to get the window rectangles
data = encoding.GetString(dataToRead);
try
{
// Convert the string data to rectangles
RectangleConverter rectConv = new RectangleConverter();
string form1pos = data.Substring(1, data.IndexOf("~", 1) - 1);
_form1Position = (Rectangle)rectConv.ConvertFromString(form1pos);
string form2pos = data.Substring(data.IndexOf("~", 1) + 1);
_form2Position = (Rectangle)rectConv.ConvertFromString(form2pos);
return true;
}
catch
{
// Error occurred while attempting to convert the rectangle data.
// Return false to use default values.
return false;
}
}
else
{
// No data in the file, return false to use default values.
return false;
}
}
//<Snippet4>
[STAThread]
static void Main(string[] args)
{
// Create the MyApplicationContext, that derives from ApplicationContext,
// that manages when the application should exit.
MyApplicationContext context = new MyApplicationContext();
// Run the application with the specific context. It will exit when
// all forms are closed.
Application.Run(context);
}
//</Snippet4>
}
//</Snippet2>
}
//</Snippet1>
@@ -0,0 +1,75 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{37FC2D7B-9F35-4D66-8CD2-C76F7E242552}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ApplicationSettingsArchitectureCS</RootNamespace>
<AssemblyName>ApplicationSettingsArchitectureCS</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DummyClass.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,44 @@
//<SNIPPET1>
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
namespace ApplicationSettingsArchitectureCS
{
[SettingsProvider("SqlSettingsProvider")]
class CustomSettings : ApplicationSettingsBase
{
// Implementation goes here.
}
}
//</SNIPPET1>
namespace ApplicationSettingsArchitectureCS
{
public abstract class DummySettingsBase
{
public abstract string ApplicationName
{
get;
set;
}
}
public class DummySettings : DummySettingsBase
{
//<SNIPPET2>
public override string ApplicationName
{
get
{
return (System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
}
set
{
// Do nothing.
}
}
//</SNIPPET2>
}
}
@@ -0,0 +1,39 @@
namespace ApplicationSettingsArchitectureCS
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}
#endregion
}
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ApplicationSettingsArchitectureCS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ApplicationSettingsArchitectureCS
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ApplicationSettingsArchitectureCS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ApplicationSettingsArchitectureCS")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2005")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("36af196a-a168-42a6-a697-3ae9594bb79b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ApplicationSettingsArchitectureCS.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ApplicationSettingsArchitectureCS.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ApplicationSettingsArchitectureCS.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,79 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5C6D141F-0E63-486F-AEB3-E6766F89B6CB}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AppSettingsArchitectureProject</RootNamespace>
<AssemblyName>AppSettingsArchitectureProject</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="MyAppSettings.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<SubType>Designer</SubType>
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,87 @@
namespace AppSettingsArchitectureProject
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(72, 61);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1});
this.statusStrip1.Location = new System.Drawing.Point(0, 251);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(292, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(109, 17);
this.toolStripStatusLabel1.Text = "toolStripStatusLabel1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
}
}
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AppSettingsArchitectureProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}
//<SNIPPET3>
//Make sure to hook up this event handler in the constructor!
//this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
mus.Save();
}
//</SNIPPET3>
private void button1_Click(object sender, EventArgs e)
{
mus.BackgroundColor = Color.Black;
}
//<SNIPPET2>
MyUserSettings mus;
private void Form1_Load(object sender, EventArgs e)
{
mus = new MyUserSettings();
mus.BackgroundColor = Color.AliceBlue;
this.DataBindings.Add(new Binding("BackColor", mus, "BackgroundColor"));
}
//</SNIPPET2>
}
}
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
@@ -0,0 +1,22 @@
//<SNIPPET1>
using System;
using System.Configuration;
using System.Drawing;
public class MyUserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[DefaultSettingValue("white")]
public Color BackgroundColor
{
get
{
return ((Color)this["BackgroundColor"]);
}
set
{
this["BackgroundColor"] = (Color)value;
}
}
}
//</SNIPPET1>
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace AppSettingsArchitectureProject
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AppSettingsArchitectureProject")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("AppSettingsArchitectureProject")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2005")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("37cc6737-2577-424e-b0c9-b1b02d9c6333")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AppSettingsArchitectureProject.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AppSettingsArchitectureProject.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.42
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AppSettingsArchitectureProject.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,58 @@
namespace DisplayWebBrowserCode
{
partial class CodeForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(776, 651);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// CodeForm
//
this.ClientSize = new System.Drawing.Size(776, 651);
this.Controls.Add(this.richTextBox1);
this.Name = "CodeForm";
this.Text = "HTML Source Code Window";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DisplayWebBrowserCode
{
partial class CodeForm : Form
{
public CodeForm()
{
InitializeComponent();
}
//<SNIPPET1>
public string Code
{
get
{
if (richTextBox1.Text != null)
{
return (richTextBox1.Text);
}
else
{
return ("");
}
}
set
{
richTextBox1.Text = value;
}
}
//</SNIPPET1>
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,76 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.41025</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A1758485-65E5-4E5D-B57A-50F9B2838D3D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>DisplayWebBrowserCode</RootNamespace>
<AssemblyName>DisplayWebBrowserCode</AssemblyName>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CodeForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CodeForm.Designer.cs">
<DependentUpon>CodeForm.cs</DependentUpon>
</Compile>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="CodeForm.resx">
<DependentUpon>CodeForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.cs</LastGenOutput>
</EmbeddedResource>
<Compile Include="Properties\Resources.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>
@@ -0,0 +1,67 @@
namespace DisplayWebBrowserCode
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// webBrowser1
//
this.webBrowser1.Location = new System.Drawing.Point(12, 250);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(744, 382);
this.webBrowser1.Url = new System.Uri("http://www.msn.com/");
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(768, 644);
this.Controls.Add(this.button1);
this.Controls.Add(this.webBrowser1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.Button button1;
}
}
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace DisplayWebBrowserCode
{
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//<SNIPPET2>
private void button1_Click(object sender, EventArgs e)
{
HtmlElement elem;
if (webBrowser1.Document != null)
{
CodeForm cf = new CodeForm();
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("HTML");
if (elems.Count == 1)
{
elem = elems[0];
cf.Code = elem.OuterHtml;
cf.Show();
}
}
}
//</SNIPPET2>
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace DisplayWebBrowserCode
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DisplayWebBrowserCode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MS")]
[assembly: AssemblyProduct("DisplayWebBrowserCode")]
[assembly: AssemblyCopyright("Copyright @ MS 2004")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6b24619b-1c02-4b9b-a282-7aaa133b26a9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,70 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version:2.0.41025.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace DisplayWebBrowserCode.Properties
{
using System;
using System.IO;
using System.Resources;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the Strongly Typed Resource Builder
// class via a tool like ResGen or Visual Studio.NET.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
class Resources
{
private static System.Resources.ResourceManager _resMgr;
private static System.Globalization.CultureInfo _resCulture;
/*FamANDAssem*/
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static System.Resources.ResourceManager ResourceManager
{
get
{
if ((_resMgr == null))
{
System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Resources", typeof(Resources).Assembly);
_resMgr = temp;
}
return _resMgr;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static System.Globalization.CultureInfo Culture
{
get
{
return _resCulture;
}
set
{
_resCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version:2.0.41025.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
namespace DisplayWebBrowserCode.Properties
{
public partial class Settings : System.Configuration.ApplicationSettingsBase
{
private static Settings m_Value;
private static object m_SyncObject = new object();
public static Settings Value
{
get
{
if ((Settings.m_Value == null))
{
System.Threading.Monitor.Enter(Settings.m_SyncObject);
if ((Settings.m_Value == null))
{
try
{
Settings.m_Value = new Settings();
}
finally
{
System.Threading.Monitor.Exit(Settings.m_SyncObject);
}
}
}
return Settings.m_Value;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='iso-8859-1'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,324 @@
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml;
using System.Data;
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
public class LinesCurvesAndShapes : Form
{
// 0195df81-66be-452d-bb53-5a582ebfdc09
// Vector Graphics Overview
Pen myPen = Pens.Black;
SolidBrush mySolidBrush = (SolidBrush)Brushes.Red;
GraphicsPath myGraphicsPath = new GraphicsPath();
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new LinesCurvesAndShapes());
}
public void Method11(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet11>
myGraphics.DrawRectangle(myPen, 20, 10, 100, 50);
// </snippet11>
}
// 08d2cc9a-dc9d-4eed-bcbb-2c8e2ca5d3ae
// Open and Closed Curves in GDI+
public void Method21(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet21>
myGraphics.FillPie(mySolidBrush, 0, 0, 140, 70, 0, 120);
myGraphics.DrawArc(myPen, 0, 0, 140, 70, 0, 120);
// </snippet21>
}
public void Method22(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet22>
Point[] myPointArray =
{
new Point(0, 0),
new Point(60, 20),
new Point(40, 50)
};
myGraphics.DrawClosedCurve(myPen, myPointArray);
myGraphics.FillClosedCurve(mySolidBrush, myPointArray);
// </snippet22>
}
public void Method23(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet23>
SolidBrush mySolidBrush = new SolidBrush(Color.Aqua);
GraphicsPath myGraphicsPath = new GraphicsPath();
Point[] myPointArray =
{
new Point(15, 20),
new Point(20, 40),
new Point(50, 30)
};
FontFamily myFontFamily = new FontFamily("Times New Roman");
PointF myPointF = new PointF(50, 20);
StringFormat myStringFormat = new StringFormat();
myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
myGraphicsPath.AddCurve(myPointArray);
myGraphicsPath.AddString("a string in a path", myFontFamily,
0, 24, myPointF, myStringFormat);
myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
myGraphics.FillPath(mySolidBrush, myGraphicsPath);
myGraphics.DrawPath(myPen, myGraphicsPath);
// </snippet23>
}
// 09b3797a-6294-422d-9adf-a5a0a7695c0c
// Cardinal Splines in GDI+
public void Method31(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
Point[] myPointArray =
{
new Point(10, 10),
new Point(50, 40),
new Point(123, 200)
};
// <snippet31>
myGraphics.DrawCurve(myPen, myPointArray, 1.5f);
// </snippet31>
}
// 30b25aae-e3eb-4479-bdb8-187cf651fc84
// Pens, Lines, and Rectangles in GDI+
public void Method41(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet41>
myGraphics.DrawLine(myPen, 4, 2, 12, 6);
// </snippet41>
}
public void Method42(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet42>
Point myStartPoint = new Point(4, 2);
Point myEndPoint = new Point(12, 6);
myGraphics.DrawLine(myPen, myStartPoint, myEndPoint);
// </snippet42>
}
public void Method43(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet43>
Pen myPen = new Pen(Color.Blue, 2);
myGraphics.DrawLine(myPen, 0, 0, 60, 30);
// </snippet43>
}
public void Method44(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet44>
myPen.DashStyle = DashStyle.Dash;
myGraphics.DrawLine(myPen, 100, 50, 300, 80);
// </snippet44>
}
public void Method45(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet45>
myGraphics.DrawRectangle(myPen, 100, 50, 80, 40);
// </snippet45>
}
public void Method46(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet46>
Rectangle myRectangle = new Rectangle(100, 50, 80, 40);
myGraphics.DrawRectangle(myPen, myRectangle);
// </snippet46>
}
// 34f35133-a835-4ca4-81f6-0dfedee8b683
// Ellipses and Arcs in GDI+
public void Method51(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet51>
myGraphics.DrawEllipse(myPen, 100, 50, 80, 40);
// </snippet51>
}
public void Method52(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet52>
Rectangle myRectangle = new Rectangle(100, 50, 80, 40);
myGraphics.DrawEllipse(myPen, myRectangle);
// </snippet52>
}
public void Method53(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet53>
myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180);
// </snippet53>
}
// 52184f9b-16dd-4bbd-85be-029112644ceb
// Regions in GDI+
public void Method61(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
Region myRegion = new Region(this.ClientRectangle);
// <snippet61>
myGraphics.FillRegion(mySolidBrush, myRegion);
// </snippet61>
}
// 5774ce1e-87d4-4bc7-88c4-4862052781b8
// Bézier Splines in GDI+
public void Method71(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet71>
myGraphics.DrawBezier(myPen, 0, 0, 40, 20, 80, 150, 100, 10);
// </snippet71>
}
// 810da1a4-c136-4abf-88df-68e49efdd8d4
// Antialiasing with Lines and Curves
public void Method81(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet81>
myGraphics.SmoothingMode = SmoothingMode.AntiAlias;
myGraphics.DrawLine(myPen, 0, 0, 12, 8);
// </snippet81>
}
// 8b5f71d9-d2f0-4540-9c41-740f90fd4c26
// Restricting the Drawing Surface in GDI+
public void Method91(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
Region myRegion = new Region(this.ClientRectangle);
// <snippet91>
myGraphics.Clip = myRegion;
myGraphics.DrawLine(myPen, 0, 0, 200, 200);
// </snippet91>
}
// a5500dec-666c-41fd-9da3-2169dd89c5eb
// Graphics Paths in GDI+
public void Method101(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet101>
myGraphicsPath.AddLine(0, 0, 30, 20);
myGraphicsPath.AddEllipse(20, 20, 20, 40);
myGraphicsPath.AddBezier(30, 60, 70, 60, 50, 30, 100, 10);
myGraphics.DrawPath(myPen, myGraphicsPath);
// </snippet101>
}
public void Method102()
{
GraphicsPath graphicsPath1 = new GraphicsPath();
GraphicsPath graphicsPath2 = new GraphicsPath();
// <snippet102>
myGraphicsPath.AddPath(graphicsPath1, false);
myGraphicsPath.AddPath(graphicsPath2, false);
// </snippet102>
}
public void Method103(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet103>
GraphicsPath myGraphicsPath = new GraphicsPath();
Point[] myPointArray =
{
new Point(5, 30),
new Point(20, 40),
new Point(50, 30)
};
FontFamily myFontFamily = new FontFamily("Times New Roman");
PointF myPointF = new PointF(50, 20);
StringFormat myStringFormat = new StringFormat();
myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
myGraphicsPath.StartFigure();
myGraphicsPath.AddCurve(myPointArray);
myGraphicsPath.AddString("a string in a path", myFontFamily,
0, 24, myPointF, myStringFormat);
myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
myGraphics.DrawPath(myPen, myGraphicsPath);
// </snippet103>
}
// a72213d2-d69a-4c2b-a75c-be7b20390c13
// Polygons in GDI+
public void Method111(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet111>
Point[] myPointArray =
{
new Point(0, 0),
new Point(50, 30),
new Point(30, 60)
};
myGraphics.DrawPolygon(myPen, myPointArray);
// </snippet111>
}
// e863e2a7-0294-4130-99b6-f1ea3201e7cd
// Brushes and Filled Shapes in GDI+
public void Method121(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet121>
SolidBrush mySolidBrush = new SolidBrush(Color.Red);
myGraphics.FillEllipse(mySolidBrush, 0, 0, 60, 40);
// </snippet121>
}
public void Method122()
{
// <snippet122>
HatchBrush myHatchBrush =
new HatchBrush(HatchStyle.Vertical, Color.Blue, Color.Green);
// </snippet122>
}
public void Method123(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
// <snippet123>
Image myImage = Image.FromFile("MyTexture.bmp");
TextureBrush myTextureBrush = new TextureBrush(myImage);
myGraphics.FillEllipse(myTextureBrush, 0, 0, 100, 50);
// </snippet123>
}
public void Method124(PaintEventArgs e)
{
Graphics myGraphics = e.Graphics;
Rectangle myRectangle = new Rectangle(new Point(10, 10), new Size(40, 50));
// <snippet124>
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(
myRectangle,
Color.Blue,
Color.Green,
LinearGradientMode.Horizontal);
myGraphics.FillEllipse(myLinearGradientBrush, myRectangle);
// </snippet124>
}
}
@@ -0,0 +1,61 @@
namespace ManagedDOMStyles
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.SuspendLayout();
//
// webBrowser1
//
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point(0, 0);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(742, 318);
this.webBrowser1.Url = new System.Uri("c:\\userfiles\\jayallen\\ManagedDOMStyles\\test.htm", System.UriKind.Absolute);
this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(742, 318);
this.Controls.Add(this.webBrowser1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.WebBrowser webBrowser1;
}
}
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Permissions;
namespace ManagedDOMStyles
{
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
//<SNIPPET2>
StyleGenerator sg = null;
HtmlElement elem = null;
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
sg = new StyleGenerator();
webBrowser1.Document.MouseOver += new HtmlElementEventHandler(Document_MouseOver);
webBrowser1.Document.MouseLeave += new HtmlElementEventHandler(Document_MouseLeave);
}
void Document_MouseOver(object sender, HtmlElementEventArgs e)
{
elem = webBrowser1.Document.GetElementFromPoint(e.MousePosition);
if (elem.TagName.Equals("DIV"))
{
sg.ParseStyleString(elem.Style);
sg.SetStyle("font-style", "italic");
elem.Style = sg.GetStyleString();
}
}
void Document_MouseLeave(object sender, HtmlElementEventArgs e)
{
if (elem != null)
{
sg.RemoveStyle("font-style");
elem.Style = sg.GetStyleString();
// Reset, since we may mouse over a new DIV element next time.
sg.Clear();
}
}
//</SNIPPET2>
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,71 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50304</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6531B7A2-E512-4AC0-A5BF-4A41259FE13D}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ManagedDOMStyles</RootNamespace>
<AssemblyName>ManagedDOMStyles</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="StyleGenerator.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ManagedDOMStyles
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ManagedDOMStyles")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MS")]
[assembly: AssemblyProduct("ManagedDOMStyles")]
[assembly: AssemblyCopyright("Copyright © MS 2005")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("401692d3-2767-47ab-a9d5-9213495a5054")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Some files were not shown because too many files have changed in this diff Show More