コード例 #1
0
        protected void DisplayRoundMark(PaintEventArgs pe, Image imgMark, InstrumentControlMarksDefinition insControlMarksDefinition, Point ptImg, int radiusPx, Boolean displayText, float scaleFactor)
        {
            Double     alphaRot;
            int        textBoxLength;
            int        textPointRadiusPx;
            int        textBoxHeight = (int)(insControlMarksDefinition.fontSize * 1.1 / scaleFactor);
            Point      textPoint     = new Point();
            Point      rotatePoint   = new Point();
            Font       markFont      = new Font("Arial", insControlMarksDefinition.fontSize);
            SolidBrush markBrush     = new SolidBrush(insControlMarksDefinition.fontColor);

            InstrumentControlMarkPoint[] markArray = new InstrumentControlMarkPoint[2 + insControlMarksDefinition.numberOfDivisions];

            // Buid the markArray
            markArray[0].value = insControlMarksDefinition.minPhy;
            markArray[0].angle = insControlMarksDefinition.minAngle;
            markArray[markArray.Length - 1].value = insControlMarksDefinition.maxPhy;
            markArray[markArray.Length - 1].angle = insControlMarksDefinition.maxAngle;

            for (int index = 1; index < insControlMarksDefinition.numberOfDivisions + 1; index++)
            {
                markArray[index].value = (insControlMarksDefinition.maxPhy - insControlMarksDefinition.minPhy) / (insControlMarksDefinition.numberOfDivisions + 1) * index + insControlMarksDefinition.minPhy;
                markArray[index].angle = (insControlMarksDefinition.maxAngle - insControlMarksDefinition.minAngle) / (insControlMarksDefinition.numberOfDivisions + 1) * index + insControlMarksDefinition.minAngle;
            }

            // Define the rotate point (center of the indicator)
            rotatePoint.X = (int)((this.Width / 2) / scaleFactor);
            rotatePoint.Y = rotatePoint.X;

            // Display mark array
            foreach (InstrumentControlMarkPoint markPoint in markArray)
            {
                // pre computings
                alphaRot          = (Math.PI / 2) - markPoint.angle;
                textBoxLength     = (int)(Convert.ToString(markPoint.value).Length *insControlMarksDefinition.fontSize *0.8 / scaleFactor);
                textPointRadiusPx = (int)(radiusPx - 1.2 * imgMark.Height - 0.5 * textBoxLength);
                textPoint.X       = (int)((textPointRadiusPx * Math.Cos(markPoint.angle) - 0.5 * textBoxLength + rotatePoint.X) * scaleFactor);
                textPoint.Y       = (int)((-textPointRadiusPx * Math.Sin(markPoint.angle) - 0.5 * textBoxHeight + rotatePoint.Y) * scaleFactor);

                // Display mark
                RotateImage(pe, imgMark, alphaRot, ptImg, rotatePoint, scaleFactor);

                // Display text
                if (displayText == true)
                {
                    pe.Graphics.DrawString(Convert.ToString(markPoint.value), markFont, markBrush, textPoint);
                }
            }
        }
コード例 #2
0
        protected void DisplayRoundMark(PaintEventArgs pe, Image imgMark, InstrumentControlMarksDefinition insControlMarksDefinition, Point ptImg, int radiusPx, Boolean displayText, float scaleFactor)
        {
            Double alphaRot;
            int textBoxLength;
            int textPointRadiusPx;
            int textBoxHeight = (int)(insControlMarksDefinition.fontSize*1.1/scaleFactor);      
            Point textPoint = new Point();
            Point rotatePoint = new Point();
            Font markFont = new Font("Arial", insControlMarksDefinition.fontSize);
            SolidBrush markBrush = new SolidBrush(insControlMarksDefinition.fontColor);
            InstrumentControlMarkPoint[] markArray = new InstrumentControlMarkPoint[2 + insControlMarksDefinition.numberOfDivisions];

            // Buid the markArray
            markArray[0].value = insControlMarksDefinition.minPhy;
            markArray[0].angle = insControlMarksDefinition.minAngle;
            markArray[markArray.Length - 1].value = insControlMarksDefinition.maxPhy;
            markArray[markArray.Length - 1].angle = insControlMarksDefinition.maxAngle;

            for (int index = 1; index < insControlMarksDefinition.numberOfDivisions+1; index++)
            {
                markArray[index].value = (insControlMarksDefinition.maxPhy - insControlMarksDefinition.minPhy) / (insControlMarksDefinition.numberOfDivisions + 1) * index + insControlMarksDefinition.minPhy;
                markArray[index].angle = (insControlMarksDefinition.maxAngle - insControlMarksDefinition.minAngle) / (insControlMarksDefinition.numberOfDivisions + 1) * index + insControlMarksDefinition.minAngle;
            }

            // Define the rotate point (center of the indicator)
            rotatePoint.X = (int)((this.Width/2)/scaleFactor);
            rotatePoint.Y = rotatePoint.X;
            
            // Display mark array
            foreach (InstrumentControlMarkPoint markPoint in markArray)
            {
                // pre computings
                alphaRot = (Math.PI / 2) - markPoint.angle;
                textBoxLength = (int)(Convert.ToString(markPoint.value).Length * insControlMarksDefinition.fontSize*0.8/scaleFactor);
                textPointRadiusPx = (int)(radiusPx - 1.2*imgMark.Height - 0.5 * textBoxLength);
                textPoint.X = (int)((textPointRadiusPx * Math.Cos(markPoint.angle) - 0.5 * textBoxLength + rotatePoint.X) * scaleFactor);
                textPoint.Y = (int)((-textPointRadiusPx * Math.Sin(markPoint.angle) - 0.5 * textBoxHeight + rotatePoint.Y) * scaleFactor);
                
                // Display mark
                RotateImage(pe, imgMark, alphaRot, ptImg, rotatePoint, scaleFactor);

                // Display text
                if (displayText == true)
                {
                    pe.Graphics.DrawString(Convert.ToString(markPoint.value), markFont, markBrush, textPoint);
                }
            }
        }