|
-
Jul 18th, 2008, 04:15 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2008] shortcut menu, left click, add in reverse order
Hello,
I have created a shortcut menu. And assigned this to the link control. When the user right clicks the link control the shortcut menu will appear.
Code:
Me.linkLabel1.ContextMenu = contextMenu1
However, is there a way to left click instead of right clicking. I could not find any property that would change this?
My menu is created dynamically as it will display the last number that was dialed. However, I want to display the last number dailed as the top one in the short cut menu. Is there a way to reverse the order of the items in the shortcut menu?
Code:
//create a new menu item
Dim menu As MenuItem = New MenuItem
'Add the number entered from the text box.
menu.Text = textBox1.Text
contextMenu1.MenuItems.Add(menu)
Many thanks,
Last edited by steve_rm; Jul 18th, 2008 at 02:45 PM.
Reason: Question not fully completed
steve
-
Jul 18th, 2008, 05:12 AM
#2
Addicted Member
Re: [2008] shortcut menu, left click, add in reverse order
I'm not sure about the left-click, but for the order of items in the shortcut menu, instead of:-
vb.net Code:
contextMenu1.MenuItems.Add(menu)
...try this:-
vb.net Code:
contextMenu1.MenuItems.Insert(0,menu)
This should insert the entry at index position 0 in the list (so the last added is always at the top).
I assume also, that you have in place some routine to check that TextBox1.Text actually has some text in it before trying to add to the Context Menu?
If my post helped you, please rate it. Thanks.
-
Jul 18th, 2008, 05:49 AM
#3
Thread Starter
Frenzied Member
Re: [2008] shortcut menu, left click, add in reverse order
I should have seen this.
vb Code:
contextMenu1.MenuItems.Add(0, menu)
Just the left click now?
Thanks,
-
Jul 18th, 2008, 12:07 PM
#4
Re: [2008] shortcut menu, left click, add in reverse order
For the left click, you can handle the LinkClicked event and manually show your contextmenu by calling its Show() method.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 18th, 2008, 12:09 PM
#5
Thread Starter
Frenzied Member
Re: [2008] shortcut menu, left click, add in reverse order
-
Jul 18th, 2008, 02:31 PM
#6
Thread Starter
Frenzied Member
Re: [2008] shortcut menu, left click, add in reverse order
Hello,
Just another question to make this compete.
How do I get the number that has been added to the shortcut menu? I have created a click event in the designer.
vb Code:
AddHandler Me.menu.Click, AddressOf menuitemRedial_Click
And the method that raises the event.
vb Code:
Private Sub menuitemRedial_Click(ByVal sender As Object, ByVal e As EventArgs)
'Get the item that has been clicked.
Dim number As String = menu.Text
End Sub
However, when I click on the number in the short cut menu. The event never fires. I want to get the number that the user clicked on.
This will display all the number that was added on the click event. As in my first post.
Then when the user clicks on the link control it displays the shortcut menu.
vb Code:
Private Sub linkLabel1_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs)
Dim p As New Point(45, 10)
contextmenu.Show(Me.linkLabel1, p)
End Sub
Many thanks for extra help,
Steve
Last edited by steve_rm; Jul 18th, 2008 at 02:43 PM.
Reason: Question not fully completed
steve
-
Jul 18th, 2008, 02:53 PM
#7
Re: [2008] shortcut menu, left click, add in reverse order
Show the code where you create a menuItem and add to your contextmenu.
As a side note, you should turn Option Strict On and make it a default setting in of VS.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 18th, 2008, 03:04 PM
#8
Thread Starter
Frenzied Member
Re: [2008] shortcut menu, left click, add in reverse order
Hello,
Thanks for the reply.
here is the code behind:
vb Code:
Private Sub RedialHistory_Load(ByVal sender As Object, ByVal e As EventArgs) Me.linkLabel1.ContextMenu = contextmenu End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) menu = New MenuItem() menu.Text = Textbox1.Text 'Get the number from the text box and add it. contextmenu.MenuItems.Add(0, menu) End Sub Private Sub linkLabel1_LinkClicked(ByVal sender As Object, ByVal e As LinkLabelLinkClickedEventArgs) Dim p As New Point(45, 10) contextmenu.Show(Me.linkLabel1, p) End Sub Private Sub menuitemRedial_Click(ByVal sender As Object, ByVal e As EventArgs) Dim number As String = menu.Text End Sub
The code in the designer:
vb Code:
Me.menu = New System.Windows.Forms.MenuItem() AddHandler Me.menu.Click, AddressOf menuitemRedial_Click Me.contextmenu = New System.Windows.Forms.ContextMenu() Private contextmenu As System.Windows.Forms.ContextMenu Private menu As System.Windows.Forms.MenuItem
-
Jul 18th, 2008, 03:17 PM
#9
Re: [2008] shortcut menu, left click, add in reverse order
Why would you go into the designer code? You should very very very rarely have to go in there. And what happens to all the Handles clauses?
For every new MenuItem you create, you need to AddHandler to it.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 20th, 2008, 08:27 PM
#10
Thread Starter
Frenzied Member
Re: [2008] shortcut menu, left click, add in reverse order
Hello,
This is how I finally finished. If there is a cleaner way then please advice.
I am not sure what is wrong with what Stanv suggested by not putting any code in the designer. I
thought that was perfectly ok to do that. Declaring and Initializing controls in the designer like I have done. Why is that a bad idea?
Many thanks,
Designer code:
Code:
Me.menu = new System.Windows.Forms.MenuItem()
Me.contextmenu = new System.Windows.Forms.ContextMenu()
private System.Windows.Forms.ContextMenu contextmenu
private System.Windows.Forms.MenuItem menu
code behind:
Code:
Private Sub RedialHistory_Load(ByVal sender As Object, ByVal e As EventArgs)
Me.linkLabel1.ContextMenu = contextmenu
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
menu = New MenuItem()
menu.Text = Me.textBox1.Text
contextmenu.MenuItems.Add(0, menu)
AddHandler Me.menu.Click, AddressOf menuitemRedial_Click
End Sub
Private Sub linkLabel1_LinkClicked(ByVal sender As Object, ByVal e As
LinkLabelLinkClickedEventArgs)
Dim p As New Point(45, 10)
contextmenu.Show(Me.linkLabel1, p)
End Sub
Private Sub menuitemRedial_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim redialMenu As MenuItem = DirectCast(sender, MenuItem)
Dim number As String = redialMenu.Text
End Sub
-
Jul 20th, 2008, 09:09 PM
#11
Re: [2008] shortcut menu, left click, add in reverse order
The designer generated code, as it's called, is generated and modified by the designer. For example, when you drop a control to your form, some code is generated automatically and when you delete a control from your form, some code is removed automatically. For this reason, a programmer should NOT edit this file manually. If you are editing or adding code to the designer file, be prepared for the designer to alter your code without warning. You should use the class file for all developer generated code.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Jul 20th, 2008, 11:47 PM
#12
Thread Starter
Frenzied Member
Re: [2008] shortcut menu, left click, add in reverse order
Hello,
Thanks for the reply.
I am interested in what you said about the class.
Not sure that I completely understand. Do you mean create a new class for that control?
Thanks,
-
Jul 21st, 2008, 08:01 AM
#13
Re: [2008] shortcut menu, left click, add in reverse order
 Originally Posted by steve_rm
Hello,
Thanks for the reply.
I am interested in what you said about the class.
Not sure that I completely understand. Do you mean create a new class for that control?
Thanks,
With VS2005 and 2008, for each form you create, there exists 3 files:
1. <formName>.vb This is called class file, and all your code should be in written in this file only
2. <formName>.Designer.vb This is the designer generated code. You should very rarely have to dig into this file since your code may get changed by the designer without you knowing it.
3. <formName>.resx This is the resource file. You should never edit this file. Just a single mistake and your form won't load any more.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|