private KeyValuePair<string, Font> GetCodigoBarrasRecaudo(UltraLabel label, Graphics graphics) { //Other Code if (valuesOfParams[0] == "1") { privateFontCollection = new PrivateFontCollection(); privateFontCollection.AddFontFile(Application.StartupPath + @"\Updates\Fonts\Code128bWinLarge.ttf"); var fontFamily = privateFontCollection.Families.Where(p => p.Name == "Code128bWinLarge").FirstOrDefault(); if (fontFamily == null) { errorMessage = $"Error durante proceso de codificación:\nNo se encontro la fuente de Codigo de Barras"; return GetErrorMessageBarCodeRecaudo(label, errorMessage, fontToText, graphics); } if (fontFamily.IsStyleAvailable(FontStyle.Regular)) fontToText = new Font(fontFamily, label.Font.SizeInPoints, FontStyle.Regular, GraphicsUnit.Pixel); if ((int)label.Appearance.TextHAlign == 0) label.Appearance.TextHAlign = HAlign.Left; } ModifySizeOfControl(label, fontToText, encodeData, graphics); return new KeyValuePair<string, Font>(encodeData, fontToText); }
private string GetValorCalculado(UltraLabel lblCalculado, Graphics graphics, ref Font fontToControl) { //other code..... var resultEncode = GetCodigoBarrasRecaudo(lblCalculado, graphics); valorCalculado = resultEncode.Key; fontToControl = resultEncode.Value; return valorCalculado; }
private void ultraPrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { //other code....... string valueOfLabel = string.Empty; Font fontToLabel = lbl.Font; valueOfLabel = GetValorCalculado(lbl, e.Graphics, ref fontToLabel); e.Graphics.DrawString(valueOfLabel, fontToLabel, new SolidBrush(lbl.Appearance.ForeColor), rt, this.alineacionTexto(lbl)); }
Hi, thanks for your response.
I do not understand what you mean, e.Graphics.DrawString that is displayed, is obtained from the PrintPage event of my UltraPrintDocument.
UltraPrintDocument derives from PrintDocument. So the event you are handling is an event on PrintDocument, and the Graphics object in the event args is simply the graphics of the printer page. In any case, I'm not sure if the graphics object is really relevant here. If you assigned a font from a PrivateFontCollection as the Font property of the label, and then you are getting the lbl.Font property, I would expect it to return the Font you set it to. But once again, the Font property is a property on Control, so if that's happening, it seems to me that it's an issue with the DotNet framework and isn't anything specific to the Infragistics controls.
Is that what's happening? Are you explicitly setting the Font property of an UltraLabel and then later retrieving the Font property of that same UltraLabel control and getting the wrong Font? I don't see anywhere in the code you posted here where you are setting a Font on an UltraLabel control - or any control. I see where you are getting it and using it in the PrintPage event. If it's not the correct Font, then I recommend trying this with some other control, like an inbox Label control. If the Label control works and the UltraLabel does not, than maybe there's a bug there. Also, just to be clear, the only way this would work is if you set the Font Property on the control. Setting the UltraLabel.Appearance.Font properties would not work and would not affect the Font being returned from the property.