Creating A Menu programmatically DevExpress - windows

How to create a menu dynamically?
In detail I want to:
Create a new ribbon page (tab, I think it's called ribbon page)
Next create a title for the page
Next add 2 ribbon groups and add titles to them
Next add 3 bar button items to the first ribbon group
How to accomplish this?

Dim menu As New RibbonControl
Dim aPage As New RibbonPage("Nicks Page")
'groups
Dim aGroup1 As New RibbonPageGroup("1st Group")
'ADD BUTTONS TO RIBBON GROUP HERE
Dim i As New DevExpress.XtraBars.BarButtonItem()
i.Caption = "Nicks Button"
aGroup1.ItemLinks.Add(i)
Dim i2 As New DevExpress.XtraBars.BarButtonItem()
i2.Caption = "Nicks Other Button"
aGroup1.ItemLinks.Add(i2)
aPage.Groups.Add(aGroup1)
menu.Pages.Add(aPage)
Me.Controls.Add(menu)

Related

E4 RCP How to set selection of ToolBarItem that contains Radio Buttons

In Eclipse E4 (Luna), using the application model to create parts, handlers, commands, handled menu items etc, (these are not created programatically). I have a toolbar. This contains a sub-Menu item called "Filter" that contains another sub-menu of two filters. The two filters are two Handled Menu Items which are set up as "Radio" Buttons.
When I select the appropriate in the UI of my running app from the selection, the Radio button switches just fine to the selected Item. However I would like this selection to update (deselecting one Radio button and selecting the appropriate radio button of the handled menu item) when my ViewPart changes through other UI selection. Currently my ViewPart updates, but the Radio buttons are on the same previous selection through the UI.
Is there a way in which I get access both Handled Menu Item's IDs and set the selection (one to false, the other to true) when the viewer is updated.
Image of design is attached below:
Hierarchy of the application model is as follows:
Thanks in advance,
Marv
You can use the model service to find menu items. Use something like:
#Inject
EModelService modelService;
#Inject
MApplication app;
List<MMenuItem> items = modelService.findElements(app, "menu item id", MMenuItem.class, Collections.emptyList(), EModelService.IN_MAIN_MENU);
Once you have the MMenuItem you can call the setSelected(boolean) method to change the selection.
To find a menu item which is in a Part menu use:
modelService.findElements(app, "menu item id", MMenuItem.class, Collections.emptyList(), EModelService.IN_PART);
(IN_PART argument instead of IN_MAIN_MENU).
You could also specify the MPart rather than the Application as the first argument to findElements which may speed up the search.
For menus as a child of a Tool Bar Item it appears that the model services cannot find these directly. However you can find the Tool Bar Item and look at the menu yourself:
List<MToolItem> items = modelService.findElements(app, "tool bar item id", MToolItem.class, Collections.emptyList(), EModelService.IN_PART);
MToolItem item = items.get(0);
MMenu menu = item.getMenu();
List<MMenuElement> children = menu.getChildren();
... search menu elements
I solved this by starting with MPart PartID and drilling down to the HandledMenuItems on which I wanted to set the Radio Button selections, then setting the selection property for each individual HandledMenuItem.
This can probably be refactored to be more concise, but I've left the code with each step to have the solution easier to read.
BTW, in every instance / combination of the EModelService methods, the list returned a size of 0. So I'm not certain if that will work for what I'm trying to achieve. The following does work, although I'm not certain it is the most efficient means.
I hope this helps others.
// Get view part
MPart viewPart = _partService.findPart("part_id");
// get list of all menu items from the Part
List<MMenu> viewPartMenu = viewPart.getMenus();
// Get list of ViewMenus from viewPartMenu there is only one View Menu so it will be index 0
MMenu viewMenu = viewPartMenu .get(0);
// Get list of MMenuElements from the viewMenu - the children in the view menu
List<MMenuElement> viewMenuElements = viewMenu.getChildren();
// This gets me to the 2 HandledMenuItems
// Upper Most HandledMenuItem Radio Button is at viewMenuElements index 0. This is cast to MHandledMenuItem
MHandledMenuItem upperHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(0);
// Set Selection
upperHandledMenuItem.setSelected(false);
// Lower Most HandledMenuItem Radio Button is at viewMenuElements index 1. This is cast to MHandledMenuItem
MHandledMenuItem lowerHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(1);
// Set selection
lowerHandledMenuItem.setSelected(true);

Event Handlers for Dynamic Table Layout Panel in Visual Basic

I am making a risk-type game for school that dynamically creates a 4x4 grid of buttons inside a table layout panel in visual basic. I have successfully created the panel and buttons with names that correspond to the row and column of the button. There are also two parallel arrays - one for button owner and the other for button number - that correspond to the owner of the button and the number of "armies" in the button. My issue is that when the user clicks a certain button, I need to reference the button name/value to know how many "armies" the button has to control the "attack" portion of the player's turn.
The following code creates the table layout panel and the buttons with names.
'Create table Dynamically
Dim ColCount As Integer = 4
Dim RowCount As Integer = 4
Dim f As New System.Drawing.Font("Arial", 15)
riskTable.AutoScroll = True
riskTable.Dock = DockStyle.Fill
riskTable.ColumnCount = ColCount
riskTable.RowCount = RowCount
For rowNo As Integer = 0 To riskTable.RowCount - 1
For columnNo As Integer = 0 To riskTable.ColumnCount - 1
Dim buttonname As String
buttonname = "B" & rowNo & columnNo
Dim button As Control = New Button
button.Size = New Size(179, 100)
button.Name = buttonname
button.Text = "1"
button.ForeColor = Color.White
button.Font = f
AddHandler button.Click, AddressOf buttonname_Click
riskTable.Controls.Add(button, columnNo, rowNo)
Next
Next
Me.Controls.Add(riskTable)
This is the dynamic event handler that I created. I tried using 'Me.Click' to get the name of the button, but it only returns the name of the form. I need to have code in here that references the name of the currently clicked button to then in turn reference the box owner and box number arrays.
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
MessageBox.Show(Me.Name)
End Sub
Any help would be greatly appreciated! I think that once I get this working, the rest of the game will be pretty simple to figure out.
Thanks!
Put the name in 'button.Tag' instead/also:
button.Tag = buttonname
Then it is easy to get the name with:
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
Dim result As String = CType(CType(sender, System.Windows.Forms.Button).Tag, String)
End Sub
(Check the System.Windows.Forms.Button though, might need some tweak to match your buttons inside the table. riskTable.Controls.button ?)

How to append a dynamic menu item after call CMenu::LoadMenu?

In my project, there is a menu that need to be appended an item dynamically.
In original code, items in the menu are stationary. So the menu is defined in the resource file:
IDM_SERVER_OPTIONS MENU DISCARDABLE
BEGIN
POPUP ""
BEGIN
MENUITEM "&Connect", IDC_LAUNCHITEM_CONNECT
MENUITEM "&Delete", IDC_REMOVE_SERVER
END
END
and is loaded in the code:
CMenu menu;
menu.LoadMenu(IDM_SERVER_OPTIONS);
Now, there is a new requirement that need to append a dynamic menu item after load the resource menu. I referred this aricle:
Dynamic menu using mfc
Followed it, I wrote these code:
CMenu menu;
menu.LoadMenu(IDM_SERVER_OPTIONS);
CMenu *autoConnectMenu = new CMenu;
autoConnectMenu->CreatePopupMenu();
autoConnectMenu->AppendMenu(MF_STRING | MF_ENABLED,
IDC_MENU_AUTO_CONNECT_SERVER,
utils::LoadString(IDS_MENU_AUTO_CONNECT_SERVER));
menu.AppendMenu(MF_POPUP,
(UINT)autoConnectMenu->m_hMenu,
L"auto connect server");
Unfortunately, it doesn't work. The new menu item "auto connect server" can't be displayed.
Then, I tried the HMENU function:
CMenu menu;
menu.LoadMenu(IDM_SERVER_OPTIONS);
AppendMenu((HMENU)menu.GetSubMenu(0),
MF_STRING | MF_ENABLED,
IDC_AUTO_CONNECT_SERVER,
utils::LoadString(IDS_MENU_AUTO_CONNECT_SERVER));
It works fine!
I want to know what problem in my former code? Appreciate!
I think that I have found the issue. I should have called
menu.GetSubMenu(0)->AppendMenu(...);
instead of
menu.AppendMenu(...);

get cursor position another form in windows application

I have two form in my application i am calling two form together from master page.i wrote code in my master page
in top i declared like this
Dim form As New FrmDelivary
Dim frm1 As New FrmrecievedDelivaryRequest
in toolstrip menu event like this:
Dim frm1 As New FrmrecievedDelivaryRequest
frm1.Location = New Point(625, 225)
frm1.MdiParent = Me
frm1.Show()
Dim frm2 As New FrmDelivary
frm2.Location = New Point(965, 0)
frm2.MdiParent = Me
frm.show()
if i press R i want to go my cursor the particular textbox of FrmrecievedDelivaryRequest
if i press D i want to go my cursor the particular textbox of FrmDelivary
How can I do this? i trey something like this in frmMaster_KeyDown event: but same page is showing again. I have already open instance of FrmDelivary, so I don't want to show same page again. I want to just get cursor position to particular textbox of this form
If e.KeyCode = Keys.A Then
form.Show()
form.txtTicket.Focus()
Cursor.Position = form.txtTicket.Location
end if
I am working on vb.net windows application
After
frm1.Show()
place
frm1.txtTicket.Focus()
I don't think you need the Cursor.Position call
Set your frm1 and frm2 variables at the top of the code window so they are accessible from all of the Subs. In your KeyDown event, put
If e.KeyCode = Keys.A Then
frm1.Show()
frm1.txtTicket.Focus()
Cursor.Position = frm1.txtTicket.Location
end if
The problem is that you are instantiating a new copy of the form with the "AS NEW frmDelivery" statement.

Lists box manipulation on button click in VB 6.0

Hello
I am doing a small I.T assignment where we have to create a database library type borrowing system and I have two list boxes listbox 1 is where all the games are listed and you can chose to borrow them the other one is where the games go to after you click the button that transfers them to listbox 2.
Aso how can I add a button that when you click it adds a new Item (game) to the first listbox and so you can borrow that one two
Thank you for your help.
Assuming two list boxes (listbox1 and listbox2) and a command button (cmd1) on a VB 6 form named Form1
private sub Form_Load()
listbox1.AddItem "game 1"
listbox1.AddItem "game 2"
listbox1.AddItem "game 3"
end sub
Private Sub cmd1_click ()
If listbox1.listindex >-1 then
'Add the selected item from listbox1 to list box 2
listbox2.AddItem listbox1.List(listbox1.ListIndex)
'Remove selected item from listbox1
listbox1.removeitem(listbox1.listindex)
End If
End Sub

Resources