Splash screen is still using background image How to release vb.net - vb.net

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)

Related

load a webpage in a webview vb

Public NotInheritable Class MainPage
Inherits Page
Private Sub WebView_NavigationCompleted()
Dim uri As New Uri("google.com")
webView1.Navigate(uri)
End Sub
End Class
I have a webview on my designer and I clicked on the webview to get the private sub above. However, when the app loads, it won't display the webpage. What am I doing wrong?
I wanted this app to view a single web page as soon as the app loads.
I have tried to look this up on google, but nothing is seeming to work.
A Uri like that would, under normal circumstances, cause a System.UriFormatException (Check here). Try something like "http://www.google.com" instead.

animated GIF not working if Button is disabled

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.

Force UI redraw after loading new resource files

I have defined 2 themes (Resource files containing colours - .xaml), one in the resource dictionary on app load and one added on a button click by the following code:
Application.Current.Resources.MergedDictionaries.Clear()
Dim lightTheme As New ResourceDictionary()
Dim lightThemeUri As New Uri("/MyApp.UI;component/Assets/ColourResourcesLight.xaml", UriKind.Relative)
lightTheme.Source = lightThemeUri
Application.Current.Resources.MergedDictionaries.Add(lightTheme)
The colours in the new light theme are defined with the same key as the dark theme (loaded when app loads). My controls are then bound to this key with a staticResource.
After the new resource file loads i would like to somehow update / force a redraw of the whole UI to allow my new theme to display. This works on the controls contained in pages that i then navigate to, however it does not update my navigation bar (Main Page). Every other page is loaded into a container on the main page.
I would like the navigation bar to also update.
Was wondering what the best way to do this was, i have tried updating the bindings by using :
Public Shared Sub ForceControlRebind(cntrl As Control, depprop As DependencyProperty)
Try
Dim BindExp As BindingExpression = cntrl.GetBindingExpression(depprop)
Dim Bind As Binding = BindExp.ParentBinding
cntrl.SetBinding(depprop, Bind)
Catch generatedExceptionName As Exception
Throw
End Try
End Sub
However the BindExp always returns nothing.
I have also tried forcing a UI redraw by using:
mainpage.InvalidateMeasure()
mainpage.InvalidateArrange()
mainpage.UpdateLayout()
I know the resource file is properly loaded as the properties have updated when i step into the controls

Windows Store App Search Contract Blank Screen

I recently added the search contract to my app. It is working great! But, whenever I search in the app when it is not running, it only starts with a blank screen. I did the part to add search results even in OnSearchActivated method. But even if I remove the code that I added, the blank screen persists. I created a blank project and added the search contract to it. And it is working in it even when the app is not running. The issue seems to be with my app only. I cannot debug it because it is something that runs when the app is not even running. Tell me a solution.
Code in OnSearchActivated and OnLaunched
Protected Overrides Async Sub OnSearchActivated(args As Windows.ApplicationModel.Activation.SearchActivatedEventArgs)
Dim previousContent As UIElement = Window.Current.Content
Dim frame As Frame = TryCast(previousContent, Frame)
If frame Is Nothing Then
frame = New Frame
Common.SuspensionManager.RegisterFrame(frame, "AppFrame")
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
Try
Await Common.SuspensionManager.RestoreAsync()
Catch ex As Common.SuspensionManagerException
End Try
End If
End If
frame.Navigate(GetType(SearchResultsPage1), args.QueryText)
Window.Current.Content = frame
Window.Current.Activate()
End Sub
Protected Overrides Async Sub OnLaunched(args As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
AddHandler SearchPane.GetForCurrentView.SuggestionsRequested, AddressOf OnSearchPaneSuggestionsRequested
'Contains definition of arrays ExNam, ExAbbr, ExInst, etc. removed from here to shorten the code and focus on its logic
If rootFrame Is Nothing Then
rootFrame = New Frame()
Train_Thy_Brain.Common.SuspensionManager.RegisterFrame(rootFrame, "appFrame")
If args.PreviousExecutionState = ApplicationExecutionState.Terminated Then
Await Train_Thy_Brain.Common.SuspensionManager.RestoreAsync()
End If
Window.Current.Content = rootFrame
End If
If rootFrame.Content Is Nothing Then
If Not rootFrame.Navigate(GetType(Instructions), args.Arguments) Then
Throw New Exception("Failed to create initial page")
End If
End If
Window.Current.Activate()
End Sub
'Also the namespace definitions are done at the top so they are not the issues neither.
There is a solution to debug your app : in VS2012, Right-click on your project in the Solution Explorer, then go to the Debug tab and in the Start Action section, check "Do not launch, but debug my code when it starts".
Now you can start your app from the Search Contract even if it is not running yet and debug it!
Now for your problem, I would suggest you to check whether the data is loaded before you actually search for something.
You might be hitting the search activation with empty query string. Check your search activation handler, whether you are handling the blank query text case or not?
protected override void OnSearchActivated(SearchActivatedEventArgs args)
{
// your app initialization code here.
Frame frame = (Frame)Window.Current.Content;
if (!string.IsNullOrEmpty(args.QueryText))
{
frame.Navigate(typeof(SearchResultsPage), args.QueryText);
}
else
{
// navigate to your app home page if the query text is empty.
frame.Navigate(typeof(Home), null);
}
Window.Current.Activate();
}

How to set 5 second timing of a splash screen in VB.NET

I have used this code to set 5 second time of my vb.net's project's splash screen.
Imports System.Collections.ObjectModel
Namespace My
Partial Friend Class MyApplication
Protected Overrides Function OnInitialize(ByVal commandLineArgs As ReadOnlyCollection(Of String)) As Boolean
Me.MinimumSplashScreenDisplayTime = 5000
Return MyBase.OnInitialize(commandLineArgs)
End Function
End Class
End Namespace
This code is fully working but as my project takes no time to load so as soon the splashscreen is getting loaded the 1st form is also getting loaded, and it is hiding the splash screen.
I want that the 1st form will load after the splash screen gets closed. Can any one help me out in this?
You could try setting your application to use a 'Sub Main' as its startup object rather then either form. In the 'Sub Main' you can show your splash screen as a modaless form while you do your initialization, then hide it when you you are ready to show your main form. Something like:
Sub Main
Dim slash as new SpashScreenForm
slash.Show()
<do the initialization for several seconds>
slash.Hide()
Dim mainForm as new TheMainForm
mainForm.ShowDialow()
End Sub
You may need to throw in a few Application.DoEvents() calls to get the splash screen to refresh.