Just like what is said above, I'm having a problem regarding animated GIF. I have a button then if the button is clicked it show/display LOADING GIF within the button but I want that button not clickable while in the process of loading. So I use me.btn1.enabled = false but then the LOADING GIF is not working. What I mean is, it is visible but the ANIMATED LOADING GIF EFFECT not moving/working (or whatever you call that staff).
Thank you in advance!
Leave your button enabled but change the code behind so it ignores subsequent clicks if the loading process is underway. You could use a simple state flag for this.
Dim IsLoading As Boolean
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If (IsLoading) Then
Return
Else
IsLoading = True
' Update button with loading GIF, do loading logic etc.
End If
End Sub
Obviously, you will need to reset IsLoading when your load is complete.
OR, hide the button when loading and show a PictureBox containing the loading GIF in its place.
Related
I'm a newbie with UWP coding. I've got a simple UWP app using VB.NET. Code behind a ContentGrid elsewhere on the same 'form' updates some settings that effect the NavigationView. How can I get the NavigationView to refresh?
I can't seem to reference it from one view to another
XAML snip of Navigation view:
<winui:NavigationView.MenuItems>
<winui:NavigationViewItem x:Uid="Shell_Main" Name="MainMenu" Tag="" Icon="Home" helpers:NavHelper.NavigateTo="views:MainPage" />
<winui:NavigationViewItem x:Uid="Shell_ContentGrid" Name="Video1" Tag="" Icon="GotoStart" helpers:NavHelper.NavigateTo="views:ContentGridPage" />
<winui:NavigationViewItem x:Uid="Shell_ContentGrid2" Name="Video2" Tag="\KES\" Icon="Slideshow" helpers:NavHelper.NavigateTo="views:ContentGridPage2" />
</winui:NavigationView.MenuItems>
<winui:NavigationView.PaneFooter>
<NavigationViewItem Icon="Help" Content="Help" Tag="User"/>
</winui:NavigationView.PaneFooter>
VB code behind the form/view to disable menu items in the OnLoaded event, works fine
For Each topic In navigationView.MenuItems
strDepends = topic.tag
bAllowed = Helpers.ContentAllowed(strDepends)
If Not bAllowed Then topic.IsEnabled = False
Next
Code on another view changes the settings, enabling a menu setting but I can't seem to tell the menu to refresh.
I'd like the NavigationView to refresh/repaint/whatever
Code on another view changes the settings, enabling a menu setting but I can't seem to tell the menu to refresh.
If we want to make NavigationView could update in other view, we pass the NavigationView instance to another view when call Navigate method. I found you have used VB UWP template studio, please refer the following code.
Private Sub OnItemInvoked(ByVal sender As WinUI.NavigationView, ByVal args As WinUI.NavigationViewItemInvokedEventArgs)
Dim item = navigationView.MenuItems.OfType(Of WinUI.NavigationViewItem).First(Function(menuItem) CStr(menuItem.Content) Is CStr(args.InvokedItem))
Dim pageType = TryCast(item.GetValue(NavHelper.NavigateToProperty), Type)
NavigationService.Navigate(pageType, navigationView)
End Sub
Other Page
Protected Overrides Sub OnNavigatedTo(ByVal e As NavigationEventArgs)
MyBase.OnNavigatedTo(e)
Dim nav = TryCast(e.Parameter, Microsoft.UI.Xaml.Controls.NavigationView)
If nav IsNot Nothing Then
For Each item As Microsoft.UI.Xaml.Controls.NavigationViewItem In nav.MenuItems
// update navigateview's status
Next
End If
End Sub
I have a WebBrowser in my VB.net form. I want to disable from users clicking links in the Webbrowser, but still able to scroll the Webbrowser.
I found this code but it locks up the whole WebBroswers so I can't click links or scroll, but I need to be able to scroll.
DirectCast(WebBrowser1, Control).Enabled = False
Just set the following property:
WebBrowser1.AllowNavigation = False
A hacky work-around to change the address from code would be to turn AllowNavigation on again, but it requires a BeginInvoke to allow the navigation to take place before turning it off again:
WebBrowser1.AllowNavigation = True
WebBrowser1.Navigate("new web address...")
Me.BeginInvoke(New Action(Sub() WebBrowser1.AllowNavigation = False))
I am copying all the images from the server to the local workstation so that one cannot tamper with them and when the application closes I want to delete those files.
currently I just tested with the splash screens background image. I copied the file to temp folder in workstation and it worked well.
But when I tried to delete it I am not able to do so as it is still used by splash screen.
How to release it from splash screen?
I tried to delete the directory
I am using the image on splash screen load method with the following code:
My.Computer.FileSystem.CopyDirectory("\\bwingssrv01\NRSRoot$\NRS_img", "c:\windows\temp\NRS_img", True)
Me.BackgroundImage = Image.FromFile("c:\windows\temp\NRS_img\splash.jpg")
I have tried to delete the directory on MyApplication_Shutdown
I was able to solve this by using delegate in SplashScreen:
I just tried to dispose the background image in the function called from My MDI form at the end of my code and was successful.
I used following code to solve the issue:
A delegate in my SplashScreen as:
Public Delegate Sub unload()
and following function in my SplashScreen as:
Public Sub unload1()
If Me.InvokeRequired Then
Me.Invoke(New unload(AddressOf unload1))
Else
Me.Visible = False 'to avoid showing the error image in background
Me.BackgroundImage.Dispose()
End If
End Sub
At the end of my MDI form I used following:
SplashScreen1.unload1()
Threading.Thread.Sleep(100)
I've created a form that has a tabbed control that gets users controls added to each tab dynamically and a StatusStrip at the bottom of the form. When the app starts, the user controls are loaded in the tabs based on security with at least 1 tab being loaded. On the StatusStrip, two ToolStripComboBoxes, 2 ToolStripButtons, 1 ToolStripLabel, and 1 ToolStripStatusLabel. Everything loads fine and works.
I've been taksed to have a MonthCalendar popup when the user presses one of the two buttons. Here's the code I use to do this:
If IsNothing(theCal) Then
theCal = New MonthCalendar
AddHandler theCal.DateSelected, AddressOf theCalDateSelected
AddHandler theCal.LostFocus, AddressOf theCalLostFocus
AddHandler theCal.GotFocus, AddressOf theCalLostFocus
theCal.Parent = Me
theCal.Top = StatusStripMain.Top - theCal.Height
theCal.Left = ComboBoxAvailableLegDay.Bounds.X
theCal.Anchor = AnchorStyles.Bottom + AnchorStyles.Left
theCal.Show()
theCal.BringToFront()
theCal.Focus()
Else
Me.Controls.Remove(theCal)
theCal = Nothing
End If
theCal is defined as Protected at the top of the form's class. So, pressing the button will create the MonthCalendar and position it correctly if it doesn't exists and if it does exists, then it is removed. This works with no problems.
My problem is that theCal never fires GotFocus or LostFocus. I've got the procedure theCalLostFocus defined as follows and it never thows the exception. I can put a breakpoint at the throw and the code never makes it to that point.
Private Sub theCalLostFocus(ByVal sender As Object, ByVal e As EventArgs)
Throw New NotImplementedException
End Sub
Clicking a date on theCal will call theCalDateSelected procedure, but clicking any other area of the form does not fire theCalLostFocus. Since the user may want to not select a date and I don't want to force them to have to press the button to remove theCal, I'd like to be able to remove theCal when it loses focus. Anyone have any idea why this is happening and anyone got a solution?
Thanks.
-NCGrimbo
i'm not that surprised that the focus event won't fire, because you add the handler before inserting it in the visual tree. try adding the handler after the call to show(). or maybe in the loaded event handler. Note that since you request the focus, your focus event handler will be called every time.
Rq : as it is written, your code has memory leak since you do not remove the event handler when you clear theCal, so since a reference is kept to theCal, neither theCal nor the event handler get cleared and this lead to memory leak (cyclical reference).
How do I reduce flicker in a vb2005 panel?
Inside the parent panel I have 2 other panels that I'm am using.
The outer most panel contains a background sprite and the two innermost panels are overlays that change to fit the places in the background sprite.
When I change the overlay sprites I would like to reduce the flicker and make it a smooth transition from one sprite to the next.
Here is the code that changes the images in the overlay panels
the overlay panel is not changed if the new value is the same as the old value
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll, TrackBar1.Scroll
If (Panel2.Tag <> TrackBar1.Value) Then
Panel2.Tag = TrackBar1.Value
Panel2.BackgroundImage = tops(TrackBar1.Value) //img array for the top panel
Panel2.Update()
End If
If (Panel3.Tag <> TrackBar2.Value) Then
Panel3.Tag = TrackBar2.Value
If (TrackBar2.Value > 0) Then
Panel3.Location = New Point(182, 210)
Else
Panel3.Location = New Point(182, 209)
End If
Panel3.BackgroundImage = bottoms(TrackBar2.Value)//img array for the bottom panel
Panel3.Update()
End If
You're not going to like this answer. The flicker is caused by the fact that the default .NET panel is not double buffered - so it does all the drawing directly in the visible memory, not a back buffer.
You need to subclass the Panel class and enable double buffering on the new class. This can be done by doing a
SetStyle
call in the constructor with the flags OptimisedDoubleBuffering and DoubleBuffering enabled.
Once you have the new panel class that is double buffered, you can use them in your application instead of the standard Panel.
I told you you wouldn't like the answer ;)
Rein is right, subclassing is the best way. In the meantime though, change that call from Update to Invalidate; that might help a little.