导航
  • 主页
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm
  • WPF
  • 问答

紧急求教:字体设置问题

letian 2003-04-21 09:43:50
如何改变DataGrid选中方框的字体?
用FontDialog fDlg=new FontDialog();打开的字体设置对话框
如何把fDlg.Font赋值DataGrid当前所在方框呢?
我用以下方法
this.ActiveControl.Font=fDlg.Font;
当dataGrid当前编辑框焦点失去后,字体变为原来的字体,为什么呢???


...全文
7 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
aaxu 2003-04-24
up
回复
jlhdlj 2003-04-24
同意楼上!
回复
TheAres 2003-04-23
同样的,打不开看这个:

5.10 How do I color a individual cell depending upon its value or some external method?
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q745q

一种办法如下:

public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn

{

protected override void Paint(System.Drawing.Graphics g,

System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager

source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush

foreBrush, bool alignToRight)

{

// the idea is to conditionally set the foreBrush and/or backbrush

// depending upon some crireria on the cell value

// Here, we color anything that begins with a letter higher than 'F'

try{

object o = this.GetColumnValueAtRow(source, rowNum);

if( o!= null)

{

char c = ((string)o)[0];

if( c > 'F')

{

// could be as simple as

// backBrush = new SolidBrush(Color.Pink);

// or something fancier...

backBrush = new LinearGradientBrush(bounds,

Color.FromArgb(255, 200, 200),

Color.FromArgb(128, 20, 20),

LinearGradientMode.BackwardDiagonal);

foreBrush = new SolidBrush(Color.White);

}

}

}

catch(Exception ex){ /* empty catch */ }

finally{

// make sure the base class gets called to do the drawing with

// the possibly changed brushes

base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);

}

}

}

回复
hillwell 2003-04-23
关注
回复
sheyanfen 2003-04-22
没看TheAres(班门斧) 给的地址吗?
我试了,这样就可以啊,你再试试,看还有没有其它问题!
dataGrid1.Font=new System.Drawing.Font("Microsoft Sans Serif",11);
回复
letian 2003-04-22
To unfor(myes) :
感谢你的回复!
我用你的方法也是出现同样的情况,即datagrid某行某列不处于编辑状态时,字体又变为原来的字体!!
回复
unfor 2003-04-22
用以下方法:
Dim tTable As DataTable
Dim rRow As DataRow
Dim cColumn As DataColumn

tTable = myDataSet.Tables("myTable")
Dim i As Integer = 0

For Each rRow In tTable.Rows
Dim fieldvalue As Boolean = myDataSet.Tables(0).Rows(i)
("strikeout")
If fieldvalue Then
myDataGrid.Font = New System.Drawing.Font("Microsoft
Sans Serif", 8.25!, System.Drawing.FontStyle.Strikeout,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
End If
i = i + 1
Next rRow
回复
letian 2003-04-22
怎么打不开啊?
是这样的,在编辑状态能显示修改后的字体,但当显示时,去还原为原来的字体,为何呢?
请大家帮帮忙啊
回复
TheAres 2003-04-21

Datagrid Change Font in specific Row
http://www.dotnet247.com/247reference/msgs/24/124401.aspx
回复
qiuafa 2003-04-21
蹭分
回复
发动态
发帖子
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
社区公告

全世界最好的语言,没有之一.