Beispiel #1
0
        ///<summary>Just before printing or displaying the final sheet output, the heights and y positions of various fields are adjusted according to their growth behavior.  This also now gets run every time a user changes the value of a textbox while filling out a sheet.</summary>
        public static void CalculateHeights(Sheet sheet, Graphics g)
        {
            //Sheet sheetCopy=sheet.Clone();
            int       calcH;
            Font      font;
            FontStyle fontstyle;

            foreach (SheetField field in sheet.SheetFields)
            {
                if (field.GrowthBehavior == GrowthBehaviorEnum.None)
                {
                    continue;
                }
                fontstyle = FontStyle.Regular;
                if (field.FontIsBold)
                {
                    fontstyle = FontStyle.Bold;
                }
                font = new Font(field.FontName, field.FontSize, fontstyle);
                //calcH=(int)g.MeasureString(field.FieldValue,font).Height;//this was too short
                calcH = GraphicsHelper.MeasureStringH(g, field.FieldValue, font, field.Width);
                if (calcH <= field.Height)
                {
                    continue;
                }
                int amountOfGrowth = calcH - field.Height;
                field.Height = calcH;
                if (field.GrowthBehavior == GrowthBehaviorEnum.DownLocal)
                {
                    MoveAllDownWhichIntersect(sheet, field, amountOfGrowth);
                }
                else if (field.GrowthBehavior == GrowthBehaviorEnum.DownGlobal)
                {
                    MoveAllDownBelowThis(sheet, field, amountOfGrowth);
                }
            }
            //g.Dispose();
            //return sheetCopy;
        }
        ///<summary>Triggered when any field value changes.  This immediately invalidates signatures.  It also causes fields to grow as needed and deselects other radiobuttons in a group.</summary>
        private void text_TextChanged(object sender, EventArgs e)
        {
            foreach (Control control in panelMain.Controls)
            {
                if (control.GetType() != typeof(OpenDental.UI.SignatureBoxWrapper))
                {
                    continue;
                }
                if (control.Tag == null)
                {
                    continue;
                }
                SheetField field = (SheetField)control.Tag;
                OpenDental.UI.SignatureBoxWrapper sigBox = (OpenDental.UI.SignatureBoxWrapper)control;
                sigBox.SetInvalid();
            }
            if (sender.GetType() == typeof(SheetCheckBox))
            {
                SheetCheckBox checkbox = (SheetCheckBox)sender;
                if (checkbox.Tag == null)
                {
                    return;
                }
                if (!checkbox.IsChecked)                 //if user unchecked a radiobutton, nothing else happens
                {
                    return;
                }
                SheetField fieldThis = (SheetField)checkbox.Tag;
                if (fieldThis.RadioButtonGroup == "" && fieldThis.RadioButtonValue == "")            //if it's a checkbox instead of a radiobutton
                {
                    return;
                }
                foreach (Control control in panelMain.Controls)                 //set some other radiobuttons to be not checked
                {
                    if (control.GetType() != typeof(SheetCheckBox))
                    {
                        continue;
                    }
                    if (control.Tag == null)
                    {
                        continue;
                    }
                    if (control == sender)
                    {
                        continue;
                    }
                    SheetField fieldOther = (SheetField)control.Tag;
                    if (fieldThis.FieldName != fieldOther.FieldName)                   //different radio group
                    {
                        continue;
                    }
                    //If both checkbox field names are set to "misc" then we instead use the RadioButtonGroup as the actual radio button group name.
                    if (fieldThis.FieldName == "misc" && fieldThis.RadioButtonGroup != fieldOther.RadioButtonGroup)
                    {
                        continue;
                    }
                    ((SheetCheckBox)control).IsChecked = false;
                }
                return;
            }
            if (sender.GetType() != typeof(RichTextBox))
            {
                //since CheckBoxes also trigger this event for sig invalid.
                return;
            }
            //everything below here is for growth calc.
            RichTextBox textBox = (RichTextBox)sender;
            //remember where we were
            int cursorPos = textBox.SelectionStart;
            //int boxX=textBox.Location.X;
            //int boxY=textBox.Location.Y;
            //string originalFieldValue=((SheetField)((RichTextBox)control).Tag).FieldValue;
            SheetField fld = (SheetField)textBox.Tag;

            if (fld.GrowthBehavior == GrowthBehaviorEnum.None)
            {
                return;
            }
            fld.FieldValue = textBox.Text;
            Graphics  g         = this.CreateGraphics();
            FontStyle fontstyle = FontStyle.Regular;

            if (fld.FontIsBold)
            {
                fontstyle = FontStyle.Bold;
            }
            Font font  = new Font(fld.FontName, fld.FontSize, fontstyle);
            int  calcH = GraphicsHelper.MeasureStringH(g, fld.FieldValue, font, fld.Width);

            //(int)(g.MeasureString(fld.FieldValue,font,fld.Width).Height * 1.133f);//Seems to need 2 pixels per line of text to prevent hidden text due to scroll.
            calcH += font.Height + 2;        //add one line just in case.
            g.Dispose();
            if (calcH <= fld.Height)         //no growth needed
            {
                return;
            }
            //the field height needs to change, so:
            int amountOfGrowth = calcH - fld.Height;

            fld.Height = calcH;
            FillFieldsFromControls();            //We already changed the value of this field manually,
            //but if the other fields don't get changed, they will erroneously 'reset'.
            if (fld.GrowthBehavior == GrowthBehaviorEnum.DownGlobal)
            {
                SheetUtil.MoveAllDownBelowThis(SheetCur, fld, amountOfGrowth);
            }
            else if (fld.GrowthBehavior == GrowthBehaviorEnum.DownLocal)
            {
                SheetUtil.MoveAllDownWhichIntersect(SheetCur, fld, amountOfGrowth);
            }
            LayoutFields();
            //find the original textbox, and put the cursor back where it belongs
            foreach (Control control in panelMain.Controls)
            {
                if (control.GetType() == typeof(RichTextBox))
                {
                    if ((SheetField)(control.Tag) == fld)
                    {
                        ((RichTextBox)control).Select(cursorPos, 0);
                        ((RichTextBox)control).Focus();
                        //((RichTextBox)control).SelectionStart=cursorPos;
                    }
                }
            }
        }