Example #1
0
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphics = null;

            if (e != null)
            {
                graphics = e.Graphics;
            }
            else
            {
                graphics = panel1.CreateGraphics();
            }
            graphics.Clear(Color.White);
            Invalidate();
            Size sz    = panel1.ClientSize;
            Size oldSz = panel2.ClientSize;

            Dictionary <string, object> mapCoordinatesNameTemp = new Dictionary <string, object>();
            bool  isError = false;
            float deltaX  = (float)sz.Width / (float)oldSz.Width;

            deltaX = CommonFunction.roundValue(deltaX);
            float deltaY = (float)sz.Height / (float)oldSz.Height;

            deltaY = CommonFunction.roundValue(deltaY);
            try
            {
                List <LabelBean> labelBeans = CommonFunction.getListLabel();
                float            nameY      = 0;
                foreach (LabelBean labelBean in labelBeans)
                {
                    if (labelBean.Text.Equals(""))
                    {
                        continue;
                    }
                    float width  = sz.Width;
                    float height = sz.Height;


                    width  *= deltaX;
                    height *= deltaY;

                    drawRectangleAsNameMenu(graphics, labelBean.Text, 0, (int)nameY, (int)width, (int)height,
                                            Color.Black, Color.Black, Color.White, 0, labelBean.Col);

                    int[] positions = CommonFunction.getValuesAsPair(labelBean.Position);
                    float x         = positions[0];
                    float y         = positions[1];
                    y *= deltaY;
                    mapCoordinatesNameTemp.Add(nameY + "", x + labelBean.Col * colMarginDefault + ", " + y);
                    nameY += heightLabelNameDefault;
                }
            }
            catch (Exception ex)
            {
                isError = true;
            }

            if (mapCoordinatesNameTemp.Count > 0 && isError == false)
            {
                mapCoordinatesName = mapCoordinatesNameTemp;
            }

            if (curY != -1)
            {
                string    coordinateLabelBean = (string)mapCoordinatesName[curY + ""];
                LabelBean curLabelBean        = (LabelBean)mapCoordinatesChair[coordinateLabelBean];
                float     width  = deltaX * (float)oldSz.Width;
                float     height = deltaY * heightLabelNameDefault;
                drawRectangleAsNameMenu(graphics, curLabelBean.Text, 0, (int)curY, (int)width, (int)height,
                                        Color.Black, Color.Black, Color.FromArgb(255, 239, 213), 0, curLabelBean.Col);
            }
        }
Example #2
0
        private void displayPosition(Graphics graphics, Dictionary <string, object> datas, int x, int y, bool isClick, Size sz, Size oldSz)
        {
            //Size sz = pictureBox1.ClientSize;
            //Size oldSz = pictureBox2.ClientSize;

            LabelBean lbChoose = null;
            int       nameY    = 0;
            float     xPos     = 0;
            float     yPos     = 0;
            float     width    = 0;
            float     height   = 0;
            float     deltaX   = (float)sz.Width / (float)oldSz.Width;

            deltaX = CommonFunction.roundValue(deltaX);
            float deltaY = (float)sz.Height / (float)oldSz.Height;

            deltaY = CommonFunction.roundValue(deltaY);
            string position  = "0, 0";
            string size      = "0, 0";
            int    col       = 0;
            bool   drawChair = false;

            foreach (var data in datas)
            {
                string    dataKey   = data.Key;
                LabelBean labelBean = null;
                if (data.Value is LabelBean)
                {
                    labelBean = (LabelBean)data.Value;
                    drawChair = true;
                    position  = labelBean.Position;
                    size      = labelBean.Size;
                    col       = labelBean.Col;
                }
                else if (data.Value is string)
                {
                    string coordinateLabelBean = (string)data.Value;
                    labelBean = (LabelBean)mapCoordinatesChair[coordinateLabelBean];
                    position  = "0, " + dataKey;
                    size      = oldSz.Width + ", " + heightLabelNameDefault;
                    deltaY    = 1;
                }

                if (labelBean == null)
                {
                    return;
                }

                int[] positions = CommonFunction.getValuesAsPair(labelBean.Position);
                xPos = positions[0];
                yPos = positions[1];
                int[] sizes = CommonFunction.getValuesAsPair(labelBean.Size);
                width  = sizes[0];
                height = sizes[1];

                xPos   *= deltaX;
                xPos   += (col * colMarginDefault) * deltaX;
                yPos   *= deltaY;
                width  *= deltaX;
                height *= deltaY;

                //check current pointer is belong to label
                bool isOut = checkPointerIsOutLabels(x, y, deltaX, deltaY, position, size, col);
                if (isOut == true)
                {
                    if (drawChair == true)
                    {
                        drawRectangleAsChair(graphics, labelBean.Text, (int)xPos, (int)yPos, (int)width, (int)height, labelBean.TextCorlor, Color.Black,
                                             labelBean.BackgroundCorlor, labelBean.Rotate, labelBean.Col);
                    }
                    else
                    {
                        width   = deltaX * (float)oldSz.Width;
                        height *= deltaY * (float)oldSz.Height;
                        drawRectangleAsNameMenu(graphics, labelBean.Text, 0, int.Parse(dataKey), (int)width, (int)height,
                                                Color.Black, Color.Black, Color.White, 0, labelBean.Col);
                    }

                    continue;
                }
                if (drawChair == false)
                {
                    nameY = int.Parse(dataKey);
                    curY  = nameY;
                }
                lbChoose = labelBean;
            }

            if (drawChair == false)
            {
                width  = deltaX * (float)oldSz.Width;
                height = deltaY * heightLabelNameDefault;
                drawRectangleAsNameMenu(graphics, lbChoose.Text, 0, nameY, (int)width, (int)height,
                                        Color.Black, Color.Black, Color.FromArgb(255, 239, 213), 0, 0);

                return;
            }

            if (lbChoose != null)
            {
                int[] positions = CommonFunction.getValuesAsPair(lbChoose.Position);
                xPos = positions[0];
                yPos = positions[1];
                int[] sizes = CommonFunction.getValuesAsPair(lbChoose.Size);
                width  = sizes[0];
                height = sizes[1];

                xPos   *= deltaX;
                xPos   += (lbChoose.Col * colMarginDefault) * deltaX;
                yPos   *= deltaY;
                width  *= deltaX;
                height *= deltaY;

                if (isClick == true)
                {
                    //case: label pointer was choosen => do nothing
                    Color borderColor = Color.Black;
                    if (lbChoose == curLabelBean)
                    {
                        curLabelBean = null;
                    }
                    else
                    {
                        //case: label pointer different than label pointer was choosen => do something
                        borderColor  = Color.Red;
                        curLabelBean = lbChoose;
                    }
                    drawRectangleAsChair(graphics, lbChoose.Text, (int)xPos, (int)yPos, (int)width, (int)height,
                                         lbChoose.TextCorlor, borderColor, lbChoose.BackgroundCorlor, lbChoose.Rotate, lbChoose.Col);
                }
                //drawDataForDisplaying(bmp);
                return;
            }
        }