Re: Form component like common Openfiledialog

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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" wrote:

> 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" <DiamondDave@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:E485D429-7815-488F-81B2-4D28A8B49EC7@xxxxxxxxxxxxxxxx
> > 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
> >
> >
> > "Tim Wilson" wrote:
> >
> > > Does the following information help?
> > >
> > > "Extend the Common Dialog Boxes Using Windows Forms 1.x"
> > >
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/extensibledialogs.asp
> > >
> > > --
> > > Tim Wilson
> > > ..Net Compact Framework MVP
> > >
> > > "DiamondDave" <DiamondDave@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > > news:3596791A-C2D3-4245-B47C-2655E5F11B9F@xxxxxxxxxxxxxxxx
> > > > 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
> > > >
> > >
> > >
> > >
>
>
>
.



Relevant Pages

  • Re: AVID vs Final Cut Pro
    ... especially when they are custom built. ... all that fun stuff that goes with Windows. ... Pro, Live Type, Compressor, DVD Studio Pro, Motion and Soundtrack Pro. ... With Macs you can only really buy quality products (although there have been ...
    (rec.video.production)
  • Re: Openserver 5.0.6 ping floods router
    ... the CPU Load jumped back up to 100%. ... We finally discovered somehowthat if we disconnected a certain windows 2003 Server that had an ip addreee of XXX.XXX.XXX.97 the flooding stopped. ... remember the IP for the default gateway between reboots. ... I had run a "custom -V" to verify the entire setup, ...
    (comp.unix.sco.misc)
  • Re: can TS be used for restricted access to 1 application
    ... It sounds like I would need to go with Windows 2008 TS. ... with the start-up options for earlier versions of Terminal Services, ... be allowed to run a specific (custom made .NET) program/application. ... All version of TS have the ability to run applications directly as a ...
    (microsoft.public.windows.terminal_services)
  • Re: Windows Explorer NoNetCrawling
    ... You can create a custom .ADM that won't tattoo the registry by following: ... Windows Platform Support Team ...
    (microsoft.public.win2000.group_policy)
  • Re: Overcoming CommandButton autorepeat flaw for record navigation
    ... I may adapt that somewhat for my purposes with the custom ... Private mlngVirtualLeft As Long ... Private mlngTimerIntervalAs Long ... Private Sub DetectState ...
    (comp.databases.ms-access)