【问题标题】:Transparency on Windows embedded desktopWindows 嵌入式桌面上的透明度
【发布时间】:2013-10-06 13:53:02
【问题描述】:

我正在为 Windows Embedded Compact 7 开发一个应用程序。我的要求之一是编写一个位于其他控件顶部的圆形按钮(例如 GridList)。

在我看来,这在 .Net 框架中是不可能的,但桌面图标提供了非常好的透明度,在其他图标之上也是如此。

为什么会这样,我可以在 C# 中使用这种透明度吗?

很抱歉遗漏了这么多信息:我使用 c# .net 3.5 为两个 500 MHz、1 GHz 的 ARM 处理器开发,我使用 Resco 组件,它们只支持背景透明度。他们还说,System.Windows.Forms.Control 不支持透明度。

【问题讨论】:

  • 图标格式旨在提供透明效果。您也可以获得具有非方形轮廓的控件,它的工作方式非常不同。无法猜测您正在使用的类库,您应该查看 Control.Region 属性或底层的 SetWindowRgn() winapi 函数。我猜你的嵌入式 Windows 版本是否支持这一点你会发现。
  • 我在 .net 上工作,我想我无法从这里访问 winapi 函数,对,尤其是无法访问表面上绘制的 winapi 函数
  • 当然可以,pinvoke 就是为此而生的。你不太可能真的需要它,没有人能从你记录不足的问题中分辨出来。
  • 非常感谢您到目前为止的回答。对不起,我的信息很差。是否缺少您需要帮助的信息。好的,我知道我可以通过 pinvoke 访问 winapi,但这可以在屏幕上绘制,对 .net 和 Resco Controls 绘制的控件透明吗?

标签: c# windows embedded


【解决方案1】:

只需复制以下代码,然后粘贴即可。只需制作一个命令按钮或标签或其他任何东西。背景将透明,仅显示命令按钮。

   Option Explicit
   Private Declare Function CreateRectRgn Lib _
   "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, _
   ByVal X2 As Long, ByVal Y2 As Long) As Long
   Private Declare Function CombineRgn Lib _
   "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _
   ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
   Private Declare Function SetWindowRgn Lib _
   "user32" (ByVal hWnd As Long, ByVal hRgn As Long, _
   ByVal bRedraw As Boolean) As Long
   Private Declare Function DeleteObject Lib _
   "gdi32" (ByVal hObject As Long) As Long

   ' Constants used by the CombineRgn function
   Private Const RGN_AND = 1
   Private Const RGN_OR = 2
   Private Const RGN_XOR = 3
   Private Const RGN_DIFF = 4
   Private Const RGN_COPY = 5

   Private Sub Form_Activate()
   Dim rgnForm As Long, rgnCombined As Long
   Dim rgnControl As Long, x As Long
   Dim formWidth As Single, formHeight As Single
   Dim borderWidth As Single, titleHeight As Single
   Dim ctlLeft As Single, ctlTop As Single
   Dim ctlWidth As Single, ctlHeight As Single
   Dim ctl As Control

   ' Calculate the form area
   borderWidth = (Me.Width - Me.ScaleWidth) / 2
   titleHeight = Me.Height - Me.ScaleHeight - borderWidth
   ' Convert to Pixels
   borderWidth = ScaleX(borderWidth, vbTwips, vbPixels)
   titleHeight = ScaleY(titleHeight, vbTwips, vbPixels)
   formWidth = ScaleX(Me.Width, vbTwips, vbPixels)
   formHeight = ScaleY(Me.Height, vbTwips, vbPixels)

   ' Create a region for the whole form
   rgnForm = CreateRectRgn(0, 0, formWidth, formHeight)

   rgnCombined = CreateRectRgn(0, 0, 0, 0)
   ' Make the graphical area transparent by combining the two regions
   x = CombineRgn(rgnCombined, rgnForm, rgnForm, RGN_DIFF)

   ' Make the controls visible
   For Each ctl In Controls
   ' Make the regions of controls whose container is the form visible
   If TypeOf ctl.Container Is Form Then
   ctlLeft = ScaleX(ctl.Left, vbTwips, vbPixels) + borderWidth
   ctlTop = ScaleX(ctl.Top, vbTwips, vbPixels) + titleHeight
   ctlWidth = ScaleX(ctl.Width, vbTwips, vbPixels) + ctlLeft
   ctlHeight = ScaleX(ctl.Height, vbTwips, vbPixels) + ctlTop
   rgnControl = CreateRectRgn(ctlLeft, ctlTop, ctlWidth, ctlHeight)
   x = CombineRgn(rgnCombined, rgnCombined, rgnControl, RGN_OR)
   End If
   Next ctl


   ' Set the clipping area of the window using the resulting region
   SetWindowRgn hWnd, rgnCombined, True
   ' Tidy up
   x = DeleteObject(rgnCombined)
   x = DeleteObject(rgnControl)
   x = DeleteObject(rgnForm)
  End Sub

【讨论】:

  • 非常感谢。我认为这不是 vb.net,对。你知道这是否可以从 c# 中获得。 .net3.5?
  • 非常感谢您的代码。只是为了确保,如果 Button 位于其他控件之上,则透明度或圆形外观应该可以工作......不仅仅是在背景上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-05-21
  • 1970-01-01
  • 2016-11-23
  • 1970-01-01
  • 2010-09-28
  • 1970-01-01
  • 2016-03-29
相关资源
最近更新 更多