Is there an easy way to do transparent forms in a VB .NET app? - vb.net

I'm writing a simple app that's going to have a tiny form sitting in one corner of the screen, updating itself.
I'd really love for that form to be transparent and to have the transparency be user-configurable.
Is there any easy way to achieve this?

You could try using the Opacity property of the Form. Here's the relevant snippet from the MSDN page:
private Sub CreateMyOpaqueForm()
' Create a new form.
Dim form2 As New Form()
' Set the text displayed in the caption.
form2.Text = "My Form"
' Set the opacity to 75%.
form2.Opacity = 0.75
' Size the form to be 300 pixels in height and width.
form2.Size = New Size(300, 300)
' Display the form in the center of the screen.
form2.StartPosition = FormStartPosition.CenterScreen
' Display the form as a modal dialog box.
form2.ShowDialog()
End Sub

Set Form.Opacity = 0.0 on page load
I set something like what your talking about on an app about a year ago. Using a While loop with a small Sleep you can setup a nice fading effect.

I don't know exactly what you mean by transparent, but if you use WPF you can set AllowTransparency = True on your form and then remove the form's style/border and then set the background to a color that has a zero alpha channel. Then, you can draw on the form all you want and the background will be see-through and the other stuff will be fully visible. Additionally, you could set the background to a low-opacity layer so you can half see through the form.

You can set the Form.Opacity property. It should do what you want.

Related

Word VBA - easily remove form frame?

I'm trying to create a user entry form which both captures the users input and displays a status update message. The slickest way I think of doing it is to have my modal form for the user entry display over a modeless form. After the user enters their info and clicks OK, the info from the modal form is copied to the modeless form, the modal form is closed and status updates get pushed to the modless form as things change during processing:
Hopefully, with a lot of messing about with positions, it will look relatively seamless. My challenge is getting rid of the frame on my modal form. I've done a lot of searching and it seems to involve completely redrawing the form from base libraries - is there seriously no easier way to do it?
I would not use a 2nd form but just place a simple Frame on top of your form. When you want to show the "modal form", just set the visibility of the frame to True, and when you want to hide it, set it to False - all controls (in your case, the input field and the OK and Cancel button) that are placed on the frame are automatically shown or hidden.
If you have controls outside the "modal form" frame that you don't want to be active at that time, set them to enabled = False. You could handle this with a simple routine within your form.
In this example I have a frame FrameModal painted on top of the form. Note that this frame could be places over other controls.
Option Explicit
Private Sub UserForm_Activate()
showHideModalFrame False
End Sub
Private Sub buttonShowModal_Click()
' Show the "modal" dialog
showHideModalFrame True
End Sub
Private Sub buttonOK_Click()
' Do your stuff here...
Me.tbUpdates = Me.tbUpdates & vbCrLf & Me.tbInput
' Hide the "modal" dialog"
showHideModalFrame False
End Sub
Private Sub showHideModalFrame(show As Boolean)
Me.FrameModal.Visible = show
Me.buttonShowModal.Enabled = Not show
End Sub
Start the form
Click the show button:

VB.NET - Change form size by screen resolution:

I'm presuming the answers very simple, but here's the issue, my option menu has two parts, normal settings and advanced settings, the advanced settings are accessed by pressing the advance button, fairly basic. This will make the form bigger unveiling the further settings, but the only problem I have is making a form bigger on different resolution does not make it bigger by the same factor - to put what i saying into context, if i increase the size of my form on a standard 1080p monitor, then run my program on a laptop resolution of 1366 by 768, the form will be much smaller than what i got it to draw on the 1080p resolution screen.
Heres the code I'm using to increase the form size:
Private Sub Advance_btn_Click(sender As Object, e As EventArgs) Handles Advance_btn.Click
If advanced = 0 Then
Me.Size = New Drawing.Size(262, 198) ' will increase form size
Advance_btn.Text = "<" ' text for button changes to know i have pressed the button - (to '<')
advanced = 1
ElseIf advanced = 1 Then
Me.Size = New Size(262, 85) ' will decrease form size
Advance_btn.Text = ">" ' text for button changes to know i have pressed the button - (to '>')
advanced = 0
End If
End Sub
The form is also without borders, if that makes somewhat a difference, thanks.
Me.Height = Screen.PrimaryScreen.Bounds.Height
Me.Width = Screen.PrimaryScreen.Bounds.Width * 0.6
In this example I use for years, the width is set to 60% of the screen width. This is in an IF statement, where I check if the user has a 4K monitor, if not, a full-screen mode is set at application start-up. You can, perpahs, do a similar thing with your drawing area.

Control Tip Text on dual monitors?

I have a small user community for an application that contains a lot of user forms and fields.
I have added ControlTipText on most of the fields as helper/reminder.
The problem occurs when the user form is opened/displayed on the secondary monitor, the yellow stuff
(ControlTipText) is popping up on the right edge of the primary monitor.
Not a huge issue, but annoying.
Anyone who has a fix for this?
Same issue, resolved by:
Creating a label with a distinctive background colour positioned over the control that you want to write tip text for
Initialise the UF with the label visible = false, e.g. Userform1.label1.visible = false
use the "mousemove" event to write code to show the label
Private Sub TextBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
label1.visible = true
'position label as desired
End Sub
use the click or mousemove event on the label this time to banish the tool tip. You will have lots of labels over controls in the VB editor.
As an alternative I creatie a label with an "Information" icon that is clickable to unhide the tooltip label rather than mousemove event sometimes
As ControlTipText is a property of the Text Box it doesn't have any members which would allow you to adjust it's position.
It seems like the only way the issue can be resolved is by viewing Excel on your primary monitor. If it's useful, you can force Excel to move to the primary monitor with something like this:
With Application
.WindowState = xlNormal
.Left = 0
.Top = 0
.WindowState = xlMaximized
End With

VBA: Dynamic Adapting Scrollbar

I have a user form containg a frame. During runtime, the user can add controls to this frame. Ultimately, the added controls can exceed the size of the frame. In this case I would like to increase the insideheight of the frame. So my vertical scrollbar does cover the whole area.
frm.ScrollHeight = .InsideHeight
How do I do this?
The .InsideHeight is not responsible for the scrollbar. However, the .ScrollHeight is. While adding new controls, this height must be increased.
When adding a new set of controls execute this:
Exchange 50 with the height of your control.
Dim scrHeight As Integer
With frm
scrHeight = .ScrollHeight
.ScrollHeight = scrHeight + 50
End With

How to remove ToolStripButton´s checked blue rectangle

I have a ToolStripButton with CheckOnClick property set to true. When it is clicked the Checked property becomes true and a blue border appears surrounding the button and it remains there as long as in the checked state. I want to remove this border, because I change the background color myself to indicate that the button is selected. How could I do that? I tried with ToolStripRenderer but I could not found the way.
Implementing your own ToolStripRenderer should give you what you're looking for. I'm not real familiar with using these, but I was able able to get the functionality I believe you are looking for with the following implementation.
Public Class BorderlessToolStripRenderer
Inherits Windows.Forms.ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderButtonBackground(e As System.Windows.Forms.ToolStripItemRenderEventArgs)
Dim button = TryCast(e.Item, ToolStripButton)
If (button IsNot Nothing AndAlso button.Checked) Then
e.Graphics.Clear(Color.Yellow)
Else
MyBase.OnRenderButtonBackground(e)
End If
End Sub
End Class
I'm assuming you're using ToolStripProfessionalRenderer, so I inherited that one and just omit the standard background rendering when the button is in the checked state. This keeps the mouse over indicator, but omits the border when checked and instead renders a yellow background.
And of course, to use this class, you just need to set the Renderer property on your ToolStrip like this
Me.ToolStrip1.Renderer = New BorderlessToolStripRenderer()