Hello guys!!!
I have found this class which gives shadow on a borderless form. It's written in C# and I had to convert it in VB.NET so to use it in my project. My problem is that the converter can't convert some parts correctly and I get some errors which I can't managed to fix.
First errors located here...vb.net Code:
Public Sub New(f As Form) Owner = f ShadowRadius = 10 ShadowColor = Color.Black 'This bit of code makes the form click-through. ' So you can click forms that are below it in z-space Dim wl As Integer = Win32.GetWindowLong(Handle, -20) wl = wl Or &H80000 Or &H20 Win32.SetWindowLong(Handle, -20, wl) FormBorderStyle = FormBorderStyle.None ' bind event Owner.LocationChanged += UpdateLocation() Owner.FormClosing += Function(sender, eventArgs) Close() Owner.VisibleChanged += Function(sender, eventArgs) If Owner IsNot Nothing Then Visible = Owner.Visible End If 'Owner.Activated += (sender, args) => Owner.BringToFront(); End Function End SubLine 16: Error:BC32022 'Public Event LocationChanged As EventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.Line 16: Error:BC30491 Expression does not produce a value.Line 17: Error:BC32022 'Public Event FormClosing As FormClosingEventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.Line 18: Error:BC32022 'Public Event VisibleChanged As EventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.And the rest here...Line 25: Warning:BC42105 Function '<anonymous method>' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
vb.net Code:
Private Function DrawShadow() As Bitmap ' 窗体的大小 Dim fw As Integer = Owner.Width + ShadowRadius * 2 Dim fh As Integer = Owner.Height + ShadowRadius * 2 Dim gp As New GraphicsPath() gp.AddRectangle(New RectangleF(0, 0, fw, fh)) 'gp.AddEllipse(ClientRectangle); 'gp.AddRectangle(new RectangleF(ShadowRadius + WithBorderRadius ' , ShadowRadius + WithBorderRadius, ow, oh)); Dim pgb As New PathGradientBrush(gp) pgb.CenterPoint = New PointF(fw / 2.0F, fh / 2.0F) pgb.CenterColor = ShadowColor pgb.SurroundColors = New() {Color.Transparent} 'pgb.ScaleTransform(1,1); Dim bitmap As New Bitmap(fw, fh) Dim g As Graphics = Graphics.FromImage(bitmap) 'var ctr = new Bitmap(Width, Height, CreateGraphics()); 'g.DrawImage(ctr, new Point(0,0)); 'var g = CreateGraphics(); g.FillPath(pgb, gp) pgb.Dispose() gp.Dispose() ' Width = fw Height = fh Return bitmap End FunctionLine 17: Error:BC30182 Type expected.Line 17: Error:BC37259 Tuple must contain at least two elements.Line 17: Error:BC30311 Value of type '(?, ?)' cannot be converted to 'Color()'.If for some reason you need to check the full vb.net converted version of the class, I have uploaded it here. Thank you in advance!!!Line 17: Error:BC37280 'New' cannot be used with tuple type. Use a tuple literal expression instead.![]()





Reply With Quote
