Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Change Order of Events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Randy - 15 Oct 2007 07:47 GMT
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.
rowe_newsgroups - 15 Oct 2007 13:26 GMT
> Hi,
> I have an odd issue with the MonthCalendar control.  I need to capture
[quoted text clipped - 16 lines]
> 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
Randy - 15 Oct 2007 17:13 GMT
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
rowe_newsgroups - 15 Oct 2007 17:29 GMT
> 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
[quoted text clipped - 46 lines]
> 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
Charlie - 16 Oct 2007 21:56 GMT
I added a post to the thread you started on 10/7.

> 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
[quoted text clipped - 46 lines]
> Thanks again,
> Randy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.