private void tableCell25_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
// 获取当前单元格的内容
string originalContent = tableCell25.Text;
// 如果内容不为空,则替换逗号为换行符
if (!string.IsNullOrEmpty(originalContent)) {
tableCell25.Text = originalContent.Replace(",", Environment.NewLine + Environment.NewLine);//换两行
}
tableCell25.CanGrow = true; // 允许单元格自动扩展高度
tableCell25.WordWrap = true; // 允许文本换行
tableCell25.Multiline = true; // 允许多行
// 手动调整字体大小(如果 ShrinkToFit 不生效)
while (tableCell25.Text.Length > 20 && tableCell25.Font.Size > 8) {
tableCell25.Font = new System.Drawing.Font(tableCell25.Font.FontFamily, tableCell25.Font.Size - 1);
}
}
本文链接:https://blog.vvlei.com/archives/42.html