Remove the form close button - vb.net

I need a form without buttons, but with Text and icon;
So far, I managed to get it except the close "X" button;
Is there a way to remove it?
My code is below,
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Text = "Form with Icon and Text, but NO Buttons"
Me.Icon = New Icon("c:\test.ico")
Me.MaximizeBox = False
Me.MinimizeBox = False
End Sub

You can hide it using Me.ControlBox=false; in code or in properties change the
ControlBox option to false

You can workaround this by one of the following (two involves custom drawing on the title bar):
Disable the close button and custom draw on the title bar to hide it
Remove the close button and draw the icon on the title bar
check this link for custom title bar drawing : http://msdn.microsoft.com/en-us/library/windows/desktop/bb688195(v=vs.85).aspx
Best of luck

Related

How to avoid triggering MouseLeave event when hovering over a child control?

I am trying to make it so if you hover into a panel, it will change its color, and when you hover into a label, the panel will not change its color or go back to default, let me show pictures of what I am trying to explain:
If you didn't hover into anything, it would be at its default state:
If you hovered into it, panel color will change:
Then, if you hover into the label, panel color shouldn't change:
But instead, what it does is if you hover into the label, the panel color goes back to what its default was. This is my code:
Private Sub Panel13_MouseEnter(sender As Object, e As EventArgs) Handles Panel13.MouseEnter
Panel13.BackColor = Color.DarkGreen
End Sub
Private Sub Panel13_MouseLeave(sender As Object, e As EventArgs) Handles Panel13.MouseLeave
Panel13.BackColor = Color.LimeGreen
End Sub
How can I fix this problem? Is there any way to make the code clean or do I have to copy and paste the code and replace words?
You may use the GetChildAtPoint method to check if the mouse cursor is over a child control.
Replace the code in your MouseLeave event handler with the following:
Dim childControl = Panel13.GetChildAtPoint(Panel13.PointToClient(Cursor.Position))
If childControl Is Nothing Then
Panel13.BackColor = Color.LimeGreen
End If

How can i build an expandable and collapsible panel in VB.net?

I am looking for a way to make a panel which can be expanded and collapsed with a little arrow or button. I tried to find some examples, nothing worked so far. I tried to resize a group to 0px but the problem was when i did that the panel below it stayed in a same place, and I wanted it to slide upside, to save screen real estate.
I have a bunch of labels and text boxes which provides me data, but takes up a lot of space, and i grouped them together.
All help would be appreciated.
David
Simple in window Form
Insert a button and write code
Simple Example:
Public Class Form1
Dim panelshow As Boolean = False
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If panelshow = False Then
panelshow = True
Panel1.Show()
Else
Panel1.Hide()
panelshow = False
End If
End Sub
End Class
You can change name of variables, buttons and panels.
Set the panelshow to false if on application start your panel is collapsed otherwise to true if your panel is visible on startup and want to hide later by user.
Most people have answered the question about the collapse and expand, but to answer your question about "animation" so that it really has a good slide feel. For winforms i recommend this library on github DotNet Transitions
you can then write very simple code to give it animated transition.
using the transitions library, this code would collapse the panel in half a second:
Transitions.Transition.run(pnl, "Height",
initialValue:=pnl.Height,
destinationValue:=0,
transitionMethod:=New TransitionType_EaseInEaseOut(500)
)
If you want to use animation in win forms like when panel collapsed and the additional space should be covered with content then you can use
Control.Top() And Control.Left() Property ' control = your control name on which content is written like label, textbox etc.
Or second choice
To resize your content (like increasing the size etc).
Depend on your choice as I can't see your form presentation but advise you on the base of my imagination.
For example my panel height is 100 and when i collapsed I want my next control should move upward by 100 (Just suppose)
Suppose, my next control is RichTextBox
Then, you can do change here :
Public Class Form1
Dim panelshow As Boolean = True
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
If panelshow = False Then
panelshow = True
Panel1.Show()
RichTextBox1.Top = RichTextBox1.Top + 100
RichTextBox1.Height = RichTextBox1.Height - 100
Else
Panel1.Hide()
panelshow = False
RichTextBox1.Top = RichTextBox1.Top - 100
RichTextBox1.Height = RichTextBox1.Height + 100
End If
End Sub
End Class
Just add a method in addition to our previous code to do this thing.
Don't mind my grammar mistakes.
I am not perfect in English.
For more help comment or post your code (if you have any kind of problem)

How to make a Search Bar that looks for buttons

I want to make a Flow Layout Panel and fill it with a bunch of buttons. I want to have a Text box on the top of the form to search for a specific button. No clue on how. When the user searches, all other buttons will not be visible, only the button that its .text property matches will be visible.
Assuming search box is looking for the button's .Text property, that the textbox is named txtSearch, and the panel is named pnlButtons:
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
pnlButtons.SuspendLayout()
For Each c As Control In pnlButtons.Controls
c.Visible = False
Next
Dim matchingButtons = pnlButtons.Controls.OfType(Of Button).Where(Function(b) b.Text.StartsWith(txtSearch.Text))
For Each b As Button In matchingButtons
b.Visible = True
Next
pnlButtons.ResumeLayout()
End Sub

Darken a .Net Form

I have a 1080p touchscreen application. When a modal pops up, i want to emphasize that by darkening the main form.
Right now i use a second form, the size of the main form, that is black and has 50% opacity. Whenever a modal needs to appear, i open the opaque form, and then open the desired modal.
I feel this is a bit devious for my purpose. Its also not asshole-proof that when the user alt tabs, the forms will glitch out of sequence.
Is there a better way to achieve the darkening effect. Perhaps by darkening the main form from within itself?
Solved it myself by doing the following:
Place a hidden picturebox with dock:fill on the main form,
Take a screenshot of the current screen and darken it
assign the image to the picturebox and make it visible
open the modal in a new win
when the modal is dismissed
hide the picturebox
It really stupid that VB.net doesn't have this function built into it. Here's what you do to get around it:
Make a new form and call it Shade. I'm going to assume your main form is called frmMain. For the sake of clarity, lets assume the form you're launching is called dlgX.
Add the following lines in the Load event of dlgX (that's the sub with dlgX.Load or Me.Load or MyBase.Load):
Shade.Opacity = 0.001
Shade.Show()
Shade.Location = frmMain.Location ' Form location will only update if the form is visible.
Shade.Hide()
Shade.FormBorderStyle = Windows.Forms.FormBorderStyle.None 'This gets rid of the windows Titlebar and window border.
Shade.Size = frmMain.Size
Shade.BackColor = Color.Black
Shade.Opacity = 0.5
Shade.Show() ' Form size will only update the next time you show it.
Shade.TopMost = True ' Puts Shade over main form
Me.TopMost = True ' Puts current form over shade
Under all events that dismiss the form dlgX (OK.click, Cancel.click, etc), add the following lines:
Shade.Close
Or you can even make your own sub that handles all events where the form is closed:
Private Sub DispelShades(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosed
Shade.Close()
End Sub
This is way simpler than the PictureBox scenario and you don't have to mess with layering issues and having to ensure that the PictureBox renders on top of everything (for example, tabs really do not like having things rendered above them and they will not let you render a picture box above them). Rendering a black semi transparent form above your main form gets around all these headaches.
If you have multiple forms to shade, just make a Shad1, Shade2, Shade3 etc.
This is pretty obvious but it's worth stating: if you're shading the main form, you'll also want to make it unclickable by opening dlgX via dlgX.ShowDialog and not dlgX.Show
Here is some code, very similar to the method in Thomas's answer. Note to use the Darkness property in a Try...Finally block, to make sure you never leave the form in the dark state.
Public Class Form1
Private _PB As PictureBox
Public WriteOnly Property Darkness
Set(value)
If value Then
Dim Bmp = New Bitmap(Bounds.Size.Width, Bounds.Size.Height)
Me.DrawToBitmap(Bmp, New Rectangle(Point.Empty, Bounds.Size))
Using g = Graphics.FromImage(Bmp)
Dim Brush As New SolidBrush(Color.FromArgb(125, Color.Black))
g.FillRectangle(Brush, New Rectangle(Point.Empty, Bmp.Size))
End Using
_PB = New PictureBox
Me.Controls.Add(_PB)
_PB.Size = Bounds.Size
_PB.Location = Bounds.Location - PointToScreen(Point.Empty)
_PB.Image = Bmp
_PB.BringToFront()
Else
If _PB IsNot Nothing Then
Me.Controls.Remove(_PB)
_PB.Dispose()
End If
End If
End Set
End Property
Private Sub btnDialog_Click(sender As Object, e As EventArgs) Handles btnDialog.Click
Try
Darkness = True
MsgBox("Modal dialog")
Finally
Darkness = False
End Try
End Sub
End Class

Setting Focus on a Tab

I have a tab in a windows form called Wafer Map that has three sub-tabs. The First sub-tab is the called Map and has a Load and Skip button. I am trying to set the focus on the Wafer sub-tab on the Load button click. This is the following code I have tried to use.
Private Sub Load_Wafer_Layout_Map_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Load_Wafer_Layout_Map.Click
Wafer_Info.Enabled = True
Wafer_Info.Show()
End Sub
The Wafer_Info.Enabled = True is used to enabled all of the controls on the Wafer tab and works properly when the button is clicked. I have tried using .Focus() and .Show() to bring focus to the next tab but I am not have any luck getting to switch. Anyone have any suggestions?
Just set it:
tabControl.SelectedTab = yourTab
On the Tab Controls Tab Pages, just ensure you name the tab you are attempting to reference. Additionally, see MSDN TabControl.SelectedTab
The code that worked for me is Tab_WaferMap.SelectTab(1). Tab_WaferMap is my main tab and the 1 is the index of the sub tab I wanted to show
I came across this thread as i was looking for a solution to my own focus issue. I have a TabControl with many TabPages. Each TabPage is set to auto scroll due to overflowing content. The problem I ran into was the mouse scroll wheel would not function if the TabPage did not have focus. Since there is not an event for each tab click it made setting focus to each TabPage a challenge. It was not hard, but a challenge none the less. So, here is my code (assuming auto scroll true).
On form load sets focus to main TabPage:
Private Sub frmParent_Load(sender As Object, e As System.EventArgs) Handles Me.Load
TabControl1.TabPages(0).Focus()
End Sub
Sets focus to current TabPage by getting the index then setting focus.
This is triggered by TabControl1.SelectedIndexChange event.
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
Dim intTabIndex As Integer = TabControl1.SelectedIndex
TabControl1.TabPages(intTabIndex).Focus()
End Sub
I hope someone find this useful. It was very useful for me.
Joshua
You can also set the Selected Index of the tab (and sub-tab) using a (zero based) numeric value:
TabParent.SelectedIndex = 3
TabSub.SelectedIndex=2