包装标题文本时出现问题. [英] Problem in wrapping up the header text.

查看:81
本文介绍了包装标题文本时出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个用于打印在datagrid视图中显示的内容的代码.但是由于我的表有10列,所以打印机不行
在单个页面上打印所有列.它在一页上打印7列,在另一页上打印.我试图解决这个问题
通过包装列的标题文本使所有列出现问题.我更改了gridview的"columnheaderdefaultstyle"属性,但没有帮助.我也想包装行文本.这是我正在使用的代码:

Hey guys,

I have got a code for printing content displayed in datagrid view. But as my table has 10 columns, printer is not
printing all the columns on a single page. It prints 7 columns on one page and rest on another. I tried to solve this
problem by wrapping the header text of columns so that all the columns. I changed the "columnheaderdefaultstyle" property of gridview but it didn''t help. I also want to wrap the row text. Here''s the code I am using :

SizeF tmpSize = new SizeF();
          Font tmpFont;
          float tmpWidth;
          TheDataGridViewWidth = 0;
          for (int i = 0; i < TheDataGridView.Columns.Count; i++)
          {
            tmpFont = TheDataGridView.ColumnHeadersDefaultCellStyle.Font;
            
            if (tmpFont == null) // If there is no special HeaderFont style, then use the default DataGridView font style
              tmpFont = TheDataGridView.DefaultCellStyle.Font;

            tmpSize = g.MeasureString(TheDataGridView.Columns[i].HeaderText, tmpFont);
            tmpWidth = tmpSize.Width;
            RowHeaderHeight = tmpSize.Height;

            for (int j = 0; j < TheDataGridView.Rows.Count; j++)
            {
              tmpFont = TheDataGridView.Rows[j].DefaultCellStyle.Font;
              if (tmpFont == null) // If the there is no special font style of the CurrentRow, then use the default one associated with the DataGridView control
                tmpFont = TheDataGridView.DefaultCellStyle.Font;

              tmpSize = g.MeasureString("Anything", tmpFont);
              RowsHeight.Add(tmpSize.Height);

              tmpSize = g.MeasureString(TheDataGridView.Rows[j].Cells[i].EditedFormattedValue.ToString(), tmpFont);
              if (tmpSize.Width > tmpWidth)
                tmpWidth = tmpSize.Width;
            }
            if (TheDataGridView.Columns[i].Visible)
              TheDataGridViewWidth += tmpWidth;
            ColumnsWidth.Add(tmpWidth);
          }




我该如何解决这个问题?
请帮忙.

谢谢
Ajinkya




How can I solve this problem??
Please help.

Thanks
Ajinkya

推荐答案

您是否尝试过将其打印为风景?

您将不得不做出一些权衡.
从这里我可以看到,您想要将列宽调整为与单元格内容有关的最大可能值,但不能总是得到它.
在类似的情况下,我将使用landscape作为默认方向,并尝试为字符串值调整行的高度,或者为数字值或组合使用较小的字体;正如我所说的那样,即使使用商业报告引擎,您也必须做出一些选择.
Have you tried to print it as landscape?

You will have to make some trade-offs.
From what I can see here, you want to adjust column width to maximum possible regarding the cell content, you can''t get it always.
In similar case I would use landscape as default orientation and try to adjust height of row for string values, or to use smaller font for numeric values, or combination; as I said trade-offs, you must make some even with commercial reporting engines.


这篇关于包装标题文本时出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆