Form component like common Openfiledialog

G

Guest

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 box. I now
want to create dialog that can be dragged from the toolbox onto my form,
similar to the common dialogs. So far everything I've tried is just not
turning up in the toolbox.

What should I start with as a base class and what do I need to implement to
get the same functionality as a common dialog when it is dragged onto a form
in the designer?

Thanks
Dave
 
A

Atul

If you want the toolbox item to be placed in the "Component Tray Area" at
the bottom of the forms designer, you should inherit your class from
Component instead of UserControl.

- Atul
Sky Software http://www.ssware.com/
Drop-In Windows Explorer-Like Shell Browsing UI for your apps.
 
G

Guest

Hi Atul

I kind of noticed that class, but cant make the leap to get from inheriting
Component to having a fully functioning form? How do I create a form with a
Component base class?

Thanks
Dave
 
G

Guest

Hi Atul

As I said at the top of all this, I'am a newbie to this .net stuff. Aslo,
I've not really done interface programming to the extent of creating a
replacement form class. Is there somewhere on the net you can think of that
gives an example of how to do this? I don't have a clue where to start
creating a class that inherits from Component and has methods that display a
form. I tried creating a form in the designer and then changed the parect
class from Form to Compnent, which failed to compile almost completely. I
really need to see an example so I can get the idea, but so far, I haven't
been able to find one anywhere.

Thanks
Dave
 
G

Guest

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
 
T

Tim Wilson

The basic idea, at least what I would recommend, is to create a new class
that inherits from the CommonDialog class. This would put your custom dialog
inline with the built in dialogs in the framework since they inherit,
directly or indirectly, from this class. The benefit to you as well is that
you can build a form as you normally would, and then just create an instance
of this form and show it from the custom CommonDialog class. I've included
an example below. In order to use the example you should first create a
"Windows Control Library". In the UserControl1.cs file delete everything and
paste the code for the CustomDialog class, shown below with a (1) at the
top. Next, add a new Windows Form to the "Windows Control Library" project,
delete all the code, and paste the code for the Dialog class, shown below
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
}
}

**********************************************
 
G

Guest

Hi Tim

Sorry, but it took a while to get here.

If I copy and paste that into a C# project it all works fine. I'm actually
trying to write this in MC++. I've converted both the commondialog and the
form to MC++ which all compiles fine, but when I put the library in the
toolbox, there is no common dialog imported. Not sure if this is a MC++
pecularity or if I've done something wrong, but I definetly have a class
derived from CommonDialog. Any idea if there is a difference in MC++, or what
could be screw up to not have the control turn up in the toolbox?

Thanks
Dave


Tim Wilson said:
The basic idea, at least what I would recommend, is to create a new class
that inherits from the CommonDialog class. This would put your custom dialog
inline with the built in dialogs in the framework since they inherit,
directly or indirectly, from this class. The benefit to you as well is that
you can build a form as you normally would, and then just create an instance
of this form and show it from the custom CommonDialog class. I've included
an example below. In order to use the example you should first create a
"Windows Control Library". In the UserControl1.cs file delete everything and
paste the code for the CustomDialog class, shown below with a (1) at the
top. Next, add a new Windows Form to the "Windows Control Library" project,
delete all the code, and paste the code for the Dialog class, shown below
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

DiamondDave said:
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
 
T

Tim Wilson

I'm not sure. I wouldn't think that there would be a difference in how you
add items to the ToolBox in the MC++ world since this should all be
controlled through Visual Studio. But, since I don't work in MC++, I can't
say for sure. You said that it adds fine to the ToolBox if you build it
through C#? If that's the case then you should be able to leave it coded in
C#. It'll all work together at runtime.

--
Tim Wilson
..Net Compact Framework MVP

DiamondDave said:
Hi Tim

Sorry, but it took a while to get here.

If I copy and paste that into a C# project it all works fine. I'm actually
trying to write this in MC++. I've converted both the commondialog and the
form to MC++ which all compiles fine, but when I put the library in the
toolbox, there is no common dialog imported. Not sure if this is a MC++
pecularity or if I've done something wrong, but I definetly have a class
derived from CommonDialog. Any idea if there is a difference in MC++, or what
could be screw up to not have the control turn up in the toolbox?

Thanks
Dave


Tim Wilson said:
The basic idea, at least what I would recommend, is to create a new class
that inherits from the CommonDialog class. This would put your custom dialog
inline with the built in dialogs in the framework since they inherit,
directly or indirectly, from this class. The benefit to you as well is that
you can build a form as you normally would, and then just create an instance
of this form and show it from the custom CommonDialog class. I've included
an example below. In order to use the example you should first create a
"Windows Control Library". In the UserControl1.cs file delete everything and
paste the code for the CustomDialog class, shown below with a (1) at the
top. Next, add a new Windows Form to the "Windows Control Library" project,
delete all the code, and paste the code for the Dialog class, shown
below
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

DiamondDave said:
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
box.
I
now
want to create dialog that can be dragged from the toolbox onto my form,
similar to the common dialogs. So far everything I've tried is
just
not
turning up in the toolbox.

What should I start with as a base class and what do I need to implement
to
get the same functionality as a common dialog when it is dragged
onto
a
form
in the designer?

Thanks
Dave
 
G

Guest

Hi Tim

After some thought for the past couple of days, I've decided to "bite the
bullet" and learn C#. There seems to be so much more info around on C3 and
most of the examples in MSDN are in C# or VB. I found it quite difficult when
there was no examples in C++. I'm guessing at the moment that C#'s interface
to .Net is a lot clearer and streamlined compared to C++, particularily to
2003 version with __gc classes etc.

I've just gone out and bought a couple of book and will now spend some time
reading, but was wondering if you came from a C++ background, or you know any
people who have, is it easier to learn C#? I'm really hoping so...

Thanks for all your help.
Dave


Tim Wilson said:
I'm not sure. I wouldn't think that there would be a difference in how you
add items to the ToolBox in the MC++ world since this should all be
controlled through Visual Studio. But, since I don't work in MC++, I can't
say for sure. You said that it adds fine to the ToolBox if you build it
through C#? If that's the case then you should be able to leave it coded in
C#. It'll all work together at runtime.

--
Tim Wilson
..Net Compact Framework MVP

DiamondDave said:
Hi Tim

Sorry, but it took a while to get here.

If I copy and paste that into a C# project it all works fine. I'm actually
trying to write this in MC++. I've converted both the commondialog and the
form to MC++ which all compiles fine, but when I put the library in the
toolbox, there is no common dialog imported. Not sure if this is a MC++
pecularity or if I've done something wrong, but I definetly have a class
derived from CommonDialog. Any idea if there is a difference in MC++, or what
could be screw up to not have the control turn up in the toolbox?

Thanks
Dave


Tim Wilson said:
The basic idea, at least what I would recommend, is to create a new class
that inherits from the CommonDialog class. This would put your custom dialog
inline with the built in dialogs in the framework since they inherit,
directly or indirectly, from this class. The benefit to you as well is that
you can build a form as you normally would, and then just create an instance
of this form and show it from the custom CommonDialog class. I've included
an example below. In order to use the example you should first create a
"Windows Control Library". In the UserControl1.cs file delete everything and
paste the code for the CustomDialog class, shown below with a (1) at the
top. Next, add a new Windows Form to the "Windows Control Library" project,
delete all the code, and paste the code for the Dialog class, shown
below
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
 
T

Tim Wilson

I came from a C++ and VB background. I found C# incredibly easy to learn.
The combination of less types to remember and garbage collection, amongst
other things, made C# a very attractive language, and with a background in
VB it made developing with components, a designer, a properties window, and
a simple event system easy to pick up as well. It almost seems like C++ and
VB have been slammed together, between the syntax and the designer
experience, to form C#. Since you already know the syntax coming from a C++
background, I assume that you're also proficient in object oriented
programming, the real challenge is to try to wrap your head around the new
base class libraries (BCL) so that you know what's available from a managed
API standpoint. The goal is to only p/invoke (call to native dlls directly)
when you have to. My recommendation is to focus on the BCL. Once you're
familiar with that, learning a new language to use with it, whether it's C#
or VB.Net, seems almost trivial. So if you're comfortable with the BCL and
OOP already, you'll pick up C# in no time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top