Displaying my own form with 2 inputs  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Displaying my own form with 2 inputs

Postby DannyC » Thu Apr 03, 2025 5:35 pm

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.
Attachments
Plugin Messagbox with 2 inputs.xml
(34.79 KiB) Downloaded 576 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Displaying my own form with 2 inputs

Postby Mike.Sheen » Thu Apr 03, 2025 5:40 pm

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);
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Displaying my own form with 2 inputs

Postby DannyC » Thu Apr 03, 2025 6:04 pm

You want to also call myform.ShowDialog();


OK. I did actually try
Code: Select all
myform.Show();
but that didn't work.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

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

Postby Mike.Sheen » Thu Apr 03, 2025 6:19 pm

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 10683 times
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Displaying my own form with 2 inputs

Postby DannyC » Thu Apr 03, 2025 10:04 pm

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.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Displaying my own form with 2 inputs

Postby SBarnes » Fri Apr 04, 2025 8:30 am

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 10678 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;
    }
}

Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: Displaying my own form with 2 inputs

Postby DannyC » Fri Apr 04, 2025 11:33 am

You may find it easier to actually create a winforms project in Visual Studio and desgin your form


That's exactly what I did.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests