Error with sampleapp supplied with windowsSDK evernote - vb.net

' Download the thumbnail for a note; then display it on this app's form.
Dim thumbnail As Byte() = ENSession.SharedSession.DownloadThumbnailForNote(myResultsList(0).NoteRef, 120)
Try
Dim ms As New MemoryStream(thumbnail, 0, thumbnail.Length)
ms.Position = 0
Dim image1 As System.Drawing.Image = System.Drawing.Image.FromStream(ms, False, False)
PictureBoxThumbnail.Image = image1
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
' Display a note's content as HTML in a WebBrowser control.
Dim myContent = myDownloadedNote.HtmlContent
WebBrowser1.DocumentText = myContent
End If
with these 2 blocks of code from the included "Sampleapp"
i am getting the following errors....
Error 1 'PictureBoxThumbnail' is not declared. It may be
inaccessible due to its protection level.
H:\Michael-Documents\Visual Studio
2013\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 84
17 WindowsApplication1
Error 2 'WebBrowser1' is not declared. It may be inaccessible
due to its protection level. H:\Michael-Documents\Visual Studio
2013\Projects\WindowsApplication1\WindowsApplication1\Form1.vb 91
13 WindowsApplication1
could anyone give me a helping hand, as to what is wrong. Sometimes the Head does not want to think. :-)

This sample app from the Evernote Windows SDK consists of a form with two controls on it named PictureBoxThumbnail and WebBrowser1. I checked the relevant code on Github and confirmed that they are there in the VB.NET SDK sample.
It sounds like somehow in the copy of the app you have in your Visual Studio, the names of these controls have been altered, or the controls may not be on the form at all.
Double-click on the form ("Form1") in the VS Solution Explorer window so as to open it in the VS Designer. There should be one PictureBox control on the left-hand side, named PictureBoxThumbnail, and one larger WebBrowser control on the right-hand side named WebBrowser1. If you don't have either or both of these controls on your form, add them; or if they are not named PictureBoxThumbnail and WebBrowser1, respectively, then rename them to those names. Then the app should run properly.

Related

VB.net, cannot access OpenFileDialog that has been added to project

I have decades of experience writing VB6 apps but today I tried to write a simple VB.net app using Microsoft Visual Studio 2019. I fell at the first hurdle. I'm sure I'm doing something really simple wrong so forgive the naive question.
Using the toolbox, I added an OpenFileDialog object to my main (one and only) form. Unlike VB6, this didn't appear on the form but in a sort of bar along the bottom of the window, but it was definitely there and I was able to set some properties.
I then added a button and wrote my first line of code:
With OpenFileDialog1
Wrong! I get errpr BC30451: 'OpenFileDialog1' is not declared. It may be inaccessible due to its protection level.
But I can see it sitting there in the design view, I have spelt its name correctly and the above code is
exactly copied from the example. I tried changing OpenFileDialog1's Modifiers property from Friend to Public - makes no difference.
What novice mistake have I made? How do I access an OpenFileDialog object that I have definitely added to my form?
The FolderBrowserDialog which can be dragged onto the form using the toolbox, is out of date and offers (from today's perspective) too few options. Do yourself a favor and use the Nuget Package Manager to download the modern OpenFileDialog.
Imports Microsoft.WindowsAPICodePack.Dialogs
in your Private Sub Button1_Click:
Dim Pfad As String
Using OFD1 As New CommonOpenFileDialog
OFD1.Title = "Datei auswählen"
OFD1.Filters.Add(New CommonFileDialogFilter("JPG", ".jpg"))
OFD1.Filters.Add(New CommonFileDialogFilter("JPEG", ".jpeg"))
OFD1.Filters.Add(New CommonFileDialogFilter("Bitmap", ".bmp"))
OFD1.Filters.Add(New CommonFileDialogFilter("PNG", ".png"))
OFD1.IsFolderPicker = False 'true to make it an FolderBrowserDialog ;-)
OFD1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If OFD1.ShowDialog = CommonFileDialogResult.Ok Then
Pfad = OFD1.FileName
Else
Return
End If
End Using
for Multiselect (with Bildpfade1 as a New List(of String) ):
Using OFD As New CommonOpenFileDialog
OFD.Title = "Bilder auswählen"
OFD.Filters.Add(New CommonFileDialogFilter("JPG", ".jpg;jpeg"))
OFD.Multiselect = True
OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
If OFD.ShowDialog() = CommonFileDialogResult.Ok Then
For Each file As String In OFD.FileNames
Bildpfade1.Add(file)
Next
End If
End Using
I think I have found the answer but it looks, to me, like a bug in Visual Studio. I saved the project and closed Visual Studio. Restarted and reloaded the project. All the controls I had added to my form had vanished!
I rebuilt the now-empty project then started adding controls - lo and behold, I can now access all my controls from code whereas, previously, I couldn't access any of them. It looks like, prior to the initial build, none of the controls I thought I'd added had actually been added. Certainly they didn't survive save project, restart Visual Studio.
Seems to work now. Many thanks to those who contributed suggestions.

my program stop working only in once PC (when store picture for second time)

I developed program and tried it on multi PCs, it works perfectly in some of them.
There are 2 PCs with 32 bit, which have given stop working error.
I upgraded one of them into 64 bit, but still has the same problem!
The error appeared at the same moment:
I choose picture from computer then it will shown at picture box
I save data on DB (data include text and picture (ole object))
Then I try add new record and choose new picture the Error message come (program stop working).
program developed using visual basic.net by Visual Studio and access DB
the code of showing picture :
Dim opf As New OpenFileDialog
opf.Filter = "Choose Image(*.JPG;*.PNG;*.GIF)|*.jpg;*.png;*.gif"
If opf.ShowDialog = Windows.Forms.DialogResult.OK Then
nameOfFile = opf.FileName
PicBox.Image = Image.FromFile(opf.FileName)
End If
If it just crashes out of your application, you might want to handle any exceptions. Once you handle the exception you can messagebox the error and it might give you an idea why the application has a problem.
As a guess it might be an issue with 32bit/64bit drivers but best to see why application has the issue first.
Here is the code that #Dennis suggested.
Try
Dim opf As New OpenFileDialog
opf.Filter = "Choose Image(*.JPG;*.PNG;*.GIF)|*.jpg;*.png;*.gif"
If opf.ShowDialog = Windows.Forms.DialogResult.OK Then
nameOfFile = opf.FileName
PicBox.Image = Image.FromFile(opf.FileName)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
I would guess that the error is more likely in the Save code. If this does not produce a MessageBox then try the same thing on the save code.
If this solves your problem pleas accept #Dennis's answer because it was his idea.

Check if Adobe Reader is installed before using it

I want to be able to have my app check if Adobe Reader is installed.
If it is, I want my program to use it to display the PDF, if not I want to use my free (limited) reader control to display the PDF.
Any suggestions
Edit:
my question seems to be little to broad
So basicly i'm trying to do the following
Try
Dim AcroDisplay As New AxAcroPDFLib.AxAcroPDF
AcroDisplay.Left = 50
AcroDisplay.Top = 50
AcroDisplay.Width = 200
AcroDisplay.Height = 500
me.Controls.Add(AcroDisplay)
MsgBox("Acro Added")
Catch ex As Exception
MsgBox("Acro Not installed")
''Load Alternate PDF viewer (Spire.pdf Free)
End Try
However when Acrobat Isn't installed instead of going to the catch statement it just shows an error "Could not load assembly" and then exits the sub
What i want is that if acrobat control isn't installed, that it wont display and error and instead just load the alternate pdf viewer
is there a way to check for AxAcroPDFLib.AxAcroPDF before attempting to load?
Hopefully this makes things clearer
Edit 2:
After Searching and screwing around i found 2 possible ways i might be able to do this
however both i can't find how to do it in VB.net
First
Look for AxAcroPDFLib.AxAcroPDF in available namespaces
found C# example but i don't know how to change it to Vb.net
C# - How to check if namespace, class or method exists in C#??
Second
Add Unhandled Exception Handler
also found a few examples but none seem to work
Any Chance anyone could direct me to a working example for either (or both) of these options
Manged to fin a working solution, doesn't work how i was originally thinking but it doe work just fine
i used the following code
Dim AdobeSoftwares As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("ADOBE")
If AdobeSoftwares Is Nothing Then
'MessageBox.Show("No Adobe Software")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
Else
If Not Array.IndexOf(AdobeSoftwares.GetSubKeyNames, "Acrobat Reader") = -1 Then
'MessageBox.Show("Adobe Reader Installed")
Dim PdfDisplay As New AxAcroPDFLib.AxAcroPDF
PDFControl = "Acrobat"
Else
'MessageBox.Show("Adobe Reader Not Installed")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
End If
End If
Then in my display code i just look to see what "PDFControl" is in use and run the relevant code to display in that display
So now if adobe reader is installed, I'll be using its control, and if it isn't I'll be using the free (but less featured) control to display PDF files
So hopefully if anyone else is looking at doing similar to me then they can

VB.NET Screenshot Application Window and Send

I have built an application that obtains details from a web service and displays them in a GUI for the agent to see.
I've had instances of problems occuring, sometimes an exception due to a change in how the data is received due to the provider and unfortunately no user lets me know this occurs, they just click through and pay no attention to the error.
I've built a custom form to capture the error and then email it to me with some details like username etc. etc.
I would ideally LIKE to capture the screen of the application as well, much like an ALT+PRINTSCRN so I can see what the application looks like at the time of error as well.
How possible is this?
Assuming WinForm, I've done this before:
Public Sub SaveAsImage(frm As Form)
'Dim fileName As String = "sth.png"
'define fileName
Dim format As ImageFormat = ImageFormat.Png
Dim image = New Bitmap(frm.Width, frm.Height)
Using g As Graphics = Graphics.FromImage(image)
g.CopyFromScreen(frm.Location, New Point(0, 0), frm.Size)
End Using
image.Save(fileName, format)
End Sub
When being called, it will capture the current screen in the area defined by frm and save to a file.

Getting selected files filepath without OpenFileDialog

I was wondering if there is anyway to get the file path of a selected file. I have registered a hotkey in reference to this.
E.g. RegisterHotKey(Me.Handle, 100, MOD_CONTROL Or MOD_SHIFT, Keys.D2)
Which will do certain actions on pressing ctrl, shift and 2. What i want to do is to get the path of a selected file WITHOUT opening OpenFileDialog
e.g. i select mydoc.doc located on my desktop, press ctrl shift and 2, and it will msgbox out the location of the file.
(meaning i click the file mydoc.doc on my desktop, press my hotkey and get the file location. Is there anyway to do this? (Just like how you would click a file in a folder to copy and paste it to another location, i want to click the file press my hotkey and msgbox out its location))
Is there anyway to do this or any direction anyone can point me in?Because i can't find any API which does this...
Thanks!
EDIT:
After reading all the updates and the several links here and there, I started to construct my own function for this, I'm just at the part to determine how many selected icons there are, but i keep getting back 0 icons is there something wrong with what I'm doing?
Public Function getDesktopFiles() As String
Dim vhandle As IntPtr = FindWindow("Progman", "Program Manager")
vhandle = FindWindowEx(vhandle, IntPtr.Zero, "SHELLDLL_DefView", vbNull)
vhandle = FindWindowEx(vhandle, IntPtr.Zero, "SysListView32", "FolderView")
Dim vItemcount As IntPtr
vItemcount = SendMessage(vhandle, LVM_GETSELECTEDCOUNT, 0, 0)
Return vItemcount
End Function
This question has a link to a Raymond Chen blog post which will give you the API calls you require, you will need to convert it to VB but it is based on COM so should be easy. The other answer to that question gives the C# version of Raymond's code...
Edited to add specifics:
1. Include project references to Microsoft Internet Controls (to get the SHDocVw namespace) and Microsoft Shell Controls and Automation (to get the Shell32 namespace)
2. Use SHDocVw.ShellWindows to get an enumeration of open browser windows.
3. Try to cast each item as a ShellBrowserWindow, and then try to cast the Document property as a Shell32.IShellFolderViewDual2 object.
4. The FocusedItem property gives the selected item.
VB.NET code:
Dim windows As New SHDocVw.ShellWindows
For Each window As Object In windows
Dim browser As SHDocVw.ShellBrowserWindow = window
Dim folder As Shell32.IShellFolderViewDual2 = browser.Document
Console.WriteLine(folder.FocusedItem.Path)
Next