How to hide context menu item when mouse out on grid - vb.net

I am using windows forms with vb.net. This form has infragistics ultra win grid. with context menu item. The item name is "Delete Item". But when the user performs mouse out from grid i want to hide context menu item and when user hover back to the grid i want to show the context menu item. How can i do this.

Step 1) write code to handle the 'BeforeToolDropdown' event
example method signature:
Private Sub ultraToolbar_BeforeToolDropdown(sender As Object, e As
BeforeToolDropdownEventArgs) Handles ultraToolbar.BeforeToolDropdown
Step 2) this gets you a very important eventArgs object. Check to see if the click occurred in the Ultragrid
If IsNothing(TryCast(e.SourceControl, UltraGrid)) Then
Step 3) Finally you want to disable the PopupMenuTool
Dim p As PopupMenuTool = CType(utb.Tools("key"), PopupMenuTool)
p.InstanceProps.Visible = DefaultableBoolean.False
Note: in the example, the PopupMenuTool was located on an UltraToolbarsManager

Related

Use control's events if when it is contained in a custom control

I created a custom object, name: MyList.
This Object contains a picturebox and a grid.
I need to do something if the user press on this grid, so i have to "use" MouseDown events of the grid.
I used this event in the MyList project (i can save in a propriety the result for example) but in hosts project can't.
I have only the MouseDown event of the MyList, so if i press on the "form" of the object, this events works, but if i press on the grid of this MyList.
So, i can use MouseDown Event of MyList, but how i can use Grid Events?

VB.net how to get the value from my user control textbox

I do have a project for daily monitoring, and I have a problem getting the text from my textbox wherein my textbox is in my usercontrol.
the scenario would be, if I click the show button, the userControl.vb would be called in my panel and I dont have a problem putting up userControl.vb to my panel, if I click save button which will check if all fields are fill-up before saving the data. I would save as normal and wont check my panel where I load up my userControl.vb
this my snippet project tree:
DXApplication
|_My Porject
|_User Control <folder>
|_userControl.vb <user control form>
|_frmMainActivity <winForm>
here is my code for loading the userControl in my Panel
Friend ctrlUser As UserControl
ctrlUser = New userControlx
ctrlUser.Dock = DockStyle.Top
pnlActivity.Controls.Clear()
pnlActivity.Controls.Add(ctrlUser)
here is code for calling the textbox from userControl from another sub to check if the code can get the text.
*edited the userControl should be userControlx*
Dim uc As New userControlx
Msgbox(uc.txtLatitude.text)
when i hit the trigger button to show what text i put on my textbox i would return msgbox with empty string.
Any suggestion? where did I go wrong on calling the value of the textbox?
I've tried using:
Dim uc As New userControlx
uc.txtLongitude.text = "Test Text"
msgbox(ux.txtLongitude.txt)
It will return the Test Text, But in my UI the textbox that is loaded is empty.
in the trigger button you create a new instance of userControl, thats why the content of your textbox is emtpy
instead use
Msgbox(ctrlUser.txtLatitude.text)

Loading UserControl within a Child Window

I have a child window created in silverlight. I need to load a user control within the child window(for a content change in the same child window) on a button click.
How can i acheive this?
Say for Example: If i have a child window with a Header -> Content -> Button.
I just need to change the content part and the button part on click of the button.
I need to change the buttons also since navigation is not possible using the same button click events.
Is it possible to acheive this in Silverlight 4.0 or 5.0?
Here is one way to do it. Create a canvas to hold the content and on button click, add the user control and add it as a child to the canvas. If you want to change the button, rather than changing the button, in the same button click the button content to a different text.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
SilverlightControl1 control1 = new SilverlightControl1();
top.Children.Add(control1);
}
Hope this helps.

Checked ToolStrip Submenu Items

I'm trying to create a menu in VB.Net where one item in the menu has a submenu that sprouts off to the side when the user hovers over it. In other words, a completely ordinary submenu that everyone's used a million times.
My main menu items are of class ToolStripMenuItem. I can get close to the behavior I want by using the item's "DropDown" member. This creates the submenu behavior correctly, but I also need to be able to check and uncheck the items in the submenu. I've set the submenu items' "CheckOnClick" property to True, but checkboxes are still not displayed when I run the program.
Is it possible to get this behavior? Is it possible with ToolStripMenuItem?
Here's the code I currently have, which gets close, but doesn't give me checkboxes:
Dim mainItem As ToolStripMenuItem = New ToolStripMenuItem()
mainItem.Text = "Click For Submenu"
Dim subMenu As ToolStripDropDown = New ToolStripDropDown()
For Each item As ToolStripMenuItem In listOfItems
item.CheckOnClick = True
subMenu.Items.Add(item)
Next
mainItem.DropDown = subMenu
Try getting rid of that subMenu variable and change the code this way:
For Each mi As ToolStripMenuItem In listOfItems
mi.CheckOnClick = True
mainItem.DropDownItems.Add(mi)
Next

Windows Forms: Unable to Click to Focus a MaskedTextBox in a Non TopLevel Form

Like the title says, I've got a Child form being shown with it's TopLevel property set to False and I am unable to click a MaskedTextBox control that it contains (in order to bring focus to it). I can bring focus to it by using TAB on the keyboard though.
The child form contains other regular TextBox controls and these I can click to focus with no problems, although they also exhibit some odd behavior: for example if I've got a value in the Textbox and I try to drag-click from the end of the string to the beginning, nothing happens. In fact I can't use my mouse to move the cursor inside the TextBox's text at all (although they keyboard arrow keys work).
I'm not too worried about the odd TextBox behavior, but why can't I activate my MaskedTextBox by clicking on it?
Below is the code that shows the form:
Dim newReportForm As New Form
Dim formName As String
Dim FullTypeName As String
Dim FormInstanceType As Type
formName = TreeView1.SelectedNode.Name
FullTypeName = Application.ProductName & "." & formName
FormInstanceType = Type.GetType(FullTypeName, True, True)
newReportForm = CType(Activator.CreateInstance(FormInstanceType), Form)
Try
newReportForm.Top = CType(SplitContainer1.Panel2.Controls(0), Form).Top + 25
newReportForm.Left = CType(SplitContainer1.Panel2.Controls(0), Form).Left + 25
Catch
End Try
newReportForm.TopLevel = False
newReportForm.Parent = SplitContainer1.Panel2
newReportForm.BringToFront()
newReportForm.Show()
I tried your code and got a good repro this time. As I mentioned in my original post, this is indeed a window activation problem. You can see this in Spy++, note the WM_MOUSEACTIVATE messages.
This happens because you display the form with a caption bar. That convinces the Windows window manager that the window can be activated. That doesn't actually work, it is no longer a top-level window. Visible from the caption bar, it never gets drawn with the "window activated" colors.
You will have to remove the caption bar from the form. That's best done by adding this line to your code:
newReportForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Which will turn the form into a control that's otherwise indistinguishable from a UserControl. You can still make it distinctive by using this code instead:
newReportForm.ControlBox = False
newReportForm.Text = ""
Either fix solves the mouse click problem.
This is a miserable bug and it took me a long time to find this question. We're doing exactly the same thing as the OP, displaying a Form inside a split container. My workaround was to add an event handler to the MaskedTextBox's Click event:
private void MaskedTextBoxSetFocus(object sender, EventArgs e)
{
var mtb = (MaskedTextBox)sender;
mtb.Focus();
}
This works for the MaskedTextBox but I'm concerned about other odd behavior due to this bug so I will probably set the border style as in the accepted answer.
The text box behavior is a symptom of the same problem. Something is swallowing mouse down notifications. It isn't explained by your code snippet. Forms indeed swallow the mouse click that activates them, but that is a one-time behavior and is turned off by setting its TopLevel property to False.
Not much left. One candidate is the Control.Capture property, turned on at the MouseDown event for a button so that the button can see the MouseUp event, no matter where the mouse moved. That's a one-time effect as well. Watch out for controls that set the Focus in a MouseDown event.
The other is some kind of IMessageFilter code in your form(s) that's eating WM_LBUTTONDOWN messages.