with a (2) at the top. Build this project and resolve any errors that may
arise due to the text wrapping in this post. Next, add a "Windows
Application" project to the same solution as the "Windows Control Library"
created earlier. This project will be used to test the custom dialog. With
the form displayed for the "Windows Application" project, add the custom
dialog to the TooBox by right-clicking in the ToolBox and selecting
"Add/Remove Items...", then clicking "Browse...", then navigate to the
output (assembly) of the "Windows Control Library" project (probably named
"WindowsControlLibrary1.dll"), then say "Open", then "OK", and now the
custom dialog should be in the ToolBox. To use it, drag and drop it onto the
form and you should notice it in the component tray at the bottom. To
display it, just call it's ShowDialog method just as you would for any of
the common dialogs.
**********************************************
(1)
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace MyNamespace.Windows.Forms
{
public class CustomDialog : System.Windows.Forms.CommonDialog
{
private string _StringValue = null;
[DefaultValue(null)]
public string StringValue
{
get
{
return _StringValue;
}
set
{
_StringValue = value;
}
}
public CustomDialog() {}
protected override bool RunDialog(IntPtr hWndOwner)
{
Dialog dialogInstance = null;
bool okTriggered = false;
try
{
dialogInstance = new Dialog();
dialogInstance.Owner = (Form.FromHandle(hWndOwner) as Form);
dialogInstance.textBox1.Text = this.StringValue;
if (dialogInstance.ShowDialog() == DialogResult.OK)
{
okTriggered = true;
this.StringValue = dialogInstance.textBox1.Text;
}
}
finally
{
if (dialogInstance != null)
{
dialogInstance.Dispose();
}
}
return okTriggered;
}
public override void Reset()
{
this.StringValue = null;
}
}
}
**********************************************
(2)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace MyNamespace.Windows.Forms
{
/// <summary>
/// Summary description for Dialog.
/// </summary>
internal class Dialog : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
public System.Windows.Forms.TextBox textBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Dialog()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (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.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button1.Location = new System.Drawing.Point(264, 104);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "OK";
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(360, 104);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Cancel";
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(232, 16);
this.label1.TabIndex = 2;
this.label1.Text = "Enter a string:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(32, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(384, 20);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// Dialog
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(456, 149);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Dialog";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Custom Dialog";
this.TopMost = true;
this.ResumeLayout(false);
}
#endregion
}
}
**********************************************
--
Tim Wilson
..Net Compact Framework MVP
Hi Tim
No, not quite what I was after. Basically, I want to create a form of my
own
that can be put in the toolbox and draged onto forms using the designer.
Because it is a complete form, rather than a collection of controls, it
apparently needs to inherit from Component, not Form. I don't know how to
make a form from Component?
Thanks
Dave
:
Does the following information help?
"Extend the Common Dialog Boxes Using Windows Forms 1.x"
http://msdn.microsoft.com/library/d...y/en-us/dnwinforms/html/extensibledialogs.asp
--
Tim Wilson
..Net Compact Framework MVP
Hi there
Sorry for the newbie question, but I've searched the net and MSDN and
I
can't find anything on how to do this. Any pointers to doco or advice
will
be
appreciated.
I have created a Windows Control Library in MC++ and added a couple of
User
Controls. This is fine and I'm able to select them from the tool