65.9K
CodeProject is changing. Read more.
Home

Dymo Labelwriter Class

starIconstarIconemptyStarIconemptyStarIconemptyStarIcon

2.00/5 (1 vote)

May 28, 2024

CPOL

1 min read

viewsIcon

4650

downloadIcon

98

A simple class for controlling Dymo label printers in Dymo.zip

Introduction

After a lot of searching, we figured out how to control a Dymo label printer. For this we have created a class that should work on almost every Dymo.

Background

For printing barcodes and price labels. Use NuGet to install the appropriate libraries in your project. Search for Dymo in Nuget.

Using the code

The class contains some methods of which public void Initialize() is the starting point of the class where any printers are found and the printer is called.

After starting the dialog, put in the beginning of the class of your window:

        DymoPrinters myDymoPrinters;
        string tmpLabelXml;
        IDymoLabel tmpLabel;

After this, put the following lines in the form_load routine of your main form:

        myDymoPrinters = new DymoPrinters();
        myDymoPrinters.Initialize();

And load the printers connected:

   foreach (IPrinter item in myDymoPrinters.DymoPrinterList)
   {
       LabelWriterCmb.Items.Add(item.Name);
   }
   if (LabelWriterCmb.Items.Count > 0)
   {
       LabelWriterCmb.SelectedIndex = 0;
   }
   else
   {
       MessageBox.Show("Geen Dymo labelwriter gevonden");
       Close();
       return;
   }

Create a clickable button with the following lines:

       private void PrintLabelBtn_Click(object sender, EventArgs e)
       {
           PrintLabelBtn_Click1(sender, e, LabelWriterCmb);
       }

Label over = Labels left
Label unknown
Aantal kopieën = copys left

Something like the above button prints out data

The routine which prints to the printer

        private async void PrintLabelBtn_Click1(object sender, EventArgs e, ComboBox labelWriterCmb)
        string strLokatie, strProduct, strPrijs, strBarcode, xmlstring = String.Empty;

        strLokatie = "Login PC vestiging noord";
        strProduct = "Willekeurig product";
        strPrijs = "Prijs € 999,98";
        strBarcode = "8054392616440";

                string tmpLabelXML = myDymoPrinters.LoadLabelXml("Product.label");

The variables you have named in the label creator program of Dymo in the fields as is in the example Produk.zip

Fill in the variables

                xmlstring = tmpLabelXML;
                
                xmlstring = xmlstring.Replace("xmlstringLokatie", strLokatie);
                xmlstring = xmlstring.Replace("xmlstringProductnaam", strProduct);
                xmlstring = xmlstring.Replace("xmlstringPrijs", strPrijs);
                xmlstring = xmlstring.Replace("123456789", strBarcode);

See the added label with the names of the fields on Dymo label program (Produk.zip).

Initialize the print of the product label.

               tmpLabel = myDymoPrinters.MakeLabelFromXml(xmlstring);

               aantal = (int)numericUpDown.Value;

And print on the right label printer, even if multiple label writers are connected

                var tmp1  = await myDymoPrinters.GetRemainingLabels(labelWriterCmb.Text);
                
                if (tmp1 != null)
                {
                    remaining.Text = tmp1.ToString();
                
                
                    myDymoPrinters.PrintLabel(tmpLabel, labelWriterCmb.Text, aantal);

                    var tmpi = await DymoPrinter.Instance.GetRollStatusInPrinter(labelWriterCmb.Text);

                    rollstatus = string.Empty;
                    labelsremaining = 0;
                    labelname = string.Empty    ;

                    if (tmpi != null)
                    {
                        rollstatus = tmpi.RollStatus.ToString();
                        labelsremaining = Convert.ToInt32(tmpi.LabelsRemaining);
                        labelname = tmpi.Name;
                        
                        if (labelsremaining < 6)
                        {
                            remaining.ForeColor = Color.Red;
                        }
                        Labelstatus.Text = rollstatus;
                        LabelNaam.Text = labelname;
                        remaining.Text = labelsremaining.ToString();
                    }
                }
                    
            }

        public string rollstatus { get; set; } // only 550 printer
        public int labelsremaining { get; set; }
        public string labelname { get; set; }

Points of Interest

It took me several hours to write this. I am not a manual writer, but I hope it is clear for those who want to operate a Dymo label printer. Make sure you have the correct DLL in the bin directory.

History

This is the first version if there are further extensions such as Dymo's combo