开发者

get a button font from other applications

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

now my problem how to get the font of but开发者_如何学Goton

i try to use

 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

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

after some trying with ch0kee answer

i get new result with this

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

but Buff always return "system"


You should sent WM_GETFONT (0x0031) message to a button. See http://msdn.microsoft.com/en-us/library/ms632624(v=vs.85).aspx After processing that message handle of the font is returned.

Windows Forms uses pair message WM_SETFONT (0x0030) to set window font, you may see this via Reflector.NET in Control.OnFontChanged method.


From MSDN:

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 Function

Font buttonFont = button1.Font;

thats all, don't get confused

MessageBox.Show(buttonFont.Name);

this prints me Microsoft Sans Serif default.

This is what you needed ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜