Panel problem in visual basic 2010 - vb.net-2010

I created a panel and I added a link to other form using the code
Private Sub Panel1_Paint_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
AdminLogin.TopLevel = False
Me.Panel1.Controls.Add(AdminLogin)
AdminLogin.Show()
End Sub
The panel is displaying the adminlogin form which is inside the panel but when I click any buttons inside the adminlogin the adminlogin form blinks.
Why this blink is occurring ? how can I stop it?I had also added me.refresh inside the panel but it is not working?

Why this blink is occurring ?
It is blinking because you are adding a control every paint the panel which happens when you click on a button.
how can I stop it?
You only add the control if it is not already been added.
Of course this doesn't mean your overal design isn't flawed.

Related

How to dispose of a form within a panel upon closing the main form or upon another button click event?

Disclaimer: I only have beginner to slightly intermediate experience with VB.net
Hello, I was tinkering around with some design ideas for a project and I ran into a problem that I haven't found a solution to. I have a win form with some buttons and a panel. When the user presses a button, a border-less form is loaded into the panel. The problem is this: when the main form is closed, Visual Studio does not stop debugging, presumably because the forms in the panel are not disposed of.
Win Form image
The instance of the panel form is declared in the button click event. How can I destroy that instance from another sub? If I click another button, the first panel form doesn't go away. Is there a better way to accomplish this? I'm still learning, so I'm often not aware of all the different ways to solve a problem. Thanks everyone!
Public Class frm_Clients
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim search As New Search
search.TopLevel = False
search.Dock = DockStyle.Fill
Panel1.Controls.Add(search)
search.Show()
End Sub
Private Sub frm_Clients_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
' What should I write here?
End Sub
End Class
Here's a snippet of what to do to close the windows when another button is pressed.
For Each form In Panel1.Controls.OfType(Of Form).ToList()
form.Close()
Next
Then I would suggest that you set search.Owner to the Form holding the Panel. That means that when the Owner is closed, so are the children.
search.Owner = Me

Catching event when a control loses child control

Imagine this application in Vb.net, I have 2 panels and several buttons. I am moving buttons from a panel to other panel (through catching drag and drop events). I reached it.
Now I am trying the following:
Is there any way to raise an event from a panel when this panel loses some child button (or control)?
Thanks in advance.
Try this event when a control has added to the panel :
Private Sub Panel1_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Panel1.ControlAdded
End Sub
And this when a control has removed :
Private Sub Panel1_ControlRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Panel1.ControlRemoved
End Sub
The panel control doesn't seem to have an event that fires when its child control collection changes. source
The best thing to do would be handle this as part of the drop event. Presumably you have some code to determine if the button is to be moved. If this is true, call a function to do everything you want when a panel loses a control.

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

How Can I Create a Mouseover Tooltip on an Image in VB.NET?

Can I create a tooltip that will show up when a user moves his/her cursor over an image? I can't find such a property in Visual Studio, and I've scoured Google to no avail. I'm using an image in a PictureBox.
Here's to anyone out there on StackOverflow instead of some awesome Halloween party! Yay!
yea, for some reason the Picturebox doesnt have one.
imports System.Drawing
dim tt as new ToolTip()
tt.SetToolTip(picPicture, "This is a picture")
and dont worry, the weekend has only started, plenty of time to party.
Typically I create the interface then throw a ToolTip object from the Toolbox on to the form.
This then gives each object the "ToolTip" property (towards the bottom of the list) which can then be configured to your delight.
Drag a ToolTip control from the toolbox on the left onto your form (the designer will then put it below your form, since it's not meant to be visible normally). By default it will be named "tooltip1".
Then select your checkbox and go over to its properties window. You should see a property labeled "Tooltip on tooltip1" - set this to whatever you want. When you run the app and hold the mouse over your checkbox, you should see the tooltip text.
Assuming that you have added a picture box member with the WithEvents modifier you can use the following
Private tt As ToolTip = New ToolTip()
Sub OnPictureMouseHover(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.MouseHover
tt.Show("the message", Me)
End Sub
Sub OnPictureMouseLeave(ByVal sender As Object, ByVal e As EventArgs) Handles PictureBox1.MouseLeave
tt.Hide()
End Sub

VB.net form restore not showing form

I'm currently using VB.Net 2008.
The project has the "make single instance application" checkbox checked.
The application works by hiding the form when the form is minimized.
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide()
End If
End Sub
When the appropriate menu item is pressed within the notifyicon the form should show itself again.
Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ShowToolStripMenuItem.Click
Me.Show()
Me.WindowState = FormWindowState.Normal
End Sub
This works fine until the user tries to open the same application while the form is minimized. When this occurs the application will block a new instance of the application the user was trying to open as expected, however when the user then goes to show the form from the notifyicon's menu it will have seemed to open (it shows the form in the taskbar) but no window is shown.
At this point the window can be maximized and works as intended but by using the restore button the window will not be drawn but will still be shown in the taskbar.
If any help can be given on how to restore the form correctly from being hidden it would be most appreciated.
Thanks in advance
Just a couple of suggestions...
Instead of using Hide() and Show(), could you use the ShowInTaskbar property of the form instead?
Set it to false where you use Hide() and true where you currently use Show(), and see if that makes any difference.
Or perhaps set the WindowState to Normal before calling Show().