- 題名: DataGridの列ヘッダー
- 日時: 2004/03/08 17:56:34
- ID: 2924
- この記事の返信元:
- (なし)
- この記事への返信:
- [2929] Re[1]: DataGridの列ヘッダー2004/03/09 3:51:14
- ツリーを表示
■No2937に返信(VB.NET初心者さんの記事) > VB.NETでのソースはございませんでしょうか? 例によってC# to VB.NET Translatorにて変換し、修正しました。 ちゃんと動くかまだ分かりませんので、ご報告いただければ助かります。 Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.Data Namespace Dobon.Samples.Forms Public Class MyDataGridTextBoxColumn Inherits DataGridTextBoxColumn Private _margin As New Point(0, 2) Private _dataAlignment As HorizontalAlignment = _ HorizontalAlignment.Left Public Property DataAlignment() As HorizontalAlignment Get Return _dataAlignment End Get Set(ByVal Value As HorizontalAlignment) _dataAlignment = Value End Set End Property Protected Overloads Overrides Sub Edit( _ ByVal [source] As CurrencyManager, _ ByVal rowNum As Integer, _ ByVal bounds As Rectangle, _ ByVal [readOnly] As Boolean, _ ByVal instantText As String, _ ByVal cellIsVisible As Boolean) MyBase.Edit([source], rowNum, bounds, [readOnly], _ instantText, cellIsVisible) Me.TextBox.TextAlign = _dataAlignment End Sub Protected Overloads Overrides Sub Paint( _ ByVal g As Graphics, _ ByVal bounds As Rectangle, _ ByVal [source] As CurrencyManager, _ ByVal rowNum As Integer, _ ByVal backBrush As Brush, _ ByVal foreBrush As Brush, _ ByVal alignToRight As Boolean) Dim [text] As String = _ GetColumnValueAtRow([source], rowNum).ToString() Dim sf As New StringFormat Select Case _dataAlignment Case HorizontalAlignment.Left sf.Alignment = StringAlignment.Near Case HorizontalAlignment.Center sf.Alignment = StringAlignment.Center Case HorizontalAlignment.Right sf.Alignment = StringAlignment.Far End Select sf.FormatFlags = StringFormatFlags.NoWrap If alignToRight Then sf.FormatFlags = sf.FormatFlags Or _ StringFormatFlags.DirectionRightToLeft End If g.FillRectangle(backBrush, bounds) Dim rectf As New RectangleF( _ bounds.X, bounds.Y, bounds.Width, bounds.Height) rectf.Inflate(-_margin.X, -_margin.Y) g.DrawString([text], _ Me.DataGridTableStyle.DataGrid.Font, _ foreBrush, CType(rectf, RectangleF), sf) sf.Dispose() End Sub End Class End Namespace
分類:[.NET]
DataGridの列ヘッダーを中央配置したいのですが
どのようにしたらよいのでしょうか?
初歩的な質問で申し訳ないです。