A reusable control add-in button

CaponeCapone Member Posts: 125
edited 2014-06-10 in NAV Three Tier
Hi!

I'm trying to create a resuable ControlAddIn button on pages. A button which I can reuse and set name and size dynamicaly

I managed to create it and with proper methods to do this. However, the problem I'm struggling with is to set the properties of the add-in at the startup of the page.

According to this http://msdn.microsoft.com/en-us/library/hh168173(v=nav.70).aspx I can't set this properties in the trigger OnInit, OnOpenPage and OnNewRecord because the control is not instantiated which is was of my points with this reusable add-in.

I have also tried the trigger OnAfterGetRecord but the same result.

One thought was to create static properties and methods that could set these values before instansiation but that failed since static members can't be shown in the symbol menu(?).

A workaround is to hide the Controls on the page and then show the with an action that changes the properties at the same time.

Does anyone have a better suggestion of a workaround or solution?
Hello IT, have you tried to turn it off and on?
Have you checked the cables?
Have you released the filters?

http://www.navfreak.com

Answers

  • CaponeCapone Member Posts: 125
    Solved it! \:D/

    I realised that I could do a callback to NAV from the CreateControl method and in NAV set the properties.

    Visual Studio Code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.Dynamics.Framework.UI.Extensibility;
    using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
    using System.Windows.Forms;
    using System.Drawing;
    
    
    namespace DynamicButton
    {
        [ControlAddInExport("DynamicButtonAddin")]
        public class DynamicButton : WinFormsControlAddInBase, IEventControlAddInDefinition
        {
            Int32 Width, Height, LocationX, LocationY;
            String ButtonText;
            Button button1;
    
            protected override Control CreateControl()
            {
                ButtonText = "Button";
                Width = 75;
                Height = 23;
                button1 = new Button();
                button1.Location = new System.Drawing.Point(LocationX, LocationY);
                button1.Name = "Button01";
                button1.Size = new System.Drawing.Size(Width, Height);
                button1.TabIndex = 0;
                button1.Text = ButtonText;
                button1.UseVisualStyleBackColor = true;
                button1.Click += new System.EventHandler(button1_Click);
                ControlAddIn(0, "");
                return button1;
            }
    
            void button1_Click(object sender, System.EventArgs e)
            {
    
                ControlAddIn(1, "");
            }
    
            public event ControlAddInEventHandler ControlAddIn;
    
            [ApplicationVisible]
            public void SetButtonText(String Text)
            { 
                ButtonText = Text;
                button1.Text = ButtonText;
            }
    
            [ApplicationVisible]
            public void SetButtonSize(Int32 w, Int32 h)
            {
                this.ApplySize(new DisplaySize(w,w,w),new DisplaySize(h,h,h));         
            }
                   
        }
    }
    

    Code in Control trigger in NAV:
    TestCTRL - OnControlAddIn(Index : Integer;Data : Text)
    IF Index = 0 THEN BEGIN
      CurrPage.TestCTRL.SetButtonSize(100,100);
      CurrPage.TestCTRL.SetButtonText('Dynamic Text');
    END;
    
    IF Index = 1 THEN
      ;//Do Something
    
    Hello IT, have you tried to turn it off and on?
    Have you checked the cables?
    Have you released the filters?

    http://www.navfreak.com
  • mdPartnerNLmdPartnerNL Member Posts: 802
    nice, and thx, not sure how you would use this :)
  • CaponeCapone Member Posts: 125
    How about touchscreen friendly interface? :)

    Think of it as a button control you can place on a page.
    Also, instead of creating a button addin to every button you need I wanted to create a general one which you can reuse.
    Hello IT, have you tried to turn it off and on?
    Have you checked the cables?
    Have you released the filters?

    http://www.navfreak.com
Sign In or Register to comment.