Divide userControls events - vb.net

I developed a userControl that reacts on the MouseWheel and KeyDown event.
Dragging this userControl multiple times onto the same form I recognized that the problem was that only the first userControl reacts on the MouseWheel and the KeyDown event the others do nothing.
What must I do to solve this problem and each of the controls reacts on the MouseWheel and KeyDown effect even it becomes the focus.
Can anyone please provide a solution in VB.Net or C#?

I believe you want to place each control in one event handler separated by a comma like so:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
' Add event-handler code here.
End Sub
You can read more about it here: http://msdn.microsoft.com/en-us/library/3exstx90(v=vs.110).aspx

Related

VB.net (2010) Click-through on all controls

I'm having a application with quite a few tabpages. One function of my program is that if the user leaves the application for more than 3 minutes, I display the main tabpage where the most relevant information is shown (this is done by a timer called "back_to_main_tab"). So far so good. However in a few tabpages you can enter text and "take a pause" for more than these 3 minutes, and if that happens, the user is taken back to the main tab, without his/her consent, erasing his/her entered text.
I realize that this could be solved by enabling/disabling the back_to_main_tab-timer at strategic places, but I would like to solve it by resetting the timer each time a click is registered in the application regardless of what is is clicked. The reason for this is that the problem isn't unique for a certain tabpage, so I would like to have a "all-purpose"-fix for all tabpages.
Is this possible?
Thanks in advance
Jonas
You can write an Event Handler for each element where user can write.
For example
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
'Reset timer
End Sub
(and you could try KeyUp or KeyPress too).
So you can reset timer each time the user write something somewhere.
Btw if the 3mins pass (after last KeyPress), the back_to_main_tab erase all.
EDIT
Ok so you could make one function to Manage the CLICK event. And attach the function to all items form.
To attacch an event handler to alla element you could try something like this
Private Sub AddGenericEventHandler()
For Each Ctrl As Item In Form.Items
AddHandler Ctrl.Click, AddressOf MyClickHandler
Next
End Sub
And write the function that reset your timer
Public Sub MyClickHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Timer Reset
End Sub
This is an Idea. You have to write correctly the FOR EACH to catch all form items do you need.

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.

Tooltip showing twice

I'm showing a ToolTip on a certain button's MouseHover event. If I go over it once it works but if I leave, wait for the tooltip to disapear and come back on the button, it appears twice. I tried cancelling it on MouseLeave but it still appear twice the seocnd time.
Private Sub someButton_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles someButton.MouseHover
Dim tooltipSearch As New ToolTip()
tooltipSearch.Show("I'm a tooltip"), someButton)
End Sub
Private Sub someButton_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles someButton.MouseLeave
Dim toolTip As New ToolTip()
toolTip.GetToolTip(someButton)
toolTip.Hide(someButton)
toolTip.Dispose()
End Sub
Am I missing something obvious?
You are using the ToolTip not in the way it should be used (also look at the documentation :) ). It is just like any other control, start by dragging it onto your form (like you do with other controls).
If you have no dynamic text to be displayed in your tooltip, you can easily set the text in your constructor, using the method SetToolTip. If you do want some dynamic text, you can use this method in your MouseHover event.
Apart from that, you shouldn't do anything anything else. Just set the right delays on your tooltip and it should work all fine.
Private Sub someButton_MouseHover(sender As Object, e As System.EventArgs) _
Handles someButton.MouseHover
ToolTip1.SetToolTip(someButton, "My name is Steve chamba from south Africa")
End Sub
The answer about dragging the ToolTip control to the form is great. There is a subtlety with Button controls though. They seem to automatically set the tool tip to the text of the button, so if you also call ToolTip1.SetToolTip(myButton, "Button Text") then dot-net draws two copies of the tool tip text when you hover over the button.

How to call GridView RowEditing with button outside the GridView?

I have a gridview that is populated and a button outside the gridview that I want to enable editing on the selected row when clicked. I have this in the code behind. What goes in the btn_click event to invoke the grid view editing?
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As GridViewEventArgs)
GridView1.EditIndex = e.NewEditIndex
FillGrid()
End Sub
Protected Sub btnEdit_Click(ByVal sender as Object, ByVal e As System.EventArgs) Handles btnEdit.Click
What goes here??
End Sub
There is a problem with this approach.
"GridView1_RowEditing" is expecting a row index, so it can turn on "EditItemTemplate" accordingly, correct?
But If you want to click on button outside of Gridview and make entire Gridview editable, you shouldn't trigger GridView1_RowEditing, since you don't know what editindex to pass.
You need to implement editable control(textbox) as part of "ItemTemplate", not in "EditItemTemplate".
And visibility of this control would be controlled by the outside button you have created, which will flag the visibility on / off.
Please review following link, this demonstrates how it should be implemented.
http://highoncoding.com/Articles/219_GridView_All_Rows_in_Edit_Mode.aspx

how to focus a specific textbox in vb.net

I'm making a desktop application in vb.net. When I click the back button (placed by me) on any form it hides current form and shows previous form but when i go again to the form from which i had hit back button then the focus cue still remains on the back button but I want the focus to be on the first textbox on that form or any specific button on which I want.....How can i achieve this...
I have already used some code to shift focus from one textbox to another when i press enter key...but it doesn't work in the above mentioned case....I'm using vb.net in visual studio 2005...
This is the code i'm using for shifting focus among textboxes
Private Sub party_code_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles party_code.KeyDown
If e.KeyData = Keys.Return Then
party_name.Focus()
End If
End Sub
Can anyone help me on this????
You need to add a handler for either the form's Activated event:
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
party_name.Focus()
End Sub