how to set transparent opacity to panel - vb.net

how do i set panel transparent like opacity to 0. i set the panel by program and it was on top of video player. the code is like this
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ', AxVLCPlugin21.Click
Dim panelx As New Panel
panelx.Visible = True
panelx.Size = New Size(AxVLCPlugin21.Width, CInt(AxVLCPlugin21.Height / 2))
panelx.BackColor = System.Drawing.Color.Transparent
AxVLCPlugin21.Controls.Add(panelx)
panelx.BringToFront()
'AddHandler panelx.DoubleClick, AddressOf panelx_click
End Sub
the result is like this
then i try to play the video it only show the half
the reason i use panel is to pause the video (set panel on top of video by transparent), when i click the panel since the video doesn't support click event
update
i put the code in usercontrol1
still got me an error, although i have insert the code in designer. too clarify i put the code designer after below the main designer code. i have tried to put only inherit panel code in main designer code but it only take one inherit only.

The best way to do this is to create a custom control that inherits the panel class and overrides CreateParams and OnPaintBackground with this bit of code:
(Props to Zohar Peled for his post here)
Replace the code behind with:
Public Class TransparentPanel
Inherits System.Windows.Forms.Panel
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
' Make background transparent
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H20
Return cp
End Get
End Property
Protected Overrides Sub OnPaintBackground(e As PaintEventArgs)
' call MyBase.OnPaintBackground(e) only if the backColor is not Color.Transparent
If Me.BackColor <> Color.Transparent Then
MyBase.OnPaintBackground(e)
End If
End Sub
End Class
And replace the designer code with:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class TransparentPanel
Inherits System.Windows.Forms.Panel
'Control overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Control Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer. Do not modify it
' using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
The code you're replacing may look different initially, but using this code will ensure everything works.
NOTE: This code will make the panel transparent if the backcolor is set to Transparent or Control (which depending on the control is normally actually the same as transparent.)
I tried to find an updated resource for creating and implementing a custom control, but I wasn't able to find a maintained resource. So here are some step by step instructions on how to create a custom control.
To create custom control usable in the designer:
(I'm using Visual Studio 2015 for the examples below, it may appear different in other versions.)
1. Create new Windows Forms Control Library
2. Then right click and rename your control to "TransparentPanel" (or
whatever name you like)
3. Paste the code above into the code behind and the designer code respectively (changing the class name if you didn't use "TransparentPanel")
4. Build the project (this will create the .dll you will need to reference in your main project)
5. This one is optional, but it is good to store your DLLs somewhere consistent, other than the project bin folder, so, optionally, navigate to the control library bin folder and copy the created DLL to another location you want to store your custom DLLs.
6. Go to the project you want to use the control in, and right click in the toolbox and click "Choose Items..."
7. Make sure you are on the the ".NET Framework Component" tap and select "Browse".
8. Navigate to the bin folder of the control library (or where ever you stored the DLL), select the control and click "Open".
9. You will see the TransparentControl selected now in the "Choose Toolbox Items" form. Click "OK"
10. Then you should be able to find the control under "General" section.
11. Drag and drop the control onto your form.
NOTE:
The control may not look transparent in the designer, but on runtime it should do what you are looking for.
I hope this works for you!

Related

Alt + Tab is not showing the forms when Form.Owner is set

I have an application (VB.NET) with the name MainForm and other child forms without using MDI Container. The child forms are based on assign to the MainForm with Me.Owner = MainForm
When I press Alt + Tab, for switching between these form, the Windows is showing the MainForm only unless I remove Me.Owner = Nothing it's working as expected again.
I tried Call SetWindowLong on Onload function but not luck. I am still looking for the solution.
EDIT
Actually it's easy for reproduced, I created very simple project.
Simple Application
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Form2 As New Form2
Form2.Owner = Me ' Alt+Tab only Show Form1, not showing Form2.
Form2.Show()
End Sub
Disable Owner property is working fine again.
Please check my teamview recording. Actually it's original form without change anything.
#Royce Your solution still not working, it's throw Win32Exception from my side.
Try to change the ShowInTaskbar Property to True.
Ran your example on my machine (Windows 10) and both windows showed up in my Alt-Tab menu (screenshot).
In your original program, make sure that the FormBorderStyle property of either window is not set to one of the two ToolWindow options and that ShowInTaskbar is True.
Otherwise, you might try changing the CreateParams of your second form to exclude WS_EX_TOOLWINDOW extended style bit by doing something similar to this:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle And (Not &H80)
Return cp
End Get
End Property

Changing the color of a selected item in a listbox/listview

I'm reasonably new to programming and soon I will be creating a program and would like to change the colour of a selected row via a button click.
I have been attempting this but I don't even know where to begin. If someone could point me in the correct direction it would be much appreciated.
Thanks ^.^
You could simply create a new control, then change the designer to inherit from the listbox control.
the designer code would then look something like this (vs2010):
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class UserControl1
Inherits ListBox
'UserControl overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
To see the designer code, select "Show All Files" (button at the top of your solution explorer). Then expand the new control node in your solution explorer.
then change the line:
Inherits System.Windows.Forms.UserControl
to:
Inherits ListBox
and finally delete delete the line:
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Hope that helps.

Control disappearing in designer

Consider an empty WinForms application created using VS2010.
It has a custom TextBox class with the following code:
Public Class DummyTextBox : Inherits TextBox
Private Const FONT_SIZE As Single = 14.25!
Private Const FONT_FAMILY As String = "Microsoft Sans Serif"
Private Sub Me_ParentChanged(sender As Object,
e As System.EventArgs) Handles Me.ParentChanged
'this one does not work, it causes designer
'to lose its controls once in a while
Me.Font = New Font(Me.Parent.Font.FontFamily, FONT_SIZE)
'if I use a constant value instead, like below, it works fine
'Me.Font = New Font(FONT_FAMILY, FONT_SIZE)
End Sub
End Class
So basically a TextBox with increased font size, same family as the parent form.
What happens is that after being put on the form, and then built, the control sometimes disappears from designer view. If you run the project, it's usually showing fine. Close/reopen a form and it's there again.
Sometimes, however, the control will disappear completely (I was not able to reproduce this 100% of the time), so you'd have to add it again and set the properties. If multiple controls are placed in one shot, usually only one of them disappears like that. Controls are more likely to disappear after being moved around on the form.
What's going on?
According to my research, Me.Parent can sometimes be Nothing inside ParentChanged, so that line throws an exception, which is never displayed to the user (it only happens at design time). Putting a Try/Catch around it helps verify this fact. It looks like Windows Form Designer likes detaching controls and attaching them back at its own discretion.
To solve the problem, need to verify there exists a parent, and only then set the Font.
So changing this:
Me.Font = New Font(Me.Parent.Font.FontFamily, FONT_SIZE)
To this:
Dim parent As Control = Me.Parent
If parent Is Nothing Then Return
Me.Font = New Font(parent.Font.FontFamily, FONT_SIZE)
Makes the issue go away and does not affect runtime in any way.

vb.net How to get working scrollbars when moving nested form controls inside a parent panel

I have a container (a panel) which can contain multiple Form controls.
(Form.TopLevel = False)
When the user moves the Forms around I would like to display scrollbars when a form is out of the panel bounds.
When I register the Form.Move event, I can set the AutoScrollPosition. This works unless the user uses the scrollbars.
The problem is that the form.move event is also fired when the scrollbars are used. The result is that the scrollbars don't work. (And I have currently no idea how to find out whether the form has been moved by the mouse or by the scrollbar)
So the question is: How can I make the scrollbars of the panel appear/work when a form (or multiple) forms of the panel exceed the boundaries? I think there must be a simpler way than to handle the move event..
Note:
The panel is placed inside a Infragistics DockableControlPane. (Managed by an UltraDockManager)
(So there are multiple panels which contain at least one form per panel)
The reason is that the "panels" should appear as tabs, can be moved around using the DockManager and display their "sub" forms (Which also can be moved around on their panel).
Any idea would be great
It looks like the LocationChanged event could be used. Example with only one form:
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
Dim f As New Form
f.TopLevel = False
AddHandler f.LocationChanged, AddressOf Form_LocationChanged
Panel1.Controls.Add(f)
f.Show()
Call Form_LocationChanged(f, EventArgs.Empty)
End Sub
Private Sub Form_LocationChanged(sender As Object, e As EventArgs)
With DirectCast(sender, Form)
Panel1.AutoScrollMinSize = New Size(.Bounds.Right, .Bounds.Bottom)
End With
End Sub
Using an MDI form seems to be more appropriate though for something like this.

How to make custom properties in Properties Window to refresh upon change via code?

Here is some code:
ReadOnly Property X() As Integer
Get
Return PointerX
End Get
End Property
ReadOnly Property Y() As Integer
Get
Return PointerY
End Get
End Property
Private Sub Proj_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
PointerX = e.X
PointerY = e.Y
End Sub
I want to make the Properties Window to update the properties for X and Y at each MouseMove, so they become immediately visible for the user. I know it is stupid, but it is my assignment.
Can somebody help me?
I would highly recommend pursuing this project in WPF using the OnPropertyChanged event to notify all listeners when a property is changed. Then, make the PropertyGrid listen to all such events on the object which it represents, updating the appropriate property. WPF is great for this stuff...
That's not a Windows Form project.
You created a Windows Control Library which includes a default UserControl and when you "run", you are seeing your UserControl being hosted, which is why you are seeing a PropertyGrid control.
You need to create or add a new project to your solution that is a Windows Form Application, and set it as the "Starup Project" (right mouse click the Form project and select "Set as Startup Project").
After you rebuild your solution, your UserControl "Proj" will be available from the ToolBox, which you can place on your form.