I can't understand why the double animation event is firing twice. The rich text box gets updated on the completed method. When it is faded out, I change the text from queue. Then animation begins again. When queue is empty, it replenishes with new data. But because the event is firing twice, it skips some of the texts.
Private Sub CreateNewsAnimation()
fadingNewsAnimation.From = 0
fadingNewsAnimation.To = 1
fadingNewsAnimation.AutoReverse = True
fadingNewsAnimation.Duration = New Duration(TimeSpan.FromSeconds(newsDuration))
AddHandler fadingNewsAnimation.Completed, AddressOf fadingNewsAnimation_Completed
RTBoxNewsBottom.BeginAnimation(UIElement.OpacityProperty, fadingNewsAnimation)
End Sub
Private Sub fadingNewsAnimation_Completed(ByVal sender As Object, ByVal e As EventArgs)
If enableEvent = True Then
If m_NewsQueue.Count > 0 Then
Using newsMemStream As New IO.MemoryStream(System.Text.ASCIIEncoding.[Default].GetBytes(m_NewsQueue.Dequeue()))
RTBoxNewsBottom.Selection.Load(newsMemStream, DataFormats.Rtf)
RTBoxNewsBottom.BeginAnimation(UIElement.OpacityProperty, fadingNewsAnimation)
End Using
Else
PopulateNewsQueue()
End If
End If
End Sub
Related
I have a timer. in my form is still possible to open the child window. when I open and close this window, the timer starts again. How can I continue timer operation when I open and clos the child window??? I hope very much for your help!
this is my timer:
Private timer As DispatcherTimer
Private CountUp As Integer
Public Sub DispatcherTimerSetup()
timer = New DispatcherTimer()
timer.Interval = New TimeSpan(0, 0, 1)
AddHandler timer.Tick, AddressOf timer_Tick
timer.Start()
End Sub
Private Sub timer_Tick(sender As Object, e As Object)
CountUp += 1
Dim counter As TimeSpan
counter = TimeSpan.FromSeconds(CountUp)
txblCountdown.Text = counter.ToString("mm\:ss")
End Sub
child window:
Private Sub btnMapPoint_Click(sender As Object, e As RoutedEventArgs)
SaveControlValuesInObject()
Dim intIndex As Integer = CInt(sender.Name.Replace("btnMapPoint_", ""))
Frame.Navigate(GetType(Location))
TryCast(Frame.Content, Location).InitForm_Observation(_myEventErist, intIndex, GetType(Event9900000))
TryCast(Frame.Content, Location).IsChangeMapEnabled = False
TryCast(Frame.Content, Location).SetSelectedMap(DirectCast(cboMesspunkt.SelectedItem, SMS_KARTE))
End Sub
Best regards, Polina
Frame.Navigate(GetType(Location)) will initialize new instance of Location page, so CountUp value will be lost.
You can make CountUp field public and add another field in parent object, for example, SavedCountUpValue. Then use Location.Unloaded event to save CountUp value into SavedCountUpValue field.
In parent object, in Location_Unloaded handler:
SavedCountUpValue = TryCast(Frame.Content, Location).CountUp
Then, when initializing new Location object, restore CountUp value.
In parent object, in btnMapPoint_Click handler:
Frame.Navigate(GetType(Location))
...
TryCast(Frame.Content, Location).CountUp = SavedCountUpValue
I've got a control with rectangles in a grid. I can drag rectangles from one cell to another within the grid. But I also need to double-click on a rectangle to bring up an edit dialog. The issue here is that just pressing the left mouse button on the rectangle will initiate a MouseMove event and cause the DragDrop to initiate when it's not wanted.
Here's the MouseMove and MouseDoubleClick event handlers:
Dim IsDragging As Boolean = False
Private Sub SchedItem_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If IsDragging Then Exit Sub
If e.LeftButton = MouseButtonState.Pressed Then
Dispatcher.InvokeAsync(Sub()
IsDragging = True
DragDrop.DoDragDrop(Me, Me, DragDropEffects.Move)
IsDragging = False
End Sub)
End If
End Sub
Private Sub SchedItem_PreviewMouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles Me.PreviewMouseDoubleClick
itmEditTask_Click(Nothing, Nothing)
e.Handled = True
End Sub
I tried not initiating the MouseMove by attempting to determine the distance the mouse had traveled since the MouseLeftButtonDown event. But the x & y numbers are all over the place and I can't reliably set a threshold value. Here's that code:
Private mPos As Point
Private Sub SchedItem_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
mPos = Mouse.GetPosition(Nothing)
End Sub
Private Function IsReallyMouseMove() As Boolean
Dim pPos As Point = Mouse.GetPosition(Nothing)
Debug.WriteLine(Math.Abs(mPos.X - pPos.X) & ", " & Math.Abs(mPos.Y - pPos.Y))
IsReallyMouseMove = Math.Abs(mPos.X - pPos.X) > 10 OrElse Math.Abs(mPos.Y - pPos.Y) > 10
End Function
So I'm hoping someone has done this and can provide some direction.
best way - redesign.
Make you item draggable by some object in item element. (Maybe little dot with different drag cursor)
Other area will handle double click.
In my Program Cyrus-Beck algorithm, I have to clip the points. The points inside the clipping window have to be red. The outside is still black.
I represent point in program as rectangle and I give the event handler for delete the point. when I wanted to delete points, points outside the window is working, but points that inside polygon didn't work, event the right-click event not call.
Here is my Point class.
Ignore the Component class, because it just nothing than handler to canvas in the main window
Public Class Points
Inherits Component
Public items As List(Of Point) = New List(Of Point)()
Public rects As List(Of Rectangle) = New List(Of Rectangle)
'add element
Public Overrides Sub Canvas1_MouseMove(sender As Object, e As MouseEventArgs)
canvas.Cursor = Cursors.Pen
End Sub
Public Overrides Sub Canvas1_MouseDown(sender As Object, e As MouseButtonEventArgs)
canvas.Cursor = Cursors.Pen
If e.LeftButton = MouseButtonState.Pressed Then
items.Add(e.GetPosition(canvas))
Dim p As Rectangle = New Rectangle()
p.Width = 3
p.Height = 3
canvas.SetLeft(p, e.GetPosition(canvas).X)
canvas.SetTop(p, e.GetPosition(canvas).Y)
p.Stroke = Brushes.Black
p.Fill = Brushes.Black
rects.Add(p)
End If
End Sub
'deleting element
'this method not calling when the element has updated
Sub point_rightClick(sender As Object, e As MouseButtonEventArgs)
Dim temp As Rectangle = New Rectangle()
temp = DirectCast(sender, Rectangle)
Dim pt As Point = New Point(Controls.Canvas.GetLeft(temp), Controls.Canvas.GetTop(temp))
canvas.Children.Remove(temp)
items.Remove(pt)
rects.Remove(temp)
End Sub
Public Shared Function samePoint(one As Rectangle, two As Rectangle) As Boolean
Return ((Controls.Canvas.GetLeft(one) = Controls.Canvas.GetLeft(two)) And (Controls.Canvas.GetTop(one) = Controls.Canvas.GetTop(two)))
End Function
Public Shared Function samePoint(one As Point, two As Rectangle) As Boolean
Return (one.X = Controls.Canvas.GetLeft(two)) And (one.Y = Controls.Canvas.GetTop(two))
End Function
End Class
To able to delete, I have deleting that represents the status, if deleting is true and currentState = MouseState.Pointer. the code will add handler to all the points (rectangles).
Private Sub chge_pointer_Click(sender As Object, e As RoutedEventArgs) Handles chge_pointer.Click
currentState = MouseState.Pointer
deleting = True
chooseHandler()
End Sub
Private Sub chooseHandler()
If deleting Then
For Each r As Rectangle In points.rects
AddHandler r.MouseRightButtonDown, AddressOf points.point_rightClick
Next
Else
For Each r As Rectangle In points.rects
RemoveHandler r.MouseRightButtonDown, AddressOf points.point_rightClick
Next
End If
End Sub
Before I modified the points to be red, I have to have a loop to check if the position is same, if the position same so edit the points
Dim z As CyrusBeck = New CyrusBeck(clippingWindow)
z.Clip(points.items)
'CyrusBeck has a properties 'points'
'CyrusBeck.points saves the all the point that inside the clipping window
For i As Integer = 0 To points.rects.Count - 1
For Each p As Point In z.points
If CGAProject.Points.samePoint(p, points.rects.Item(i)) Then
Dim temp_r As Rectangle = New Rectangle()
temp_r = points.rects.Item(i)
temp_r.Stroke = Brushes.Red
temp_r.Fill = Brushes.Red
points.rects.Add(temp_r)
points.rects.RemoveAt(i)
End If
Next
Next
when the program reaches this, currentState would Never to be MouseState.Pointer. so if user want to delete a point, user have to be press button chge_pointer so my chge_pointer_Click is called and all my handler would be re-setted again.
Why Rectangle.MouseRightButtonDown is not call when the rectangle has updated?
the rectangles that haven't update call the Rectangle.MouseRightButtonDown event, so I have re-set the handler.
What's worng?
Is there any alternative way so user can delete rectangle inside and outside the window?
Note :
I have resetted the handler just after I assigned back my Rectangle to the list, but it still didn't work.
I also create AddHandler temp_r.MouseRightButtonDown, AddressOf points.point_rightClick just after I assigned back my Rectangle to the list, but it didn't work either.
At the end of your events for clicking, like:
Sub point_rightClick(sender As Object, e As MouseButtonEventArgs)
I think you should have a "handles".
E.g.
Sub point_rightClick(sender As Object, e As MouseButtonEventArgs) Handles point.MouseClick
Without this, the sub will never be called (as it seems is happening).
This method also has no "handles"
Public Overrides Sub Canvas1_MouseDown(sender As Object, e As MouseButtonEventArgs)
and it could be:
Public Overrides Sub Canvas1_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles Canvas1.MouseDown
In this scenario when a user changes access to a different business (multi business accounting) it runs through a sub that closes all open tabs and changes the status of any that are still held open in editing mode.
Everything runs really well, the tabs are closed and then the ID for the new business is loaded.
The trouble is the Page.Unloaded event is running after the entire sub has run and is therefore updating the incorrect DB if any pages were left open in the edit mode.
Is there any way to force any pages that were closed as part of the sub to run unloaded before completing the rest of the code?
Thanks
Edit re comment from Pragmateek
This is an exampled of the unloaded event
Private Sub Website_WebPage_Page_Unloaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Unloaded
Try
Dim SaveUpdateButton As Button = Website_WebPage_Grid.FindName("WebsiteWebPage_SaveUpdateButton")
Dim vScrollViewer As ScrollViewer = Website_WebPage_Grid.FindName("WebsiteWebPage_ScrollViewer")
If NewRecord = True Then
RemoveHandler SaveUpdateButton.Click, AddressOf Website_WebPage_DB_Insert
Else
'Edited record
Dim EditButton As Button = Website_WebPage_Grid.FindName("WebsiteWebPage_EditButton")
Dim EditWebPageButton As Button = Website_WebPage_Grid.FindName("Website_WebPage_EditWebPageButton")
RemoveHandler EditButton.Click, AddressOf Website_WebPage_ToggleEditMode_Click
RemoveHandler vScrollViewer.MouseDoubleClick, AddressOf Website_WebPage_ToggleEditMode_Click
RemoveHandler Me.MouseDown, AddressOf Website_WebPage_MouseDown
RemoveHandler SaveUpdateButton.Click, AddressOf Website_WebPage_DB_Update
RemoveHandler EditWebPageButton.Click, AddressOf WebsiteWebPage_BrowseToClick
End If
If OpenForEdit = True Then
If DB_Functions_ReleaseDT("HOA3_Pages", Page_ID, "Page_ID") = False Then
EditForm_Error()
Else
OpenForEdit = False
End If
End If
Catch ex As Exception
EmailError(ex)
End Try
End Sub
If the tab was left in edit mode OpenForEdit will be true and it will call DB_Functions_ReleaseDT
Public Function DB_Functions_ReleaseDT(ByVal TableName As String, ByVal FileID As Integer, ByVal PKey As String) As Boolean
Try
UpdateOpenForEdit(False, TableName)
vService = New Service1Client
strSQL = "UPDATE " & TableName & " SET Open_Editing = 0, Editing_Name = 'System' WHERE " & PKey & " = " & FileID
If vService.InsertDataHOA(strSQL, "3 DB_Functions 43", Current_HOA_ID) = False Then
Return False
Else
Return True
End If
Catch ex As Exception
EmailError(ex)
Return False
Finally
If Not vService Is Nothing Then
vService.Close()
vService = Nothing
End If
End Try
End Function
The problem is Unloaded is running far too late and the variable Current_HOA_ID has changed
Turned out the answer was quite simple - the sub was being run twice, so adding...
e.Handled = True
.. as the first line of code sorted the problem out
I want to be able to accept a NULL date using the DateTimePicker control.
The "Checked" property appears to be intended to specify whether the control "holds a date" or now. However, when "unchecked", the date still appears, though it appears disabled. To me, this is distracting. If the intent of the unchecked checkbox is to indicate that there is no date value, why is there ANY date value disable or otherwise that appears in the textbox? It seems to me that if the control is unchecked, the textbox should be EMPTY and that seeing a dimmed date value when the user really wants "no value" is distracting.
If the user toggled the checkbox on, then I would like the ability to place a default value into the textbox.
I am considering creating a usercontrol that toggles between a dateTimePicker control and a textBox, but I hate to go through this trouble.
I tried looking a Telerik's DateTimePicker but trying to get decent null handling functionality out of that control seems worse. I'd love to see a working example of what one of you think is a user-friendly code example with either the std MS or Telerik DateTimePicker control that accepts null input.
I've looked at a few opensource controls, but every time they fix one issue, they introduce others.
EDIT:
See my answer below. It seems to work fine, now I just want to make it part of every DateTimePicker's behavior.
I had the same problem. Well, actually I'm smart enough to understand, but my users had a problem.
I solved by removing the checkbox, and adding 2 radio buttons. Looks something like this now:
(using pseudo UI)
O No value entered
O | 1/1/2010 |V|
The top radiobutton is checked when there is no value (null), the bottom one when there is a value. I do not hide, or disable the bottom control, and users seem to understand.
The downside is, that it takes a lot more space.
PS: Next thing users will complain about is using the scroll-wheel when a combo-box has focus.
Klugey, but it seems to get the job done. If the checkbox is not checked, assume a NULL value.
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
If DateTimePicker1.Checked Then
DateTimePicker1.Format = DateTimePickerFormat.Short 'Or whatever the original format was
Else
DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat = " "
End If
End Sub
OK, the next question...How do I roll this behavior into a subclassed DateTimePicker? What I want to do is to capture the original values of the Format and CustomFormat properties as set in the Properties window. But, this clearly isn't the way to do it.
Here's my feeble attempt:
Public Class NullableDateTimePicker
Inherits DateTimePicker
Private _OriginalFormat As DateTimePickerFormat
Private _OriginalCustomerFormat As String
Private Sub NullableDateTimePicker_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ValueChanged
If Me.Checked Then
Me.Format = _OriginalFormat
Me.CustomFormat = _OriginalCustomerFormat
Else
Me.Format = DateTimePickerFormat.Custom
Me.CustomFormat = " "
End If
End Sub
Private Sub _DP_FormatChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Static Count As Integer
If Count = 0 Then
_OriginalFormat = Me.Format
_OriginalCustomerFormat = Me.CustomFormat
End If
Count += 1
End Sub
Public Sub New()
AddHandler MyBase.FormatChanged, AddressOf _DP_FormatChanged
End Sub
End Class
I realise this is many years after your initial question but here's a subclass of the Telerik RadDateTimePicker that does what you were asking for:
Imports Telerik.WinControls.UI
Public Class DateTimePickerWithNull
Inherits Telerik.WinControls.UI.RadDateTimePicker
Private ReadOnly _calendar As RadCalendar
Sub New()
Dim calendarBehavior As RadDateTimePickerCalendar = Me.DateTimePickerElement.GetCurrentBehavior()
calendarBehavior.DropDownMinSize = New Size(220, 150)
_calendar = calendarBehavior.Calendar
_calendar.ShowFooter = True
AddHandler _calendar.ClearButton.Click, AddressOf ClearButton_Click
AddHandler _calendar.TodayButton.Click, AddressOf TodayButton_Click
End Sub
Private Sub ClearButton_Click(sender As Object, e As EventArgs)
'Do this to put the calendar away
_calendar.SelectedDate = _calendar.FocusedDate
'Then clear
Me.SetToNullValue()
End Sub
Private Sub TodayButton_Click(sender As Object, e As EventArgs)
_calendar.SelectedDate = _calendar.FocusedDate
End Sub
End Class
To get the value of the picker:
If DateTimePicker1.Value.Date = DateTimePicker1.NullDate Then
Label1.Text = "Null"
Else
Label1.Text = DateTimePicker1.Value.ToLongDateString
End If
A bit tricky to get right. This looked good:
Imports System.ComponentModel
Public Class MyDateTimePicker
Inherits DateTimePicker
Implements ISupportInitialize
Public Sub New()
Me.ShowCheckBox = True
Me.NullDate = True
End Sub
Private CustomFormatBacking As String = ""
Private FormatBacking As DateTimePickerFormat = DateTimePickerFormat.Long
<DefaultValue(True)> _
<Bindable(True)> _
Public Property NullDate() As Boolean
Get
Return Not Me.Checked
End Get
Set(ByVal value As Boolean)
Me.Checked = Not value
End Set
End Property
<DefaultValue("")> _
<Localizable(True)> _
<RefreshProperties(RefreshProperties.Repaint)> _
Public Shadows Property CustomFormat() As String
Get
Return CustomFormatBacking
End Get
Set(ByVal value As String)
CustomFormatBacking = value
If DesignMode Or Not NullDate Then MyBase.CustomFormat = value
End Set
End Property
<RefreshProperties(RefreshProperties.Repaint)> _
Public Shadows Property Format() As DateTimePickerFormat
Get
Return FormatBacking
End Get
Set(ByVal value As DateTimePickerFormat)
FormatBacking = value
If DesignMode Or Not NullDate Then MyBase.Format = value
End Set
End Property
<DefaultValue(true)> _
<Bindable(True)> _
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Shadows Property Checked() As Boolean
Get
Return MyBase.Checked
End Get
Set(ByVal value As Boolean)
MyBase.Checked = value
End Set
End Property
Private Sub updateNullState()
If NullDate and Not DesignMode Then
MyBase.CustomFormat = " "
MyBase.Format = DateTimePickerFormat.Custom
Else
MyBase.CustomFormat = CustomFormatBacking
MyBase.Format = FormatBacking
End If
End Sub
Public Sub BeginInit() Implements System.ComponentModel.ISupportInitialize.BeginInit
End Sub
Public Sub EndInit() Implements System.ComponentModel.ISupportInitialize.EndInit
updateNullState()
End Sub
Protected Overrides Sub OnValueChanged(ByVal eventargs As System.EventArgs)
MyBase.OnValueChanged(eventargs)
updateNullState()
End Sub
End Class