FolderBrowserDialog position on screen. VB.Net - position

Is it possible, without an insane amount of work, to customize to location of the FolderBrowserDialog when it appears? I was hoping for the ability to position it at the left upper corner of the main form of my application.
Hoping for something like this:
Private Sub but_OpenFolderBrowser_MoveTo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles but_OpenFolderBrowser_MoveTo.Click
'Set up the folder browser
'Set description
Me.folderBrowser.Description = "Select the directory:"
'Set starting location on screen
Me.folderBrowser.Location = Me.Location
Unfortunately I realized that this property is not available and probably not feasible.
Anyone have a solution?

Related

How to add direct numbers in a text box in visual studio 2012?

I'm trying to make something like a quantity box for my finals windows form project, and when I input as simple code like:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox2.Text = HigB
HigB += 1
End Sub
Basically, what I want to happen is that when I click the button, it adds '1' to the text box, like a quantity box.
It does work but when I click the button it doesn't start with '1' directly, instead, it starts with '0'. I think the problem is with the declaration of 'HigB' which is declared as an Integer but when I tried declaring it to different a type of numerical data such as Double, etc it still doesn't work.

BackUp+Restore IDE bookmarks at a specific line of code

Well, the title is because I had a hard time walking through some unbearable docs and finding what I was looking for so, if these keywords can help for other google searches...
Then, when quitting Excel, all previously marked lines of code are lost and it is very frustrating when you have to go to sleep or Excel crashes :)
So, in a moment of pure madness I thought it could be possible, and even not too hard, to just save those line bookmarks and restore them at start up...
You will tell me there are other choices: don't sleep.. or use some powerful add-ins like MZ-Tools or Rubberduck, but I would like to have a native solution and understand what the problem is.
To cut to the edge, here is the core of my problem:
'sub to move cursor to a selected line and add a line bookmark:
Public Sub AddBmkOnly(ByVal CompName As String, ByVal numLine As Long)
Application.VBE.VBProjects("VBAProject") _
.VBComponents(CompName).CodeModule.CodePane _
.SetSelection numLine, 1, numLine, 1
Application.VBE.CommandBars("Edit").Controls(18).Controls(1).Execute 'the only way I could find it to work
End Sub
What happens:
1) with only one call it works!
Public Sub test_addBmk()
Call AddBmkOnly("module 1", 10)
End Sub
2) once there are more, or in a loop for example:
Public Sub test_addBmk()
Call AddBmkOnly("module 1", 10) 'cursor is just moved to selected line
Call AddBmkOnly("module 2", 5) 'line bookmark is added only in the last opened/activated/selected/visible/shown/focused on..? codepane
'...
End Sub
Place your cursor inside the 2nd test_addBmk, run and you will see a beautiful cyan blue mark appearing in the margin of your "module 2" at line 5 but that's all, no where else.
I well tried to add this kind of lines in AddBmkOnly to keep focus/active state, but it has no effect:
With Application.VBE.VBProjects("VBAProject").VBComponents(CompName)
.Activate
.CodeModule.CodePane.Window.SetFocus
.CodeModule.VBE.ActiveCodePane.Show
'...?
end with
I tried adding some DoEvents, Debug.Print, loop to 1M or likes to see if it was due to some latency/refreshing effect, but no effect either.
It could have something to do with the active state of the module or codepane window, but I can't find a working combination (also, closing the last pane - .ActiveCodePane.Window.Close - will avoid a bookmark to be added too).
It seems also that the focus is lost before an anchor is added, whatever I try, or the 'add bookmark' menu action doesn't see where to apply.... or it is something else...
Calling test_addBmk() multiple times doesn't work neither, the only way I found is creating 'one action' buttons in an Excel sheet, as many as the number of bookmarks I needed... that's not funny.
What am I doing wrong? Is it even possible the way I'm trying? How can I add more than a single bookmark?
You need to active the code pane before you invoke the menu item:
Public Sub AddBmkOnly(ByVal CompName As String, ByVal numLine As Long)
Dim editor As VBE
Dim project As VBProject
Dim component As VBComponent
Set editor = Application.VBE
Set project = Application.VBE.VBProjects("VBAProject")
Set component = project.VBComponents(CompName)
component.CodeModule.CodePane.SetSelection numLine, 1, numLine, 1
component.Activate
Application.VBE.CommandBars("Edit").Controls("&Toggle Bookmark").Execute 'the only way I could find it to work... almost[*]
End Sub
Note that this won't work if you try to step through it in a debugger, because each time you step it sets the active pane back to the code that you're executing.
A couple other notes:
You should be testing the number of code lines before trying to set the selection - if numLine is higher than the lines of code in the module, that's an application error.
Call should be considered deprecated - there's absolutely no reason to use it.
You should avoid hard coding an index in the Controls collection - other add-ins can modify these, so who knows what you'll get.
Thanks for mentioning Rubberduck! (I'm a contributor)
This version of the above works for me.
Public Sub test_addBmk()
Call AddBmkOnly("module1", 10)
Call AddBmkOnly("module2", 5)
End Sub
Public Sub AddBmkOnly(ByVal CompName As String, ByVal numLine As Long)
Dim editor As VBE
Dim project As VBProject
Dim component As VBComponent
Set editor = Application.VBE
Set project = Application.VBE.VBProjects("VBAProject")
Set component = project.VBComponents(CompName)
component.CodeModule.CodePane.SetSelection numLine, 1, numLine, 1
component.Activate: DoEvents
editor.CommandBars("Edit").Controls("&Toggle Bookmark").Execute
DoEvents
End Sub

How to make Chart Legend Items interactive in mschart in a web application

How to make Chart Legend Items interactive in mschart in a web application. I have tried using HitTestResult class. However to get the coordinates for X and Y locations of click, MouseEventArgs class is not supported for charts.Could someone please answer this and preferably share a code snippet.
From the question I guess you want to hide/unhide series on click of legend items. HitResult is used with the desktop version, where we get access to clicked co-ordinates using MouseEventArgs object.
However, to achieve the same on web chart, you can follow the below,
Associate series details with Legend Item's post back property when the chart is being built
legendItem1.PostBackValue = ser.Name & ";" & Chart1.Legends(ChartArea1).CustomItems.Count - 1
This post back can be used to access the clicked series on Chart's click event,
Protected Sub Chart1_Click(ByVal sender As Object, ByVal e As ImageMapEventArgs)
Dim pointData As String() = e.PostBackValue.Split(";"c)
Dim selectedSeries As Series = Chart1.Series(pointData(0))
Dim selectedlegendItem As LegendItem = Chart1.Legends("Default").CustomItems(pointData(1))
If selectedSeries IsNot Nothing Then
If selectedSeries.Enabled Then
selectedSeries.Enabled = False
Else
selectedSeries.Enabled = True
End If
End If
End Sub

New to Visual Basic

I'm completely new to visual basic and somewhat new to programming in general. I'm trying to teach myself how to use visual basic because I was told it was easier to learn. My question is how do I connect an execute button to a text box to calculate a simple math problem? Do I double click the button I want to make the execution and then put in the code? Can someone give me a simple sample code that when you enter a number in a text box and press the execute button, the number entered would be multiplied by another number like 2 or whatever and then be displayed in another box? I just need a way to understand how the coding works and connects the gui buttons and text boxes so I can understand it better. I'm good and learning on my own when I see how things work and then I can put things together and figure them out. Thanks
That's pretty much it...
...of course the devil is in the details. The main problem you'll run into in this scenario is that your TextBox holds a String, but you want to manipulate it as a Number. First you need to convert the string to a number, then do the math. This also allows you to determine if the String in the TextBox is not a number, such as if the user entered "Unicorns are real!" in it:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x As Integer
Dim strInput As String = TextBox1.Text
If Integer.TryParse(strInput, x) Then
Dim result As Integer = x * 2
Label1.Text = x.ToString & " * 2 = " & result.ToString
Else
Label1.Text = "Invalid Integer: " & strInput
End If
End Sub
End Class

visual basic adjust audio volume with a trackbar / slider

i have a program that plays background music by using this code
My.Computer.Audio.Play("bgsound.wav", AudioPlayMode.BackgroundLoop)
How can i make a TrackBar (or slider) control its volume, and keeping it extremely simple if possible! Thanks
here is what I had in mind on what it would look like
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
'get the value of trackbar in a variable
Dim Value = TrackBar1.Value
My.Computer.Audio.Volume = Value 'i know this doesn't exist. This is what i need to know what to say
End Sub

Resources