Rashed Amini

The ara3n weblog

Dynamics NAV Addin Example Large Button

11th December 2009

Here is another example on how to create custom buttons in NAV and control events when they are pressed. In this example I’m actually using the WinForm Button controls and displaying them on a panel. When the button are pressed Nav code is triggered and you can add your own custom logic in it.

Here is a screenshot below. As you can see, there are two button with different sizes and colors and when you press then a nav message is displayed that you pressed it.

Button Screenshot Addin

The code for CreateControl is as follows


protected override Control CreateControl()
{

Button button1 = new Button();
button1.Location = new System.Drawing.Point(39, 25);
button1.Name = "button1";
button1.Size = new System.Drawing.Size(75, 23);
button1.TabIndex = 0;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
button1.Click += new System.EventHandler(button1_Click);

Button button2 = new Button();
button2.Location = new System.Drawing.Point(59, 55);
button2.Name = "Largebutton2";
button2.Size = new System.Drawing.Size(175, 123);
button2.TabIndex = 0;
button2.Text = "Largebutton2";
button2.BackColor = System.Drawing.Color.Tomato;
button2.UseVisualStyleBackColor = true;
button2.Click += new System.EventHandler(button2_Click);

Panel buttonpanel = new Panel();
buttonpanel.Controls.Add(button1);
buttonpanel.Controls.Add(button2);
buttonpanel.Location = new System.Drawing.Point(12, 12);
buttonpanel.Name = "outlookGroupBox1";
buttonpanel.Padding = new System.Windows.Forms.Padding(4, 22, 4, 4);
buttonpanel.Size = new System.Drawing.Size(376, 219);
buttonpanel.TabIndex = 0;
buttonpanel.Text = "Many Buttons";

return buttonpanel;
}

Here is the Visual Studio Project Source

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word