TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

Change Order of Events

VB.NET


Reply
 
Thread Tools Display Modes
Old 15-10-2007, 12:37 PM   #1
Randy
Guest
 
Posts: n/a
Change Order of Events

Hi,
I have an odd issue with the MonthCalendar control. I need to capture
certain mouseeventargs, which I can only do in the MouseDown event. I
need to pass these arguments to the DateChanged event to make the
logic in that routine work correctly. Simple enough, except that the
DateChanged event fires before the MouseDown event, making it too late
to gather these arguments.

Can anybody help me figure out a way to effectively reverse the order
in which these events fire?

Thanks,
Randy

p.s. apologies if anybody has seen this as part of another posting of
mine, but that posting initially dealt with another question and has
become quite long and meandering. I am posting the question here to
isolate it so that it is clear what the issue is. Upon resolution of
this issue, I will post back to the original post with this solution
in the context of that posting.

  Reply With Quote
Old 15-10-2007, 06:38 PM   #2
rowe_newsgroups
Guest
 
Posts: n/a
Re: Change Order of Events

On Oct 15, 2:47 am, Randy <spam.eastl...@gmail.com> wrote:
> Hi,
> I have an odd issue with the MonthCalendar control. I need to capture
> certain mouseeventargs, which I can only do in the MouseDown event. I
> need to pass these arguments to the DateChanged event to make the
> logic in that routine work correctly. Simple enough, except that the
> DateChanged event fires before the MouseDown event, making it too late
> to gather these arguments.
>
> Can anybody help me figure out a way to effectively reverse the order
> in which these events fire?
>
> Thanks,
> Randy
>
> p.s. apologies if anybody has seen this as part of another posting of
> mine, but that posting initially dealt with another question and has
> become quite long and meandering. I am posting the question here to
> isolate it so that it is clear what the issue is. Upon resolution of
> this issue, I will post back to the original post with this solution
> in the context of that posting.


Just a thought, not sure what problems this may cause:

////////////////
Public Class ExtendedMonthCalendar
Inherits MonthCalendar

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(e)
preventDateChanged = False
OnDateChanged(dateChangedEventArgs)
End Sub

Protected preventDateChanged As Boolean = True
Protected dateChangedEventArgs As DateRangeEventArgs

Protected Overrides Sub OnDateChanged(ByVal drevent As
System.Windows.Forms.DateRangeEventArgs)
Try
If preventDateChanged Then
dateChangedEventArgs = drevent
Else
MyBase.OnDateChanged(drevent)
End If
Finally
preventDateChanged = True
End Try
End Sub

End Class
////////////////

Thanks,

Seth Rowe

  Reply With Quote
Old 15-10-2007, 09:49 PM   #3
Randy
Guest
 
Posts: n/a
Re: Change Order of Events

Thanks, Seth. I pasted your code into my form and ran it. It
compiles without error, but it never fires. Can you take a look at
this and maybe point out where I am going wrong?

Imports System.Windows.Forms
Public Class Form3

Private Sub MonthCalendar1_DateChanged(ByVal sender As Object,
ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles
MonthCalendar1.DateChanged
Me.Text = "Order Reversed. Problem solved."
End Sub


Private Sub MonthCalendar1_MouseDown(ByVal sender As Object, ByVal
e As System.Windows.Forms.MouseEventArgs) Handles
MonthCalendar1.MouseDown
Me.Text = "Order NOT Reversed. Problem still exists."
End Sub
End Class

Public Class ExtendedMonthCalendar
Inherits MonthCalendar

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
MyBase.OnMouseDown(e)
preventDateChanged = False
OnDateChanged(dateChangedEventArgs)
End Sub


Protected preventDateChanged As Boolean = True
Protected dateChangedEventArgs As DateRangeEventArgs


Protected Overrides Sub OnDateChanged(ByVal drevent As
System.Windows.Forms.DateRangeEventArgs)
Try
If preventDateChanged Then
dateChangedEventArgs = drevent
Else
MyBase.OnDateChanged(drevent)
End If
Finally
preventDateChanged = True
End Try
End Sub

End Class

Thanks again,
Randy

  Reply With Quote
Old 15-10-2007, 10:42 PM   #4
rowe_newsgroups
Guest
 
Posts: n/a
Re: Change Order of Events

On Oct 15, 12:13 pm, Randy <spam.eastl...@gmail.com> wrote:
> Thanks, Seth. I pasted your code into my form and ran it. It
> compiles without error, but it never fires. Can you take a look at
> this and maybe point out where I am going wrong?
>
> Imports System.Windows.Forms
> Public Class Form3
>
> Private Sub MonthCalendar1_DateChanged(ByVal sender As Object,
> ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles
> MonthCalendar1.DateChanged
> Me.Text = "Order Reversed. Problem solved."
> End Sub
>
> Private Sub MonthCalendar1_MouseDown(ByVal sender As Object, ByVal
> e As System.Windows.Forms.MouseEventArgs) Handles
> MonthCalendar1.MouseDown
> Me.Text = "Order NOT Reversed. Problem still exists."
> End Sub
> End Class
>
> Public Class ExtendedMonthCalendar
> Inherits MonthCalendar
>
> Protected Overrides Sub OnMouseDown(ByVal e As
> System.Windows.Forms.MouseEventArgs)
> MyBase.OnMouseDown(e)
> preventDateChanged = False
> OnDateChanged(dateChangedEventArgs)
> End Sub
>
> Protected preventDateChanged As Boolean = True
> Protected dateChangedEventArgs As DateRangeEventArgs
>
> Protected Overrides Sub OnDateChanged(ByVal drevent As
> System.Windows.Forms.DateRangeEventArgs)
> Try
> If preventDateChanged Then
> dateChangedEventArgs = drevent
> Else
> MyBase.OnDateChanged(drevent)
> End If
> Finally
> preventDateChanged = True
> End Try
> End Sub
>
> End Class
>
> Thanks again,
> Randy


The code I gave you is a replacement for the MonthCalendar.

If I were you, I would add a new class file to my project (call it
ExtendedMonthCalendar.vb or something similar) and then place the code
I gave you there. Then, when you rebuild your project you should have
an ExtendedMonthCalendar item listed under <Project> Components in the
Toolbox. Then you can drag that component onto a form and use it as
normal.

If you want to replace your existing MonthCalendar, you pretty much
have two options. The first is to delete the existing control and
replace it with the new ExtendedMonthCalendar. This will be fairly
annoying if you have a lot of Event Handlers wired up to the calendar.
The second option is to open up the Designer.vb file for the "host"
form (or whatever) and modify the declaration for MonthCalendar1 to
use the ExtendedMonthCalendar class instead. By the way, to do this
you'll need to first click the "Show All Files" button on the solution
explorer. Then replace lines like "Private MonthCalendar1 As
MonthCalendar" and "MonthCalendar1 = New MonthCalendar()" with lines
like "Private MonthCalendar1 As ExtendedMonthCalendar" and
"MonthCalendar1 = New ExtendedMonthCalendar()"

Let me know how it works!

Thanks,

Seth Rowe


  Reply With Quote
Old 17-10-2007, 03:12 AM   #5
Charlie
Guest
 
Posts: n/a
Re: Change Order of Events

I added a post to the thread you started on 10/7.

"Randy" wrote:

> Thanks, Seth. I pasted your code into my form and ran it. It
> compiles without error, but it never fires. Can you take a look at
> this and maybe point out where I am going wrong?
>
> Imports System.Windows.Forms
> Public Class Form3
>
> Private Sub MonthCalendar1_DateChanged(ByVal sender As Object,
> ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles
> MonthCalendar1.DateChanged
> Me.Text = "Order Reversed. Problem solved."
> End Sub
>
>
> Private Sub MonthCalendar1_MouseDown(ByVal sender As Object, ByVal
> e As System.Windows.Forms.MouseEventArgs) Handles
> MonthCalendar1.MouseDown
> Me.Text = "Order NOT Reversed. Problem still exists."
> End Sub
> End Class
>
> Public Class ExtendedMonthCalendar
> Inherits MonthCalendar
>
> Protected Overrides Sub OnMouseDown(ByVal e As
> System.Windows.Forms.MouseEventArgs)
> MyBase.OnMouseDown(e)
> preventDateChanged = False
> OnDateChanged(dateChangedEventArgs)
> End Sub
>
>
> Protected preventDateChanged As Boolean = True
> Protected dateChangedEventArgs As DateRangeEventArgs
>
>
> Protected Overrides Sub OnDateChanged(ByVal drevent As
> System.Windows.Forms.DateRangeEventArgs)
> Try
> If preventDateChanged Then
> dateChangedEventArgs = drevent
> Else
> MyBase.OnDateChanged(drevent)
> End If
> Finally
> preventDateChanged = True
> End Try
> End Sub
>
> End Class
>
> Thanks again,
> Randy
>
>

  Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Label printing order change DarrelGiesbrecht Microsoft Office 2 09-10-2007 11:31 AM
Is there any way in script form I can change the order of wireless connections? Blackberry Windows XP 0 23-09-2007 05:27 PM
How to change the order of startup items Michael Windows XP 0 27-08-2007 11:33 PM
How to change file order in Vista Program menu... cpu_expert Windows Vista All 5 19-08-2007 10:38 PM
Change Order that RIS images are presented Kieran Windows XP 2 17-08-2007 02:22 PM


< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 11:12 PM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional