我在网上找到了以下代码:http://code.msdn.microsoft.com/windowsdesktop/VBWinFormExAeroToClient-f0d42b34
我一直在调整它以使用我自己的应用程序。
我需要一个小型500x30像素表格。
我一直在阅读该链接中提供的演示代码,但我似乎无法找到修改"演示表格的位置"大小/形状。
理想情况下,我只是喜欢这个演示版的1个版本,在加载时会应用完整的透明区域。 (我可能想出来的)
我遇到的问题是,我在哪里可以在这个演示表上绘制对象?
我已经获得了GlassForm,但是对象和其他属性并未传递给" DemoForm"。
我不知道为什么。
长话短说,我想要一个基本的透明表单,我可以添加其他样式属性,如大小,表单边框,以及文本框,标签和按钮等对象。
我似乎无法通过给定的演示来实现这一目标。
我能够更改表单大小/边框,但在调用DemoForm时使用以下代码。
DemoForm.Show()
DemoForm.Width = (500)
DemoForm.Height = (30)
DemoForm.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
DemoForm.TopMost = True
但我仍然无法弄清楚如何修改表单设计器中的from,以及如何将控件添加到新生成的表单中。
答案 0 :(得分:0)
设置表单不透明度:
DemoForm.Show()
DemoForm.Opacity = 0.85
DemoForm.Width = (500)
DemoForm.Height = (30)
DemoForm.TopMost = True
不透明度可以设置在0和1之间。
答案 1 :(得分:0)
简而言之,您可以更改表单的不透明度,但子控件的不透明度也会更改。为了解决这个问题,您可以将Form.BackColor
属性和Form.TransparencyKey
设置为您的表单未使用的颜色。对于我的测试,我选择了Color.Pink
,但您可以根据需要进行更改。
注意:当您更改此行为时:标签,复选框和单选按钮背景颜色不能透明,任何其他颜色都可以。
我创建了一个名为:TransitionForm的类,它继承了您需要继承的System.Windows.Forms.Form
控件,以使其他表单透明。
这是TransitionForm类......
Imports System.ComponentModel
Public Class TransitionForm
Inherits System.Windows.Forms.Form
Private intBorderThickness As BorderThick
Private clrBorderColor As Color
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer = 0
Private MouseDownY As Integer = 0
Public Enum BorderThick
Light
Medium
Thick
End Enum
<System.ComponentModel.Description("Select border thickness")>
Public Property BorderThickness As BorderThick
Get
Return intBorderThickness
End Get
Set(ByVal value As BorderThick)
intBorderThickness = value
Me.Refresh()
End Set
End Property
<System.ComponentModel.Description("Select border color")>
Public Property BorderColor As Color
Get
Return clrBorderColor
End Get
Set(ByVal value As Color)
clrBorderColor = value
Me.Refresh()
End Set
End Property
Sub New()
InitializeComponent()
Me.Size = New Size(500, 30)
Me.BorderColor = Color.LightBlue
Me.BorderThickness = BorderThick.Light
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End Sub
Private Sub TransitionForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.BackColor = Color.Pink 'This can be what ever color you want as long as it's not on your form...
Me.TransparencyKey = Color.Pink 'This can be what ever color you want as long as it's not on your form...
End Sub
Private Sub TransitionForm_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub TransitionForm_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If IsFormBeingDragged Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
Private Sub TransitionForm_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub TransitionForm_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim pPen As Pen = Nothing
Select Case BorderThickness
Case BorderThick.Light
pPen = New Pen(BorderColor, 1)
Case BorderThick.Medium
pPen = New Pen(BorderColor, 3)
Case BorderThick.Thick
pPen = New Pen(BorderColor, 5)
End Select
e.Graphics.DrawRectangle(pPen, 0, 0, Me.Width - 1, Me.Height - 1)
End Sub
End Class
现在你有了这个类,你需要将这个类继承到你想要使用它的表单中。
例如:双击要使其透明的表单的设计器文件。然后你需要输入:
Inherits TransitionForm 'This is the new class
您也可以扩展此新类的属性。我包括的其中一些是:BorderThickness(边界的大小)&amp; BorderColor(边框的颜色)。我还实现了对这个新表单的拖放操作,因为当您关闭FormBorderStyle.None
时,您无法再拖动表单。
这是一个快速模拟这个控件,它不是最好的,但我相信你可以告诉它做你想要的;还 它仍然具有您想要的控件的