从其他应用程序的按钮字体 [英] get a button font from other applications

查看:130
本文介绍了从其他应用程序的按钮字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的第一次英语对不起
我尝试下鼠标来得到一个字

hi first sorry for my English i try to get a word under mouse

现在我的问题,如何让按钮的字体

now my problem how to get the font of button

我尝试使用

 IntPtr dc=    GetDC(button1.Handle);
 IntPtr last_font = SelectObject(dc, Font.ToHfont());
         Font fon = Font.FromHdc(dc);

但它给我的表格的字体

but it gave me the font of the form

和一些时间给我的错误
只有TrueType字体的支持。这不是一个TrueType字体

and some time gave me error Only TrueType fonts are supported. This is not a TrueType font

在一些与ch0kee答案试图

after some trying with ch0kee answer

我得到这个新的结果。

 StringBuilder Buff = new StringBuilder(1024);
 IntPtr fxx = GetTextFace(dc, 1024, Buff); 

但浅黄色总是返回系统

but Buff always return "system"

推荐答案

从MSDN:

不过,对于普通的DC,GetDC的受让人
  默认情况下,每次属性的DC
  它被检索。例如,该
  缺省字体为系统,该系统是一个
  位图字体。正因为如此,该
  处理被退回公共直流
  的GetDC不会告诉你什么字体,
  使用颜色,或刷时
  绘制窗口。为了确定
  字体,叫 GetTextFace

However, for common DCs, GetDC assigns default attributes to the DC each time it is retrieved. For example, the default font is System, which is a bitmap font. Because of this, the handle to a common DC returned by GetDC does not tell you what font, color, or brush was used when the window was drawn. To determine the font, call GetTextFace.

的GetDC功能

<击>

Font buttonFont = button1.Font;

多数民众赞成,不要混淆

thats all, don't get confused

MessageBox.Show(buttonFont.Name);

这我打印Microsoft无衬线默认值。

this prints me Microsoft Sans Serif default.

这是你需要什么?

这篇关于从其他应用程序的按钮字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆