VB.Net: How to display groupbox on right click? - vb.net

I am making a VB.Net web browser, and to make the whole thing look nice, when the user right clicks, I want a groupbox to show up where the mouse was right clicked. I am using the ChromeWebBrowser.Net project on SourceForge and when I add the following code:
Private Sub ChromeWebBrowser1_MouseUp(sender As Object, e As MouseEventArgs) Handles ChromeWebBrowser1.MouseUp
If e.Button = Windows.Forms.MouseButtons.Right Then
GroupBox1.Location = (e.Location)
GroupBox1.Visible = True
Else
End If
End Sub
It should be working, but when I test it and right click on the web browser control, it does not show up. When I add the same code to the main forms code, it works fine, it just is not working on the browsing control. No errors or anything, it will just not show up. Is there something special I need to do, or can there be a workaround to this?
Thanks so much!

Honestly, this sounds more like you should be using a ContextMenuStrip. You can drop one onto your form(then add items to it), and finally after that you can set the webbrowser's contextmenustrip property to be the one you just designed.

Related

Showing a form in the position where last form was hidden (VB.net)

For a school project, I am developing software that requires the use of multiple forms.
At the moment, when a button is clicked to show a form and hide the current one, it opens in the default location that is set in the properties.
I would like it to know where the last form was hidden, so that it can open the new form in the same location. This is vital as all the forms are the same shape/size and it'll make for a better user experience if the software retains the position that it is moved into.
Thank you for any help! If you have anymore questions, please ask as this is my first time asking a question on here and don't know if I included all relevant information!
Current code for hiding, and showing the form,
This is opening the main form from another form when a button is pressed:
Private Sub btnHome_Click(sender As Object, e As EventArgs) Handles btnHome.Click
Dim Home As Form
Home = frmHome
Me.Hide()
Home.Show()
End Sub
This was fixed by using the line: frmHome.Location = Me.Location and changing the property of the StartPosition (of the form) to Manual
Thanks to this user!
https://stackoverflow.com/users/8967612/41686d6564

Nothing works anymore after building project in vb.net

I was going to build my project when i noticed i didn't put an icon,
and since i couldn't access the icon value of the original form because i used a theme i C+X the container and access it from the grey form, change it, C+V the container, built the project.
Nothing changed, all the name of the buttons and stuff are the same, but i feel like nothing is connected to the code anymore, i don't know what happened, i just recently got re-interested into coding, and i have no idea what to do, i tried some things but nothing worked, so here i am, desperate (i spent 3 days on this, i'm REALLY starting from bottom)
link to the project: http://www.mediafire.com/file/2zrbe32lzpx2qhz/SchedulerProjectVBNET.rar
Thanks in advance
It sounds like you have lost all the Handles clauses off your event handlers. As an example, if you add a Button to your form and double-click it, you will get a Click event handler like this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Note the Handles clause at the end, which is what connects the code to the event of the control. If you cut that Button from your form to the Clipboard then it no longer exists as part of the form, so that Handles clause will be automatically removed. If you paste the Button back onto the form, the Handles clause is not restored, so the method no longer handles the event.
If that's what has happened - which you can easily check just by looking at the code - then you need to restore all those Handles clauses. You can do that manually, i.e. write them all yourself in the code window, or you can have the designer regenerate them for you. To do the latter, select a control in the designer, open the Properties window, click the Events button, select the desired event and then select the appropriate method from the drop-down list.
Note that you can also double-click an event there to generate a new event handler, which can be useful for handling events other than the default event. You can generate a handler for the default event simply by double-clicking the control.

What causes Visual Studio To Change Control Names?

In one project, the names of my GUI controls are being changed at compile time.
Say, for example, I have a Label control named **lblRow0Col1".
I noticed my code was failing to find the control by name:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each ctrl As Control In Controls ' .Find("Label*", False)
If ctrl.Name = "lblRow0Col1" Then
ctrl.Text = DateTime.Now.ToShortDateString()
End If
Next
End Sub
So, I stepped through that routine and found the control I needed had been renamed to what looks like a GUI string.
lbl.Name = "07178f89-6fdd-47c7-9f84-d4d661df7554"
I created a test project to see what was going on, but this is not happening in the test project.
Is there a VS setting that tells the compiler to scramble the control names?
How do I stop this behavior?
OK, I’ve been looking at the code for that routine that populates a "details view" screen.
Before, I was filling the detail screen as soon as the Inventory Item variable changed.
I got to thinking that people rarely view the details screen, so why not just populate it after the screen was displayed? I had an event for “after displayed”, so I moved it there.
Well, I just moved it back ...and the odd behavior went away.
I don’t know what the issue was that caused that to happen, though.
The Label controls should have already been generated, but it acts like they were not until the tab screen they were on was selected.
So, there's an answer, but I'd rather someone explain to me what I did wrong.

How can you cause a combobox to loose focus?

I am developing a windows forms project in vb.net. I have added a comboBox to my form. the form automatically focuses on the comboBox. Nothing I click on causes the comboBox to loose focus. I do not want the form to focus on the comboBox because I do not want users to change the selected text in the comboBox by accidentally moving the scroll wheel.
I have tried:
comboBox1.CanFocus = False
comboBox1.Focus = false
These properties are not write-able.
InvokeLostFocus(ComboBox1, New EventArgs)
This does not throw a compiler error but it does not seem to do anything either (focus stays).
I am really stuck and can not find anything on SE or google. Any help is much appreciated.
Thanks!
You need to focus another control. Note that the form itself cannot be focused.
Something like:
label1.Focus()
If this doesn't work for you, you can try this:
Private Sub Form1_Load(sender As Object, e As EventArgs)
Me.ActiveControl = label1;
End Sub
You can even try to disable and enable the ComboBox.

close form when application loses focus

My form is displayed as TopMost on my application. The problem I have is that whenever I minimize my application or it loses focus, the form remains displaying. I want to be able to minimize my application or move to another and also hide or close my form. Once the application regains the focus, then unhide or open the form again.
Here is what I worked out on the form's closing event:
Private Sub frmNavigation_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Static Minimize As Boolean
If Minimize = True Then
e.Cancel = True
Me.Hide()
End If
End Sub
I tried using the same code in the applications WindowDeactivate event but nothing happens.
You do not show how you create the instance of your frmNavigation. I am assuming that you are using the Show Method, so just use the version of Show that you pass in the top level window. That will assign the owner of the form, it will then stay on top of your Main Form and minimize and restore with it also. If this doesn't work please show how you are creating and showing your form.
frmNavigation.Show(Me)
I was able to find an answer to the question. MSDN had an article on this very issue.
it can be found here: http://support.microsoft.com/kb/186908#appliesto