/// <summary>
        /// Clears the expression in the textbox
        /// </summary>
        private void btnClear_Click(object sender, EventArgs e)
        {
            if (richTextBox1.Text.ToLower() == "<no expression>")
            {
                if (MessageBox.Show("Remove labels?", LegendControl.Legend.AppName,
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    MapWinGIS.Labels lb = m_shapefile.Labels;
                    for (int i = 0; i < lb.Count; i++)
                    {
                        for (int j = 0; j < lb.get_NumParts(i); j++)
                        {
                            lb.get_Label(i, j).Text = "";
                        }
                    }

                    listBox1.Enabled     = true;
                    btnPlus.Enabled      = true;
                    btnQuotes.Enabled    = true;
                    btnNewLine.Enabled   = true;
                    richTextBox1.Enabled = true;
                    richTextBox1.Text    = "";

                    lb.SavingMode   = tkSavingMode.modeXMLOverwrite;
                    lb.Synchronized = true;
                    if (!lb.Synchronized)
                    {
                        lb.Clear();
                    }
                }
            }
            else
            {
                richTextBox1.Text = "";
            }
        }
        /// <summary>
        /// Generates labels with specified positions
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            // callback and wait cursor
            ICallback cBackOld = m_shapefile.GlobalCallback;
            Callback  cback    = new Callback();

            m_shapefile.GlobalCallback = cback;
            this.Enabled = false;
            this.Cursor  = Cursors.WaitCursor;

            MapWinGIS.Labels   lb          = m_shapefile.Labels;
            tkLabelPositioning positioning = get_LabelPositioning();

            lb.LineOrientation = (tkLineLabelOrientation)cboLineOrientation.SelectedIndex;

            try
            {
                // generation
                m_shapefile.GenerateLabels(-1, positioning, !chkLabelEveryPart.Checked);
                m_shapefile.Labels.SavingMode = tkSavingMode.modeXMLOverwrite;  // .lbl file should be updated

                ShpfileType type = Globals.ShapefileType2D(m_shapefile.ShapefileType);
                if (type == ShpfileType.SHP_POINT || type == ShpfileType.SHP_MULTIPOINT)
                {
                    if (optAlignBottomCenter.Checked)
                    {
                        m_alignment = tkLabelAlignment.laBottomCenter;
                    }
                    if (optAlignBottomLeft.Checked)
                    {
                        m_alignment = tkLabelAlignment.laBottomLeft;
                    }
                    if (optAlignBottomRight.Checked)
                    {
                        m_alignment = tkLabelAlignment.laBottomRight;
                    }
                    if (optAlignCenter.Checked)
                    {
                        m_alignment = tkLabelAlignment.laCenter;
                    }
                    if (optAlignCenterLeft.Checked)
                    {
                        m_alignment = tkLabelAlignment.laCenterLeft;
                    }
                    if (optAlignCenterRight.Checked)
                    {
                        m_alignment = tkLabelAlignment.laCenterRight;
                    }
                    if (optAlignTopCenter.Checked)
                    {
                        m_alignment = tkLabelAlignment.laTopCenter;
                    }
                    if (optAlignTopLeft.Checked)
                    {
                        m_alignment = tkLabelAlignment.laTopLeft;
                    }
                    if (optAlignTopRight.Checked)
                    {
                        m_alignment = tkLabelAlignment.laTopRight;
                    }
                }

                // updating references to categories
                if (lb.NumCategories > 0)
                {
                    for (int i = 0; i < lb.Count; i++)
                    {
                        MapWinGIS.Label label = lb.get_Label(i, 0);
                        label.Category = m_shapefile.get_ShapeCategory(i);
                    }
                }
            }
            finally
            {
                this.Enabled = true;
                this.Cursor  = Cursors.Default;
                cback.Clear();
                m_shapefile.GlobalCallback = cBackOld;
            }
        }