zoukankan      html  css  js  c++  java
  • 将文本在单元格中垂直显示

    将文本在DataGridView的单元格中竖直显示,需要在CellPainting事件中设置StringFormatFlag.DirectionVertical

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    DataTable dt = new DataTable();

    dt.Columns.Add("c1");

    dt.Columns.Add("c2");

    for (int j = 0; j < 10; j++)
    {

    dt.Rows.Add("aaaaaaaaa", "bbbb");

    }

    this.dataGridView1.DataSource = dt;



    this.dataGridView1.CellPainting += new

    DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting); ;


    }

    private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    {
    if (e.ColumnIndex == 1 && e.RowIndex > -1 && e.Value != null)
    {

    e.Paint(e.CellBounds, DataGridViewPaintParts.All

    & ~DataGridViewPaintParts.ContentForeground);

    StringFormat sf = new StringFormat();

    sf.Alignment = StringAlignment.Center;

    sf.LineAlignment = StringAlignment.Center;

    sf.FormatFlags = StringFormatFlags.DirectionVertical;

    e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,

    new SolidBrush(e.CellStyle.ForeColor), e.CellBounds, sf);

    e.Handled = true;

    }


    }







    }
    }

  • 相关阅读:
    JS表格分页组件:fupage的设计思路和详细使用方法(未来考虑开源,争取在2015年)
    《The Swift Programming Language》的笔记-第28页
    JavaScript基础总纲
    HTML基础总纲
    个人KPI制定
    软件测试中常用语
    测试计划
    软件性能测试的几种方法(三)
    影响软件性能的因素(二)
    性能测试的重要意义(一)
  • 原文地址:https://www.cnblogs.com/because/p/2295115.html
Copyright © 2011-2022 走看看