Page 1 of 1

Displaying my own form with 2 inputs

PostPosted: Thu Apr 03, 2025 5:35 pm
by DannyC
I'm just fiddling and experimenting with getting a dialog to display that shows 2 textboxes as inputs.
Sort of like InputBox but with 2 fields for the user to enter.

In Visual Studio I've whipped up a very simple Windows Form with 2 inputs and 2 buttons. Only 1 button actually does anything - the cancel button closes the form.
It works fine in VS, but when I copy the form code to a Jiwa plugin nothing happens. No form displays at all.

At the moment, I am triggering the form to display just by a custom button in the sales order ribbon but that I think is inconsequential i.e. its just something I can control & fire as and when I want.
So when I click my button, it's like there is no code at all behind it.

I've ran the debugger and the plugin isn't executing my custom form code but I don't know why.
I'm sure it's something simple I've missed.

Re: Displaying my own form with 2 inputs

PostPosted: Thu Apr 03, 2025 5:40 pm
by Mike.Sheen
DannyC wrote:I'm just fiddling and experimenting with getting a dialog to display that shows 2 textboxes as inputs.
Sort of like InputBox but with 2 fields for the user to enter.

In Visual Studio I've whipped up a very simple Windows Form with 2 inputs and 2 buttons. Only 1 button actually does anything - the cancel button closes the form.
It works fine in VS, but when I copy the form code to a Jiwa plugin nothing happens. No form displays at all.

At the moment, I am triggering the form to display just by a custom button in the sales order ribbon but that I think is inconsequential i.e. its just something I can control & fire as and when I want.
So when I click my button, it's like there is no code at all behind it.

I've ran the debugger and the plugin isn't executing my custom form code but I don't know why.
I'm sure it's something simple I've missed.


You're not showing the form. You create a new instance of it, but don't show it:

Code: Select all
if (e.Tool.Key == "DC")
{
    //System.Diagnostics.Debugger.Launch();
    InputForm myform = new InputForm();
}


You want to also call myform.ShowDialog(); and if you want to specify the sales order form as the owner, pass that as the owner to ShowDialog : myform.ShowDialog(salesOrderForm);

Re: Displaying my own form with 2 inputs

PostPosted: Thu Apr 03, 2025 6:04 pm
by DannyC
You want to also call myform.ShowDialog();


OK. I did actually try
Code: Select all
myform.Show();
but that didn't work.

Re: Displaying my own form with 2 inputs  Topic is solved

PostPosted: Thu Apr 03, 2025 6:19 pm
by Mike.Sheen
DannyC wrote:
You want to also call myform.ShowDialog();


OK. I did actually try
Code: Select all
myform.Show();
but that didn't work.


But not ShowDialog.

You've either not tried ShowDialog or you did, but if you did you would have discovered that your InputForm class does not have a ShowDialog method available - which should have then led you to the realisation that your InputForm is the wrong type - you've declared it as System.Windows.Forms.ContainerControl instead of System.Windows.Forms.Form.

Change your class declaration from this:
Code: Select all
partial class InputForm : System.Windows.Forms.ContainerControl

To this:
Code: Select all
partial class InputForm : System.Windows.Forms.Form


And then Show and ShowDialog will work - specifically I'd go with:
Code: Select all
myform.ShowDialog(salesOrderForm);


And then you've got your next set of problems which will be evident when you do that - that the form is empty:
DC InputForm.png
DC InputForm.png (66.34 KiB) Viewed 10685 times

Re: Displaying my own form with 2 inputs

PostPosted: Thu Apr 03, 2025 10:04 pm
by DannyC
And then you've got your next set of problems which will be evident when you do that - that the form is empty:


:( Oh well, at least if I can get the form to display then I can suss out what the issue is with the controls.

EDIT: Worked it out. I needed the code block
Code: Select all
        public InputForm()
        {
            InitializeComponent();
        }


The cancel button onClick code was wrong too. I've fixed that up so at least I have a very simple modal form displaying two input textboxes.
I'm pretty happy with that.

Onwards with getting it to actually do something useful...

Appreciate the help as always Mike.

Re: Displaying my own form with 2 inputs

PostPosted: Fri Apr 04, 2025 8:30 am
by SBarnes
You may find it easier to actually create a winforms project in Visual Studio and desgin your form, make sure it's on .net 471, then all you need to do is copy the code including the designer code over into a plugin, all the layout of the code is done for you

For example

datereset.jpg
datereset.jpg (15.09 KiB) Viewed 10680 times


Ends up with code like this, whilst this uses the Infragistics controls, which you need a license for, you can use the standard Microsft controls just as easily.

Code: Select all
namespace JiwaFinancials.Jiwa.DateReset
{
   
   public static class DateResetter
   {
      public static DateTime? ChangeDate(DateTime? input)
      {
         DateTime output = input.HasValue ? input.Value : DateTime.Now;
         frmDateReset form = new frmDateReset();
         form.DTValue = output;
         if (form.ShowDialog() == DialogResult.OK)
         {
            output = form.DTValue;
            return output;
         }
         return input;
      }
   }
   
   partial class frmDateReset : Form
    {
        /// <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);
        }
      
      
      
      public DateTime DTValue { get; set; }   
        public frmDateReset()
        {
            InitializeComponent();
         DTValue = DateTime.Now;
         this.StartPosition = FormStartPosition.CenterScreen;
        }

        public void SetDTValue()
        {

            DTValue = new DateTime(udteDate.DateTime.Year, udteDate.DateTime.Month, udteDate.DateTime.Day, udteTime.DateTime.Hour, udteTime.DateTime.Minute, udteTime.DateTime.Second);
        }

        private void ubOk_Click(object sender, EventArgs e)
        {
            SetDTValue();
            Close();
        }

        private void ubCancel_Click(object sender, EventArgs e)
        {
            SetDTValue();
            Close();
        }

        private void frmDateReset_Shown(object sender, EventArgs e)
        {
            udteDate.DateTime = DTValue;
            udteTime.DateTime = DTValue;
        }      
      

        #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.ultraPanel1 = new Infragistics.Win.Misc.UltraPanel();
            this.ubCancel = new Infragistics.Win.Misc.UltraButton();
            this.ubOk = new Infragistics.Win.Misc.UltraButton();
            this.udteDate = new Infragistics.Win.UltraWinEditors.UltraDateTimeEditor();
            this.udteTime = new Infragistics.Win.UltraWinEditors.UltraDateTimeEditor();
            this.ultraPanel1.ClientArea.SuspendLayout();
            this.ultraPanel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.udteDate)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.udteTime)).BeginInit();
            this.SuspendLayout();
            //
            // ultraPanel1
            //
            //
            // ultraPanel1.ClientArea
            //
            this.ultraPanel1.ClientArea.Controls.Add(this.udteTime);
            this.ultraPanel1.ClientArea.Controls.Add(this.ubCancel);
            this.ultraPanel1.ClientArea.Controls.Add(this.ubOk);
            this.ultraPanel1.ClientArea.Controls.Add(this.udteDate);
            this.ultraPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ultraPanel1.Location = new System.Drawing.Point(0, 0);
            this.ultraPanel1.Name = "ultraPanel1";
            this.ultraPanel1.Size = new System.Drawing.Size(308, 95);
            this.ultraPanel1.TabIndex = 0;
            //
            // ubCancel
            //
            this.ubCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.ubCancel.Location = new System.Drawing.Point(198, 51);
            this.ubCancel.Name = "ubCancel";
            this.ubCancel.Size = new System.Drawing.Size(75, 23);
            this.ubCancel.TabIndex = 2;
            this.ubCancel.Text = "Cancel";
            this.ubCancel.Click += new System.EventHandler(this.ubCancel_Click);
            //
            // ubOk
            //
            this.ubOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.ubOk.Location = new System.Drawing.Point(108, 51);
            this.ubOk.Name = "ubOk";
            this.ubOk.Size = new System.Drawing.Size(75, 23);
            this.ubOk.TabIndex = 1;
            this.ubOk.Text = "Ok";
            this.ubOk.Click += new System.EventHandler(this.ubOk_Click);
            //
            // udteDate
            //
            this.udteDate.Location = new System.Drawing.Point(26, 12);
            this.udteDate.MaskClipMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw;
            this.udteDate.MaskInput = "dd/mm/yyyy";
            this.udteDate.Name = "udteDate";
            this.udteDate.Size = new System.Drawing.Size(114, 21);
            this.udteDate.TabIndex = 0;
            //
            // udteTime
            //
            this.udteTime.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never;
            this.udteTime.Location = new System.Drawing.Point(146, 12);
            this.udteTime.MaskClipMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw;
            this.udteTime.MaskInput = "{time}";
            this.udteTime.Name = "udteTime";
            this.udteTime.Size = new System.Drawing.Size(127, 21);
            this.udteTime.SpinButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always;
            this.udteTime.TabIndex = 3;
            //
            // frmDateReset
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(308, 95);
            this.Controls.Add(this.ultraPanel1);
            this.Name = "frmDateReset";
            this.Text = "Date Reset";
            this.Shown += new System.EventHandler(this.frmDateReset_Shown);
            this.ultraPanel1.ClientArea.ResumeLayout(false);
            this.ultraPanel1.ClientArea.PerformLayout();
            this.ultraPanel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.udteDate)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.udteTime)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        public Infragistics.Win.Misc.UltraPanel ultraPanel1;
        public Infragistics.Win.UltraWinEditors.UltraDateTimeEditor udteDate;
        public Infragistics.Win.Misc.UltraButton ubCancel;
        public Infragistics.Win.Misc.UltraButton ubOk;
        public Infragistics.Win.UltraWinEditors.UltraDateTimeEditor udteTime;
    }
}


Re: Displaying my own form with 2 inputs

PostPosted: Fri Apr 04, 2025 11:33 am
by DannyC
You may find it easier to actually create a winforms project in Visual Studio and desgin your form


That's exactly what I did.