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;

    }


    }







    }
    }

  • 相关阅读:
    poj2942 点-双联通+二分图染色
    poj1523割顶-点双联通
    poj3694 边-双连通分量+lca
    poj3177边-双连通分量
    poj3352 边-双联通分量
    Codeforces Round #377 (Div. 2) F
    Educational Codeforces Round 30D. Merge Sort
    洛谷p3369 treap
    hdu3572线性欧拉筛
    HYSBZ
  • 原文地址:https://www.cnblogs.com/because/p/2295115.html
Copyright © 2011-2022 走看看