コード例 #1
0
        //Main Function
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graph = e.Graphics;
            float TranslateX = 0.0f;
            float TranslateY = 0.0f;

            //System.Diagnostics.Debug.WriteLine(string.Format("width {0}, height {1}", this.Size.Width, this.Size.Height));
            if (useWhiteBackground)
            {
                Graph.FillRectangle(Brushes.White, 0, 0, this.Size.Width, this.Size.Height); //Color label white
            }
            else
            {
                HatchBrush bb = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.LightGray, Color.White);
                Graph.FillRectangle(bb /*Brushes.White*/, 0, 0, this.Size.Width, this.Size.Height); //Color label white
                bb.Dispose();
            }
            //Graph.DrawRectangle(new Pen(Brushes.CadetBlue), 0, 0, this.Size.Width, this.Size.Height); //showit, edge filling...
            //mve,1.3.2
            Matrix mat = new Matrix();

            mat.Scale(zoomFactor, zoomFactor, MatrixOrder.Append);
            Graph.Transform = mat;
            if (rotation != 0)
            {
                Graph.RotateTransform(rotation, MatrixOrder.Append);
                if (rotation > 0)
                {
                    TranslateX = 0.0f;// -Size.Width / 2;
                    TranslateY = -Size.Width / zoomFactor;
                }
                else
                {
                    TranslateX = -Size.Height / zoomFactor;
                    TranslateY = 0.0f;
                }
                Graph.TranslateTransform(TranslateX, TranslateY);
            }
            mat.Dispose();
            mat = Graph.Transform;
            Boolean isSelectedField = false;

            foreach (LabelDef.Field field in drawingreferenceList.Values) //Draw each element in drawingreferenceList
            {
                field.BaseTransformation = mat;
                //mve,1.3.2
                Graph.ResetTransform(); //Al drawing routines can perform transforms. Reset here to start fresh.
                //if (zoomFactor != 1.0f)
                //{
                Graph.Transform = mat;
                //    if (rotation != 0)
                //    {
                //        Graph.RotateTransform(rotation, MatrixOrder.Append);
                //        Graph.TranslateTransform(TranslateX, TranslateY);
                //    }
                //}
                //*
                if (field.ID.Equals(selectedFieldId))
                {
                    isSelectedField = true;
                }
                else
                {
                    isSelectedField = false;
                }
                if (field is LabelDef.TextFieldGroup)
                {
                    LabelDef.TextFieldGroup textfieldgroup = (LabelDef.TextFieldGroup)field;
                    returnRectangle = textfieldgroup.Draw(Graph, new System.Drawing.Point(0, 0), labelset, 1043, isSelectedField);
                }
                else if (field is LabelDef.TextField)
                {
                    LabelDef.TextField          textfield    = (LabelDef.TextField)field;
                    System.Drawing.StringFormat stringFormat = new System.Drawing.StringFormat(StringFormatFlags.NoWrap);
                    if (textfield.printFormat == null)
                    {
                        stringFormat.Alignment = StringAlignment.Near;
                    }
                    else
                    {
                        stringFormat.Alignment = textfield.printFormat.format.GetAsStringAlignment();
                    }
                    returnRectangle = textfield.Draw(Graph, new System.Drawing.Point(0, 0), labelset, 1043, isSelectedField);
                }
                else if (field is LabelDef.ImageField)
                {
                    LabelDef.ImageField imagefield = (LabelDef.ImageField)field;
                    returnRectangle = imagefield.Draw(Graph, new System.Drawing.Point(0, 0), labelset, 1043, isSelectedField);
                }
                else if (field is LabelDef.BarcodeField)
                {
                    LabelDef.BarcodeField barcodefield = (LabelDef.BarcodeField)field;
                    returnRectangle = barcodefield.Draw(Graph, new System.Drawing.Point(0, 0), labelset, 1043, isSelectedField);
                }

                /* System.Diagnostics.Debug.WriteLine(
                 *       string.Format("{6}: Returnrectangle: {0},{1} -> {2},{3}  Contains? {4},{5} ?",
                 *                       returnRectangle.X,
                 *                       returnRectangle.Y,
                 *                       returnRectangle.Right,
                 *                       returnRectangle.Bottom,
                 *                       selectX, selectY,
                 *                       field.ID.ToString()
                 *                    )
                 *     );*/
                if (detectedClickToSelect)
                {
                    if (returnRectangle.Contains(new System.Drawing.Point(selectX, selectY)))
                    {
                        fieldIDToSelect       = field.ID;
                        detectedClickToSelect = false;
                    }
                }
            }
            detectedClickToSelect = false;
            mat.Dispose();
        }
コード例 #2
0
ファイル: AddBarcodeForm.cs プロジェクト: nekoprog/LabelPrint
        //Main Function
        private void Okbtn_Click(object sender, EventArgs e)
        {
            try
            {
                barcodefield           = new LabelDef.BarcodeField(new ACA.LabelX.Tools.CoordinateSystem(200, 200, GetString("MILLIMETER")));
                barcodefield.ID        = IDtxt.Text;
                barcodefield.PositionX = new Length(System.Convert.ToInt32(XPostxt.Text), System.Drawing.GraphicsUnit.Millimeter);
                barcodefield.PositionY = new Length(System.Convert.ToInt32(YPostxt.Text), System.Drawing.GraphicsUnit.Millimeter);
                barcodefield.Rotation  = System.Convert.ToInt32(rotationcombo.SelectedItem.ToString());
                barcodefield.Height    = new Length(System.Convert.ToInt32(heighttxt.Text), System.Drawing.GraphicsUnit.Millimeter);
                barcodefield.Width     = new Length(System.Convert.ToInt32(widthtxt.Text), System.Drawing.GraphicsUnit.Millimeter);

                LabelDef.StringFormat stringformat = new LabelDef.StringFormat(true);
                if (alignTextcombo.SelectedItem.ToString().Equals(GetString("LEFT"), StringComparison.OrdinalIgnoreCase))
                {
                    stringformat.Align = LabelDef.FieldFormat.Alignment.Left;
                }
                else if (alignTextcombo.SelectedItem.ToString().Equals(GetString("RIGHT"), StringComparison.OrdinalIgnoreCase))
                {
                    stringformat.Align = LabelDef.FieldFormat.Alignment.Right;
                }

                string barcodetype = typecombo.SelectedItem.ToString();
                switch (barcodetype)
                {
                case "EAN8":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.EAN8;
                    break;

                case "EAN13":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.EAN13;
                    break;

                case "UPCVersionA":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.UPCVersionA;
                    break;

                case "Code39":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.Code39;
                    break;

                case "Interleaved2Of5":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.Interleaved2Of5;
                    break;

                case "EAN128":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.EAN128;
                    break;

                case "DataMatrix":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.DataMatrix;
                    break;

                case "PDF417":
                    barcodefield.Type = LabelDef.BarcodeField.BarcodeType.PDF417;
                    break;
                }

                barcodefield.MaxCharCount = System.Convert.ToInt32(maxcharcounttxt.Text);
                barcodefield.printText    = showtextcheck.Checked;
                barcodefield.printFormat  = new LabelDef.PrintFormat(stringformat);

                if (referencecombo.SelectedItem.ToString().Equals(GetString("NOTHING")))
                {
                    barcodefield.ValueRef = null;
                }
                else
                {
                    barcodefield.ValueRef = referencecombo.SelectedItem.ToString();
                }

                DialogResult = DialogResult.OK;
                this.Close();
            }
            catch
            {
                MessageBox.Show(GetString("INVALIDINPUTERROR"), GetString("INVALIDINPUTERRORTITLE"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }