控制使用VISUALSTYLES的边框颜色 [英] Border Color of Controls Using VisualStyles

查看:1370
本文介绍了控制使用VISUALSTYLES的边框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

微软的视觉样式的WinForms一直迷惑我。

Microsoft's visual styles for winforms have always befuddled me.

我想有一个面板坐在旁边的一个的TreeView ,只是有相同的VisualStyle边界。

I am trying to have a Panel sit next to a TreeView and just have the same VisualStyle border.

正如你所看到的,的TreeView 边框比我的画我尝试面板的不同。面板的边框样式设置为无。

As you can see, the TreeView border is different than my drawing attempts in my Panel. The panel's BorderStyle is set to None.

我已经试过这样:

  Rectangle r = new Rectangle(0, 0, panel1.ClientRectangle.Width - 1, panel1.ClientRectangle.Height - 1);
  using (Pen p = new Pen(VisualStyleInformation.TextControlBorder))
    e.Graphics.DrawRectangle(p, r);

和我试过这样的:

VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.TextBox.TextEdit.Normal);
renderer.DrawEdge(e.Graphics, panel1.ClientRectangle, 
         Edges.Bottom | Edges.Left | Edges.Right | Edges.Top,
         EdgeStyle.Sunken, EdgeEffects.Flat);

正确的视觉边框颜色或视觉元素任何建议使用?

Any suggestions for the correct visual border color or visual element to use?

推荐答案

这个问题并不仅限于的WinForms ......由于WinForms的的TreeView 控件是一个简单的包装围绕本地的Win32 TreeView控件,它的绘制相同的边框风格为TreeView控件将其他地方的系统,如Windows资源管理器。正如你所观察到的,3D边框样式看起来启用的确要比在Windows上的previous版本的外观风格不同。它实际上不看3D都—效果更接近,如果你设置边框 / FixedSingle ,不同之处在于它是一个有点暗比周围的树视图的人。

This issue isn't limited to WinForms... Since the WinForms TreeView control is simply a wrapper around the native Win32 TreeView control, it's drawing the same border style as a TreeView control would anywhere else in the system, such as Windows Explorer. And as you've observed, the 3D border style looks different with visual styles enabled than it did on previous versions of Windows. It actually doesn't look 3D at all—the effect is closer if you set the border to Single/FixedSingle, except that it's a little too dark compared to the one around the TreeView.

至于如何复制,对于一个面板控制,我想招不在于绘制的边缘的,而是绘画一个的背景的。

As far as how to replicate that for a Panel control, I think the trick lies not in drawing an edge, but rather in drawing a background.

有可能是一个更好的解决方案,如果你的P / Invoke的 DrawThemeBackground 函数直接与一些部件和状态的未暴露在.NET VisualStyleRenderer 包装,但这个看起来pretty的好对我说:

There might be a more elegant solution if you P/Invoke the DrawThemeBackground function directly along with some of the Parts and States that aren't exposed in the .NET VisualStyleRenderer wrapper, but this one looks pretty good to me:

VisualStyleRenderer renderer =
              new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
renderer.DrawBackground(e.Graphics, panel1.ClientRectangle);

   

   

   (TreeView的是在左边;面板在右边)

   (The TreeView is on the left; the Panel is on the right.)

。这仅仅是确定正确的颜色,然后使用标准的GDI +画图程序绘制一条线或两个控件周围的事情。

If you want to draw the border yourself and match the colors used when visual styles are enabled, you can do that, too. This would simply be a matter of determining the correct color, and then using the standard GDI+ drawing routines to draw a line or two around the control.

但是,不要火起来的Photoshop只是还没有!这些颜色都记录在一个文件名为 AeroStyle.xml ,位于Windows SDK中的包括文件夹。你有兴趣在全局值;这些:

But don't fire up Photoshop just yet! The colors are all documented in a file named AeroStyle.xml, located in the include folder of the Windows SDK. You're interested in the globals values; these:

<globals>
    <EdgeDkShadowColor> 100 100 100</EdgeDkShadowColor>
    <EdgeFillColor>     220 220 220</EdgeFillColor>
    <EdgeHighLightColor>244 247 252</EdgeHighLightColor>
    <EdgeLightColor>    180 180 180</EdgeLightColor>
    <EdgeShadowColor>   180 180 180</EdgeShadowColor>
    <GlowColor>         255 255 255</GlowColor>
</globals>

这篇关于控制使用VISUALSTYLES的边框颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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