tooltiptext

  

public void createPartControl(Composite parent) {

final Composite top = new Composite(parent, SWT.NONE);

GridLayout topLayout = new GridLayout(2, false);

top.setLayout(topLayout);

Label label = new Label(top, SWT.NONE);

label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,false));

label.setText("Name:");

final Text text = new Text(top, SWT.SINGLE | SWT.LEAD | SWT.BORDER);

text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

text.setText("");

final Color bgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED);

final Color fgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);

final AtomicReference x = new AtomicReference();

final AtomicReference y = new AtomicReference();

text.addMouseTrackListener(new MouseTrackAdapter(){

public void mouseHover(MouseEvent e) {

x.set(e.x);

y.set(e.y);

text.redraw();

}

});

text.addPaintListener(new PaintListener(){

public void paintControl(PaintEvent e) {

GC gc = e.gc;

if(x.get() != null && y.get() != null){

Rectangle rect = new Rectangle(x.get(),y.get(),100,20);

gc.setBackground(bgColor);

gc.setForeground(fgColor);

gc.fillRectangle(rect);

gc.drawText("Hello, it works!", rect.x, rect.y);

}

}

});

}

 

 

http://blog.csdn.net/goggler/article/details/5044983

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要设置DataGridView的ToolTipText字体大小,可以使用以下代码: ``` private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; string cellValue = cell.Value == null ? "" : cell.Value.ToString(); if (cell.ToolTipText != cellValue) { cell.ToolTipText = cellValue; ToolTip tt = new ToolTip(); tt.UseFading = true; tt.UseAnimation = true; tt.IsBalloon = true; tt.ShowAlways = true; tt.AutoPopDelay = 5000; tt.InitialDelay = 1000; tt.ReshowDelay = 500; tt.OwnerDraw = true; tt.Draw += new DrawToolTipEventHandler(tt_Draw); tt.Popup += new PopupEventHandler(tt_Popup); tt.SetToolTip(dataGridView1, cell.ToolTipText); } } } private void tt_Popup(object sender, PopupEventArgs e) { Font f = new Font("Arial", 12, FontStyle.Bold); e.ToolTipSize = TextRenderer.MeasureText(e.ToolTipText, f); e.ToolTipSize = new Size(e.ToolTipSize.Width + 20, e.ToolTipSize.Height + 10); } private void tt_Draw(object sender, DrawToolTipEventArgs e) { e.DrawBackground(); e.DrawBorder(); e.DrawText(TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter); } ``` 在这个代码示例中,我们使用了DataGridView的CellMouseEnter事件来设置ToolTipText的值。然后,我们创建了一个ToolTip对象,并设置其各种属性,例如使用动画、显示气球、自动弹出延迟等。 在Popup事件中,我们使用MeasureText方法来测量ToolTipText的大小,并将其大小增加了一些以适应字体大小。在Draw事件中,我们使用DrawBackground、DrawBorder和DrawText方法来绘制ToolTipText的外观。 要更改字体大小,只需更改Font对象的大小即可。例如,要将字体大小更改为14,只需将以下行更改为: ``` Font f = new Font("Arial", 14, FontStyle.Bold); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值