How to suppress the MouseMove event in particular case? - events

My issue is that I need to change the mouse pointer's position within the MouseMove event, which causes infinite recursion. I need to suppress the MouseMove event which Me.Cursor.Position = newpos generates. How can I do that?
I read about Me.EnableEvents = False but this is not valid for Visual Studio 2005 and I could not find an equivalent.

What exactly are you trying to do? Maybe there's a better way. But assuming this is what you want, you could unsubscribe the event handler in your MouseMove event before changing the cursor position using RemoveHandler. Just add it back when you're done:
Public Class MyForm
Private Sub MyForm_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseMove
UnsubscribeEvents()
' change mouse pointer's position here...
ResubscribeEvents()
End Sub
Private Sub UnsubscribeEvents()
RemoveHandler Me.MouseMove, AddressOf MyForm_MouseMove
End Sub
Private Sub ResubscribeEvents()
AddHandler Me.MouseMove, AddressOf MyForm_MouseMove
End Sub
End Class

Related

Form closing Event in VB6?

Just wanted to ask, Is there a form_closing event equivalent in VB6? (.bas). the reason I ask is that I wanted to prevent first closing the application if there's an open sub-window.
something like this.
Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If hasSubWindow Then
MessageBox.Show("You currently have active sub-window(s)")
e.Cancel = false
End If
End Sub
There are three events: Form_QueryUnload(Cancel As Integer, UnloadMode As Integer), Form_Unload(Cancel As Integer) and Form_Terminate().
Form_QueryUnload fires before the Form_Unload where setting Cancel to any value other than 0 cancels the unload and UnloadMode indicates the cause of the unload event.
See https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-basic-6/aa445536(v=vs.60)?redirectedfrom=MSDN
Form_Unload takes an integer that if set to any value other than 0, cancels the Unload.
The Unload event procedure is where programmers usually put cleanup code. The Unload event fires after the QueryUnload event. The Unload event procedure takes a single parameter, the Cancel parameter. Unload's Cancel parameter works the same as QueryUnload's Cancel parameter.
The Terminate event happens when the instance of the form has been completely unloaded and all the form's variables have been set to Nothing. The Terminate event happens only when you explicitly set the form to Nothing in your code during or after the Unload event procedure.
Source: https://www.freetutes.com/learn-vb6-advanced/lesson6/p5.html
In your case, you probably want to put code into Form_QueryUnload or Form_Unload that checks if there are any other open forms.
Private Sub Form_Unload(Cancel As Integer)
If hasSubWindow = True Then
MsgBox "You currently have active sub-window(s)", vbInformation, "Confirm"
Cancel = 1
End if
End Sub

MouseDown not triggered in tablet mode

If my users (who are handicapped children) press their finger on an icon in my application, something should happen right away.
To do that, I react to the MouseDown event.
What I expect is the following:
User touches screen with finger: MouseDown
User releases finger from screen: MouseClick, MouseUp
However, in Windows 10 with Tablet Mode activated, this does not work.
Instead, the sequence "MouseDown", "MouseClick", "MouseUp" is triggered only when the finger is lifted.
How could I make it so that I get a notification about the finger touch?
Sample code in VB.NET:
Public Class Form1
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
Me.ListBox1.Items.Add("mousedown")
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
Me.ListBox1.Items.Add("mouseup")
End Sub
Private Sub Form1_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
Me.ListBox1.Items.Add("mouseclick")
End Sub
End Class

visual basic multiple toolstripmenuitems to perform the same on click

I am new here. So apologize in advance if not wording question properly.
I am developing an application (VS2013, Visual Basic) that using multiple menu items in the MenuStrip. When item is clicked the identical function is called - the Tab is created and appropriate form is loaded.
i.e.
Private Sub XXXMNU0039_Click(sender As Object, e As EventArgs) Handles XXXMNU0039.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim imgnm As String = "XXXMNU0039"
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
Private Sub XXXMNU0040_Click(sender As Object, e As EventArgs) Handles XXXMNU0040.Click
Dim f1 As New frm_B05_03_SalesQuotesReports
Dim imgnm As String = "XXXMNU_Reports"
Call XXXTabPages("Sales Quotes Reports", f1, imgnm)
End Sub
....
I am wondering is there is a way to create a "global" default "on click event" for all menu items that will accomplish the same thing by default. I have all the relevant information for each menu item stored in a table and hope to avoid creating "on click" for each item.
Thanks in advance.
You could have the same handler for the click event of your ToolStripMenuItems.
Just add, after the first Handles XXXMNU0039.Click the event to handle for another ToolStripMenuItem and so on
Oviously, then problem is how to differentiate the various ToolStripMenuItem that calls the same event handler. But in the event arguments there is the Sender object that represent the current ToolStripMenuItem that has called the event.
Just DirectCast to a ToolStripMenuItem and read its name to pass the correct parameter to the XXXTablPages method
Private Sub menuItemHandler_Click(sender As Object, e As EventArgs) _
Handles XXXMNU0039.Click, XXXMNU0040.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim itm = DirectCast(sender, ToolStripMenuItem)
Dim imgnm As String = item.Name
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub

Copy event handler assignment to another instance

I am trying to create a clone of an object instance.
Creating the new instance and copying property values is no problem but the original object instance has some event handlers assigned to its events. How can I copy event handlers to the new instance?
Thanks..
Here is a code sample...
Public Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(sender.Name + "was clicked")
End Sub
Public Sub CloneButton()
Dim newButton = New Button
newButton.Name = Button1.Name + "_Clone"
newButton.Text = Button1.Text
newButton.Width = Button1.Width
newButton.Height = Button1.Height
'Some code here to copy Button1's event handler ButtonClick,
'so when the new button is clicked "Button1_Clone was clicked" is displayed.
End Sub
This is freakin' old, I know, but I can't believe this guy didn't get an answer, it's been answered on SO before, right here.
Just one thing; in the example code given, miHandler will be Nothing if there is no event handler attached to the sourceObject, you should test for that.

ModalPopupExtender + ASP.NET AJAX: Can't page grid

I'm trying to page and sort my DataGrid which is inside a ModalPopupExtender but I can't page it in any way, already tried with <Triggers>, put the UpdatePanel inside, outside, in the middle, and it does NOT work. Modal popup does not get closed but the grid just disappears. Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
SqlServerDS.SelectCommand = "SELECT * FROM emp WHERE name LIKE '%" & txtSearchName.Text & "%'"
BindData()
End Sub
Private Sub BindData()
grdSearch.DataSource = SqlServerDS
grdSearch.DataBind()
End Sub
Private Sub grdBuscaPaciente_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdSearch.PageIndexChanging
grdSearch.PageIndex = e.NewPageIndex
BindData()
End Sub
Inside the Designer, this is the code h:
<modalpopupextender>
</modalpopupextender>
<panel>
<updatepanel>
<gridview>
</gridview>
</updatepanel>
</panel>
Tommy is right, so what you just have to do is re-show the popup.
After the BindData() in the PageIndexChanging event show the panel again with the Show() method of the popup extender.
This code is in c# but is pretty much the same.
gvHorarioPB.DataSource = (DataTable)Session["Prueba"];
gvHorarioPB.PageIndex = e.NewPageIndex;
gvHorarioPB.DataBind();
//mpePB is my modalpopupextender
this.mpePB.Show();
If you are using the .NET AJAX toolkit, keep in mind that each time you click someting (paging, sorting, etc.), the page performs a postback, even if it looks AJAX-y. Meaning that you will need to rebind the data each time. Try removing the IfPostback in your page load and see what that does for you.

Resources