Control Properties of LinkLabel when used for HelpProvider - vb.net

I am working with Visual Studio 2017, working in VB. I am linking to a .CHM file from a LinkLabel which works fine with following code:
Private Sub LinkLabel2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkLabel2.Click
' Create link to help file
System.Windows.Forms.Help.ShowHelp(Me, "RPM_Help.chm", HelpNavigator.AssociateIndex)
End Sub
I use a simple image to indicate the link to the .chm file that is 32x32 pixels in size, I have been playing with the properties of LinkLabel2 but I just can't figure out how to make the entire label a link space. I did find that unless there is a Text property on the label a MouseOver cursor will not show up, but how can I make the entire label image a cursor link?

As shown in the code and image below this can be solved by using LinkLabel2.AutoSize = False and adding a ToolTip from Common Controls to the form in design mode.
Each control, such as Buttons and TextBoxes, will acquire a ToolTip on toolTip1 property when you add a toolTip1 to your designer view. You can access this property in the Properties pane to set the tool tips.
Public Class frmMain
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LinkLabel2.BackColor = Color.CornflowerBlue
LinkLabel2.AutoSize = False
LinkLabel2.Width = 168
LinkLabel2.Height = 40
LinkLabel2.Text = ""
End Sub
Private Sub LinkLabel1_Click(sender As Object, e As EventArgs) Handles LinkLabel1.Click
' --- Open help file - Table of contents
System.Windows.Forms.Help.ShowHelp(Me, "hlp/CHM-example.chm", HelpNavigator.TableOfContents)
End Sub
Private Sub LinkLabel2_Click(sender As Object, e As EventArgs) Handles LinkLabel2.Click
' --- Open help file - Index
System.Windows.Forms.Help.ShowHelp(Me, "hlp/CHM-example.chm", HelpNavigator.Index)
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
' --- Open help file - Search
System.Windows.Forms.Help.ShowHelp(Me, "hlp/CHM-example.chm", HelpNavigator.Find, "")
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
The code corresponds to the image shown. The values can of course also be set via the properties, but are included here in the FormLoad for documentation.
You may want to use a simple PictureBox1_Click event for your needs as shown below (third item in the "Show help" group box).

Related

Drag and Drop not working on shortcut or exefile

Drag&Drop is working correctly when application is running. But when a file is dropped on application shortcut or exe.file, no drag&drop event is triggered just aaplication starts.
I created simple application in Visual Studio 2019, only Form1 with following adjustments
Form1.AllowDrop = True
Private Sub Form1_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub Form1_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop
Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
Me.Text = files(0)
End Sub
Can you help me how to open my application with correct filename which is dropped on application icon/shortcut?
Thanks, Martin
Your code only handles the drag and drop on the form itself (which can be done with any other control with AllowDrop = True). Dropping a file onto the application executable file (or shortcut) is a totally different thing; what it does is simply open the application normally but with a command-line argument passed to it (i.e., the file/folder path).
To retrieve that file/folder path, you can use Environment.GetCommandLineArgs, to read the command-line arguments, make sure it returns at least two elements (the first one is your application's executable path), and then display the second (or second to last) elements.
This should work:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim args = Environment.GetCommandLineArgs()
If args.Length > 1 Then Me.Text = args(1)
End Sub
If you drop multiple files onto your program's icon and you want to display them all, you can adjust the above code to something like this:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim args = Environment.GetCommandLineArgs()
For Each arg In args.Skip(1)
' Do something with `arg`.
Next
End Sub

VB.NET Create a to a form attached Preview window

I want to create a little window which gets visible when I press a button and is attached to the main Form (like shwon below). I want to use this window to show preview of Images (I gonna have a Listbox and depending on which entry is selected, a picture is shown) How can I do this? And how can I be sure that the window will always be attached to the main Form (not depending on resolution). I tried to do it with a second form, but I can't fix it in the correct position.
regards
Assuming your preview form class is frmPreview and you open it this way:
Private mPreviewForm As frmPreview
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
mPreviewForm = New frmPreview
mPreviewForm.Show()
AttachPreviewForm()
End Sub
Then you must reposition it every time the main form is changing size or location:
Private Sub AttachPreviewForm()
If mPreviewForm IsNot Nothing Then
mPreviewForm.AttachForm(Me)
End If
End Sub
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
AttachPreviewForm()
End Sub
Private Sub Form1_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
AttachPreviewForm()
End Sub
And in the frmPreview:
Public Sub AttachForm(parent As Form)
Location = New Point(parent.Left + parent.Width, parent.Top)
Size = New Size(200, parent.Height)
End Sub

viewing image in picturebox using listview in vb.net 2008

I am working in vb.net 2008 with listview control. I added some images in listview.items using imagelist. now I want to show that image in picture box when I clicked on button. I had tried some time for this but getting error everytime.
Here is the code :
Public Class Form1
Private Sub ListView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
PictureBox1.Image = Bitmap.FromFile(ListView1.Items.Item(1).ToString)
End Sub
End Class
If you want the picture to show when you click a button then I think you want to use Button_Click instead of ListView_Click
Private Sub MyButton_Click(sender As Object, e As EventArgs) Handles MyButton.Click
'Also, might be easier just to do this:
PictureBox1.Image = ImageList1.Images(0)
End Sub
Then you can set different buttons for your different pictures

Trying to enter a name in a textbox, hit ok, and have that form close and pass the info to another forms label

***THE CODE FROM THE FIRST WINDOW GOES INTO A TEXT BOX AND YOU HIT THE BUTTON HERE.
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Me.Close()
End Sub
***THE CODE ON THE FORM WHERE I WANT THE INFO TO BE PLACED IS HERE.
Private Sub Loan1Form_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.lblCompanyName.Text = DataEntryForm.txtCompanyNameInput.Text
End Sub
Anyway's that's what I found on a youtube video and im having trouble getting it to work. Any help would be appreciated.
Thanks.
Pass the data to an instance of the form:
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Dim f As New OtherForm
f.lblCompanyName.Text = txtCompanyNameInput.Text
f.Show()
Me.Close() 'make sure this form is not the one that closes the app if it closes
End Sub

Drag & drop and get file path in VB.NET

I'd like to be able to drag a file/executable/shortcut into a Windows Forms application and have the application determine the original path of the dropped file then return it as a string.
E.g. drag an image from the desktop into the application and messagebox up the local path of the image.
Is that possible? Could someone provide me with an example maybe?
It's quite easy. Just enable drap-and-drop by setting the AllowDrop property to True and handle the DragEnter and DragDrop events.
In the DragEnter event handler, you can check if the data is of the type you want using the DataFormats class.
In the DragDrop event handler, use the Data property of the DragEventArgs to receive the actual data and the GetData method
Example:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True
End Sub
Private Sub Form1_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
MsgBox(path)
Next
End Sub
Private Sub Form1_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
This is just a note to state that if drag and drop does not work, it could be because you are running Visual Studio in Administrator Mode (Windows 7 and up I believe).
This also has to do with the UAC level currently set on your Windows installation.