///<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; } } } }
///<summary>Runs as the final step of loading the form, and also immediately after fields are moved down due to growth.</summary> private void LayoutFields() { panelMain.Controls.Clear(); RichTextBox textbox;//has to be richtextbox due to MS bug that doesn't show cursor. FontStyle style; SheetCheckBox checkbox; //first, draw images--------------------------------------------------------------------------------------- //might change this to only happen once when first loading form: if(pictDraw!=null) { if(panelMain.Controls.Contains(pictDraw)) { Controls.Remove(pictDraw); } pictDraw=null; } imgDraw=null; pictDraw=new PictureBox(); if(SheetCur.IsLandscape) { imgDraw=new Bitmap(SheetCur.Height,SheetCur.Width); pictDraw.Width=SheetCur.Height; pictDraw.Height=SheetCur.Width; } else { imgDraw=new Bitmap(SheetCur.Width,SheetCur.Height); pictDraw.Width=SheetCur.Width; pictDraw.Height=SheetCur.Height; } pictDraw.Location=new Point(0,0); pictDraw.Image=(Image)imgDraw.Clone(); pictDraw.SizeMode=PictureBoxSizeMode.StretchImage; panelMain.Controls.Add(pictDraw); panelMain.SendToBack(); Graphics pictGraphics=Graphics.FromImage(imgDraw); foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.Image) { continue; } string filePathAndName=ODFileUtils.CombinePaths(SheetUtil.GetImagePath(),field.FieldName); Image img=null; if(field.FieldName=="Patient Info.gif") { img=Properties.Resources.Patient_Info; } else if(File.Exists(filePathAndName)) { img=Image.FromFile(filePathAndName); } else { continue; } pictGraphics.DrawImage(img,field.XPos,field.YPos,field.Width,field.Height); } pictGraphics.Dispose(); //Set mouse events for the pictDraw pictDraw.MouseDown+=new MouseEventHandler(pictDraw_MouseDown); pictDraw.MouseMove+=new MouseEventHandler(pictDraw_MouseMove); pictDraw.MouseUp+=new MouseEventHandler(pictDraw_MouseUp); //draw drawings, rectangles, and lines----------------------------------------------------------------------- RefreshPanel(); //draw textboxes---------------------------------------------------------------------------------------------- foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.InputField && field.FieldType!=SheetFieldType.OutputText && field.FieldType!=SheetFieldType.StaticText) { continue; } textbox=new RichTextBox(); textbox.BorderStyle=BorderStyle.None; textbox.TabStop=false;//Only input fields allow tab stop (set below for input text). //textbox.Multiline=true;//due to MS malfunction at 9pt which cuts off the bottom of the text. if(field.FieldType==SheetFieldType.OutputText || field.FieldType==SheetFieldType.StaticText) { //textbox.BackColor=Color.White; //textbox.BackColor=Color.FromArgb(245,245,200); } else if(field.FieldType==SheetFieldType.InputField) { textbox.BackColor=Color.FromArgb(245,245,200); textbox.TabStop=(field.TabOrder==0?false:true); textbox.TabIndex=field.TabOrder; } textbox.Location=new Point(field.XPos,field.YPos); textbox.Width=field.Width; textbox.ScrollBars=RichTextBoxScrollBars.None; textbox.Text=field.FieldValue; style=FontStyle.Regular; if(field.FontIsBold) { style=FontStyle.Bold; } textbox.Font=new Font(field.FontName,field.FontSize,style); if(field.Height<textbox.Font.Height+2) { textbox.Multiline=false; //textbox.AcceptsReturn=false; } else { textbox.Multiline=true; //textbox.AcceptsReturn=true; } textbox.Height=field.Height; //textbox.ScrollBars=RichTextBoxScrollBars.None; textbox.Tag=field; textbox.TextChanged+=new EventHandler(text_TextChanged); panelMain.Controls.Add(textbox); textbox.BringToFront(); } //draw checkboxes---------------------------------------------------------------------------------------------- foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.CheckBox) { continue; } checkbox=new SheetCheckBox(); if(field.FieldValue=="X") { checkbox.IsChecked=true; } checkbox.Location=new Point(field.XPos,field.YPos); checkbox.Width=field.Width; checkbox.Height=field.Height; checkbox.Tag=field; checkbox.Click+=new EventHandler(text_TextChanged); checkbox.TabStop=(field.TabOrder==0?false:true); checkbox.TabIndex=field.TabOrder; panelMain.Controls.Add(checkbox); checkbox.BringToFront(); } //draw signature boxes---------------------------------------------------------------------------------------------- foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.SigBox) { continue; } OpenDental.UI.SignatureBoxWrapper sigBox=new OpenDental.UI.SignatureBoxWrapper(); sigBox.Location=new Point(field.XPos,field.YPos); sigBox.Width=field.Width; sigBox.Height=field.Height; if(field.FieldValue.Length>0) {//a signature is present bool sigIsTopaz=false; if(field.FieldValue[0]=='1') { sigIsTopaz=true; } string signature=""; if(field.FieldValue.Length>1) { signature=field.FieldValue.Substring(1); } string keyData=Sheets.GetSignatureKey(SheetCur); sigBox.FillSignature(sigIsTopaz,keyData,signature); } sigBox.Tag=field; sigBox.TabStop=(field.TabOrder==0?false:true); sigBox.TabIndex=field.TabOrder; panelMain.Controls.Add(sigBox); sigBox.BringToFront(); } }
///<summary>Runs as the final step of loading the form, and also immediately after fields are moved down due to growth.</summary> private void LayoutFields() { panelMain.Controls.Clear(); RichTextBox textbox; //has to be richtextbox due to MS bug that doesn't show cursor. FontStyle style; SheetCheckBox checkbox; //first, draw images--------------------------------------------------------------------------------------- //might change this to only happen once when first loading form: if (pictDraw != null) { if (panelMain.Controls.Contains(pictDraw)) { Controls.Remove(pictDraw); } pictDraw = null; } imgDraw = null; pictDraw = new PictureBox(); if (SheetCur.IsLandscape) { imgDraw = new Bitmap(SheetCur.Height, SheetCur.Width); pictDraw.Width = SheetCur.Height; pictDraw.Height = SheetCur.Width; } else { imgDraw = new Bitmap(SheetCur.Width, SheetCur.Height); pictDraw.Width = SheetCur.Width; pictDraw.Height = SheetCur.Height; } pictDraw.Location = new Point(0, 0); pictDraw.Image = (Image)imgDraw.Clone(); pictDraw.SizeMode = PictureBoxSizeMode.StretchImage; panelMain.Controls.Add(pictDraw); panelMain.SendToBack(); Graphics pictGraphics = Graphics.FromImage(imgDraw); foreach (SheetField field in SheetCur.SheetFields) { if (field.FieldType != SheetFieldType.Image) { continue; } string filePathAndName = ODFileUtils.CombinePaths(SheetUtil.GetImagePath(), field.FieldName); Image img = null; if (field.FieldName == "Patient Info.gif") { img = Properties.Resources.Patient_Info; } else if (File.Exists(filePathAndName)) { img = Image.FromFile(filePathAndName); } else { continue; } pictGraphics.DrawImage(img, field.XPos, field.YPos, field.Width, field.Height); } pictGraphics.Dispose(); //Set mouse events for the pictDraw pictDraw.MouseDown += new MouseEventHandler(pictDraw_MouseDown); pictDraw.MouseMove += new MouseEventHandler(pictDraw_MouseMove); pictDraw.MouseUp += new MouseEventHandler(pictDraw_MouseUp); //draw drawings, rectangles, and lines----------------------------------------------------------------------- RefreshPanel(); //draw textboxes---------------------------------------------------------------------------------------------- foreach (SheetField field in SheetCur.SheetFields) { if (field.FieldType != SheetFieldType.InputField && field.FieldType != SheetFieldType.OutputText && field.FieldType != SheetFieldType.StaticText) { continue; } textbox = new RichTextBox(); textbox.BorderStyle = BorderStyle.None; textbox.TabStop = false; //Only input fields allow tab stop (set below for input text). //textbox.Multiline=true;//due to MS malfunction at 9pt which cuts off the bottom of the text. if (field.FieldType == SheetFieldType.OutputText || field.FieldType == SheetFieldType.StaticText) { //textbox.BackColor=Color.White; //textbox.BackColor=Color.FromArgb(245,245,200); } else if (field.FieldType == SheetFieldType.InputField) { textbox.BackColor = Color.FromArgb(245, 245, 200); textbox.TabStop = (field.TabOrder == 0?false:true); textbox.TabIndex = field.TabOrder; } textbox.Location = new Point(field.XPos, field.YPos); textbox.Width = field.Width; textbox.ScrollBars = RichTextBoxScrollBars.None; textbox.Text = field.FieldValue; style = FontStyle.Regular; if (field.FontIsBold) { style = FontStyle.Bold; } textbox.Font = new Font(field.FontName, field.FontSize, style); if (field.Height < textbox.Font.Height + 2) { textbox.Multiline = false; //textbox.AcceptsReturn=false; } else { textbox.Multiline = true; //textbox.AcceptsReturn=true; } textbox.Height = field.Height; //textbox.ScrollBars=RichTextBoxScrollBars.None; textbox.Tag = field; textbox.TextChanged += new EventHandler(text_TextChanged); panelMain.Controls.Add(textbox); textbox.BringToFront(); } //draw checkboxes---------------------------------------------------------------------------------------------- foreach (SheetField field in SheetCur.SheetFields) { if (field.FieldType != SheetFieldType.CheckBox) { continue; } checkbox = new SheetCheckBox(); if (field.FieldValue == "X") { checkbox.IsChecked = true; } checkbox.Location = new Point(field.XPos, field.YPos); checkbox.Width = field.Width; checkbox.Height = field.Height; checkbox.Tag = field; checkbox.Click += new EventHandler(text_TextChanged); checkbox.TabStop = (field.TabOrder == 0?false:true); checkbox.TabIndex = field.TabOrder; panelMain.Controls.Add(checkbox); checkbox.BringToFront(); } //draw signature boxes---------------------------------------------------------------------------------------------- foreach (SheetField field in SheetCur.SheetFields) { if (field.FieldType != SheetFieldType.SigBox) { continue; } OpenDental.UI.SignatureBoxWrapper sigBox = new OpenDental.UI.SignatureBoxWrapper(); sigBox.Location = new Point(field.XPos, field.YPos); sigBox.Width = field.Width; sigBox.Height = field.Height; if (field.FieldValue.Length > 0) //a signature is present { bool sigIsTopaz = false; if (field.FieldValue[0] == '1') { sigIsTopaz = true; } string signature = ""; if (field.FieldValue.Length > 1) { signature = field.FieldValue.Substring(1); } string keyData = Sheets.GetSignatureKey(SheetCur); sigBox.FillSignature(sigIsTopaz, keyData, signature); } sigBox.Tag = field; sigBox.TabStop = (field.TabOrder == 0?false:true); sigBox.TabIndex = field.TabOrder; panelMain.Controls.Add(sigBox); sigBox.BringToFront(); } }
///<summary>Runs as the final step of loading the form, and also immediately after fields are moved down due to growth.</summary> private void LayoutFields() { List<SheetField> fieldsSorted=new List<SheetField>(); fieldsSorted.AddRange(SheetCur.SheetFields);//Creates a sortable list that will not change sort order of the original list. fieldsSorted.Sort(SheetFields.SortDrawingOrderLayers); panelMain.Controls.Clear(); RichTextBox textbox;//has to be richtextbox due to MS bug that doesn't show cursor. FontStyle style; SheetCheckBox checkbox; //first, draw images--------------------------------------------------------------------------------------- //might change this to only happen once when first loading form: if(pictDraw!=null) { if(panelMain.Controls.Contains(pictDraw)) { Controls.Remove(pictDraw); } pictDraw=null; } imgDraw=null; pictDraw=new PictureBox(); if(SheetCur.IsLandscape) { //imgDraw=new Bitmap(SheetCur.Height,SheetCur.Width); pictDraw.Width=SheetCur.Height; pictDraw.Height=SheetCur.Width; } else { //imgDraw=new Bitmap(SheetCur.Width,SheetCur.Height); pictDraw.Width=SheetCur.Width; pictDraw.Height=SheetCur.Height; } if(Sheets.CalculatePageCount(SheetCur,_printMargin)==1){ pictDraw.Height=SheetCur.HeightPage;//+10 for HScrollBar } else { int pageCount=0; pictDraw.Height=SheetPrinting.bottomCurPage(SheetCur.HeightLastField,SheetCur,out pageCount); } //imgDraw.Dispose();//dispose of old image before setting it to a new image. imgDraw=new Bitmap(pictDraw.Width,pictDraw.Height); pictDraw.Location=new Point(0,0); pictDraw.Image=(Image)imgDraw.Clone(); pictDraw.SizeMode=PictureBoxSizeMode.StretchImage; panelMain.Controls.Add(pictDraw); panelMain.SendToBack(); Graphics pictGraphics=Graphics.FromImage(imgDraw); SheetPrinting.DrawImages(SheetCur,pictGraphics,true); pictGraphics.Dispose(); //Set mouse events for the pictDraw pictDraw.MouseDown+=new MouseEventHandler(pictDraw_MouseDown); pictDraw.MouseMove+=new MouseEventHandler(pictDraw_MouseMove); pictDraw.MouseUp+=new MouseEventHandler(pictDraw_MouseUp); //draw drawings, rectangles, and lines----------------------------------------------------------------------- RefreshPanel(); //draw textboxes---------------------------------------------------------------------------------------------- foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.InputField && field.FieldType!=SheetFieldType.OutputText && field.FieldType!=SheetFieldType.StaticText) { continue; } textbox=new RichTextBox(); textbox.BorderStyle=BorderStyle.None; textbox.TabStop=false;//Only input fields allow tab stop (set below for input text). //textbox.Multiline=true;//due to MS malfunction at 9pt which cuts off the bottom of the text. if(field.FieldType==SheetFieldType.OutputText || field.FieldType==SheetFieldType.StaticText) { //textbox.BackColor=Color.White; //textbox.BackColor=Color.FromArgb(245,245,200); } else if(field.FieldType==SheetFieldType.InputField) { textbox.BackColor=Color.FromArgb(245,245,200); textbox.TabStop=(field.TabOrder==0?false:true); textbox.TabIndex=field.TabOrder; } textbox.Location=new Point(field.XPos,field.YPos); textbox.Width=field.Width; textbox.ScrollBars=RichTextBoxScrollBars.None; if(field.ItemColor!=Color.FromArgb(0)){ textbox.ForeColor=field.ItemColor; } //textbox.Text=field.FieldValue; textbox.SelectionAlignment=field.TextAlign; textbox.SelectedText=field.FieldValue; style=FontStyle.Regular; if(field.FontIsBold) { style=FontStyle.Bold; } textbox.Font=new Font(field.FontName,field.FontSize,style); if(field.Height<textbox.Font.Height+2) { textbox.Multiline=false; //textbox.AcceptsReturn=false; } else { textbox.Multiline=true; //textbox.AcceptsReturn=true; } textbox.Height=field.Height; //textbox.ScrollBars=RichTextBoxScrollBars.None; textbox.Tag=field; textbox.TextChanged+=new EventHandler(text_TextChanged); panelMain.Controls.Add(textbox); textbox.BringToFront(); } //draw checkboxes---------------------------------------------------------------------------------------------- foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.CheckBox) { continue; } checkbox=new SheetCheckBox(); if(field.FieldValue=="X") { checkbox.IsChecked=true; } checkbox.Location=new Point(field.XPos,field.YPos); checkbox.Width=field.Width; checkbox.Height=field.Height; checkbox.Tag=field; checkbox.MouseUp+=new MouseEventHandler(checkbox_MouseUp); checkbox.TabStop=(field.TabOrder==0?false:true); checkbox.TabIndex=field.TabOrder; panelMain.Controls.Add(checkbox); checkbox.BringToFront(); } //draw signature boxes---------------------------------------------------------------------------------------------- foreach(SheetField field in SheetCur.SheetFields) { if(field.FieldType!=SheetFieldType.SigBox) { continue; } OpenDental.UI.SignatureBoxWrapper sigBox=new OpenDental.UI.SignatureBoxWrapper(); sigBox.Location=new Point(field.XPos,field.YPos); sigBox.Width=field.Width; sigBox.Height=field.Height; if(field.FieldValue.Length>0) {//a signature is present bool sigIsTopaz=false; if(field.FieldValue[0]=='1') { sigIsTopaz=true; } string signature=""; if(field.FieldValue.Length>1) { signature=field.FieldValue.Substring(1); } string keyData=Sheets.GetSignatureKey(SheetCur); sigBox.FillSignature(sigIsTopaz,keyData,signature); } sigBox.Tag=field; sigBox.TabStop=(field.TabOrder==0?false:true); sigBox.TabIndex=field.TabOrder; panelMain.Controls.Add(sigBox); sigBox.BringToFront(); } }