I need help creating a CtrlAddIn for Dynamics NAV using C#
I am quite new to matrix and c#, i am using WinForm and VisualStudio to create a DLL.
Here is part of the code:
region Fonctions pilotées depuis Dynamics
// Tout effacer
[ApplicationVisible]
public void CleanPanel()
{
MainPanel.Controls.Clear(); //Tous les elements seront effacés
}
// Gestion des rôles
[ApplicationVisible]
public void AjouterRole(string NameL, string idRoleL, int posRoleL)
{
TextBox tb = new TextBox();
//Random random = new Random();
ToolTip TTL = new ToolTip();
String TooltipL;
//int randRed = random.Next(1, 255);
//int randGreen = random.Next(1, 255);
//int randBlue = random.Next(1, 255);
//tb.BackColor = Color.FromArgb(randRed, randGreen, randBlue);
tb.BackColor = Color.Bisque;
tb.Name = idRoleL;
//si le texte est plus grand, je mets ...
tb.Text = NameL;
if (tb.TextLength > 7)
{
string nameO = NameL.Substring(0, 7);
string points = "...";
tb.Text = string.Concat(nameO + points);
}
else
{
tb.Text = NameL;
}
tb.AllowDrop = true; //pour le drag and drop
tb.Multiline = true;//pour pouvoir avoir des textboxes de taille differente
tb.ScrollBars = ScrollBars.None; //pour enlever les scrollbars dans tout les textboxes
tb.HideSelection = true;//pour ne pas avoir le focus dans le precedent textbox
tb.Size = new Size(70, 60);
tb.Left = posRoleL * 70;
tb.Visible = true;
tb.Cursor = Cursors.Hand;
//wrap pour que le texte n'aille pas a la ligne et tooltip pour voir le text
TooltipL = NameL;
tb.WordWrap = false;
TTL.SetToolTip(tb, TooltipL);
//evenement pour le DRAG AND DROP
//1 Je gere le drag pour pouvoir le bouger
tb.MouseDown += (senderL, eL) => tb.DoDragDrop(tb.Text, DragDropEffects.Move);
tb.DragEnter += (senderL, eL) => { eL.Effect = DragDropEffects.Move; };
//EventControlAddin(3, idRoleL.PadRight(10) + ";" + (string)posRoleL.ToString());
//2 Je gere le drop pour pouvoir bouger le controle
tb.DragDrop += (senderL, eL) => { tb.Text = eL.Data.GetData(DataFormats.Text).ToString(); EventControlAddin(3, idRoleL.PadRight(10) + ";" + (string)posRoleL.ToString()); };
//evenement pour pouvoir supprimer un role
tb.MouseEnter += IlumineRole;
tb.MouseLeave += Eteint;
//evenement pour modifier le role
tb.DoubleClick += (senderL, eL) => EventControlAddin(6, tb.Name);
MainPanel.Controls.Add(tb);
}
[ApplicationVisible]
public void AjouterTotalRole(string NameL, string idRoleL, int posRoleL, string dureeL, string coutL)
{
// Textbox
TextBox tb = new TextBox();
tb.Name = idRoleL;
tb.Text = NameL;
int indexMaxRoles = 99;//somme de toutes les lignes + 1
// Je dois mettre un tooltip pour comprendre
ToolTip TTL = new ToolTip();
String TooltipLCout = "Totaux des rôles en durée et en coût.";
//Panel contenant les labels
Panel pn = new Panel();
pn.Size = new Size(70, 60);
pn.BackColor = Color.Azure;
pn.BorderStyle = BorderStyle.FixedSingle;
pn.Left = posRoleL * 70;
pn.Top = indexMaxRoles + 1; //Il faut qu'il soit a la casse finale
Label lb_Duree = new Label();
lb_Duree.Text = "Durée:" + dureeL;
//lb_Duree.Width = 60;
Label lb_Cout = new Label();
lb_Cout.Text = "Coût:" + coutL;
//lb_Cout.Width = 60;
lb_Cout.Top = 20;
TTL.SetToolTip(pn, TooltipLCout);
pn.Controls.Add(lb_Duree);
pn.Controls.Add(lb_Cout);
MainPanel.Controls.Add(pn);
}
I need to add the total of the rows and columns as TotalRoles and TotalOperations, and i need to pass to dynamics the lastposition of my textboxes in horizontal and vertical, + 1 for getting the right position. How can i do this? Any help most welcome. Thanks