I using teamdev-dotnetbrowser in winforms. Also I using Tab Control. How to open link in new tab when clicked Ctrl + mouse left click or mouse wheel click.
Please help me!!!
You can add a new tab to the Tab Control like this using Ctrl + left mouse click.
private void tabPage1_MouseClick(object sender, MouseEventArgs e)
{
if (Control.ModifierKeys == Keys.Control)
{
if (e.Button == MouseButtons.Left)
{
var newTabPage = new TabPage();
tabControl1.TabPages.Add(newTabPage);
}
}
}
Related
I have a simple form like this:
I open the combobox and at the time dropdown is open, I click the button. On button click I show a simple message but the message is not shown at that time.
It shows when I click it again.
The same problem for textbox. When the dropdown is open, the textbox click is not working.
Why does combobox prevent clicking other controls when it is open?
You can create an event for ComboBox DropDownClosed and with the hittestfunction, find the other control that the user has clicked.
private void ComboBox_DropDownClosed(object sender, EventArgs e)
{
Point m = Mouse.GetPosition(this);
VisualTreeHelper.HitTest(this, this.FilterCallback, this.ResultCallback, new PointHitTestParameters(m));
}
Then in the FilterCallback function after finding that control, raise the mouse down event on that control.
private HitTestFilterBehavior FilterCallback(DependencyObject o)
{
var c = o as Control;
if ((c != null) && !(o is MainWindow))
{
if (c.Focusable)
{
if (c is ComboBox)
{
(c as ComboBox).IsDropDownOpen = true;
}
else
{
var mouseDevice = Mouse.PrimaryDevice;
var mouseButtonEventArgs = new MouseButtonEventArgs(mouseDevice, 0, MouseButton.Left)
{
RoutedEvent = Mouse.MouseDownEvent,
Source = c
};
c.RaiseEvent(mouseButtonEventArgs);
}
return HitTestFilterBehavior.Stop;
}
}
return HitTestFilterBehavior.Continue;
}
private HitTestResultBehavior ResultCallback(HitTestResult r)
{
return HitTestResultBehavior.Continue;
}
The combobox is implemented the way that it captures the mouse when the dropdown is open. This is done to easyly figure out when the user clicks outside of the combobox (in fact it's a one-liner). When the user clicks outside of the combobox it releases the mouse, closes the dropdown and marks the click as handled. The last action of course stops further processing and the click is not passed to the control you thought you clicked on.
My personal opinion is this behavior has pros and cons. Microsoft decided the way it is.
I need to show a tooltip while the mouse hovers on WinForms RadGridView header cells. The tooltip's text is different based on the current cell the mouse is hovering on. I don't want the tooltip to be disappeared until the mouse leaves the cell.
Maximum time is about 24 days... I suppose it's enough :)
Best way is to use ToolTipTextNeeded event:
private void radGridView1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
{
// if cursor hover GridHeaderCellElement
var header = radGridView1.ElementTree.GetElementAtPoint(PointToClient(MousePosition)) as GridHeaderCellElement;
if (header != null)
{
e.ToolTip.AutoPopDelay = int.MaxValue; // 24.86 days
e.ToolTipText = "123";
}
}
or ( tnx to #checho )
private void radGridView1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
{
// if cursor hover GridHeaderCellElement
if (sender is GridHeaderCellElement)
{
e.ToolTip.AutoPopDelay = int.MaxValue; // 24.86 days
e.ToolTipText = "123";
}
}
I have a ToolStrip with a ToolStripDropDownButton to which I am adding ToolStripMenuItems in run time in my code. I need to have a default ContextMenuStrip and assign it to each menu item so when the user right clicks a menu item he will get that context menu strip.
Is it possible ?
I appreciate your help.
I found a good solution at: enter link description here
To save you the reading I also add the solutuin here:
void MenuItemContext(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) return;
ToolStripMenuItem mID = (ToolStripMenuItem)sender;
ContextMenu tsmiContext = new ContextMenu();
MenuItem Item1 = new MenuItem();
MenuItem Item2 = new MenuItem();
Item1.Text = "Item1";
Item2.Text = "Item2";
tsmiContext.MenuItems.Add(Item1);
tsmiContext.MenuItems.Add(Item2);
Item1.Click += new EventHandler(Item1_Click);
Item2.Click += new EventHandler(Item2_Click);
hndPass = mID.Text;
tsmiContext.Show(menuStrip1, menuStrip1.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)));
}
private String hndPass;
void Item1_Click(object sender, EventArgs e)
{
MenuItem mID = (MenuItem)sender;
MessageBox.Show("You clicked " + mID.Text + " in the context menu of " + hndPass);
}
void Item2_Click(object sender, EventArgs e)
{
MenuItem mID = (MenuItem)sender;
MessageBox.Show("You clicked " + mID.Text + " in the context menu of " + hndPass); ;
}
Have fun (-:
Seems like I worked out something useful,this is obviously not perfect but should give you a decent starting point.I assume you've a ContextMenuStrip named contextmenustrip1,some drop down items of which one is aaaToolStripMenuItem.Then create a private boolean field,
private static bool clickReleased=false;
In the MouseDown event of aaaTool... write the following code;
if (e.Button == MouseButtons.Right)
clickReleased = true;
then in MouseUp event,write this;
if (e.Button == MouseButtons.Right)
{
if (clickReleased)
{
contextMenuStrip1.Show(Cursor.Position);
clickReleased = false;
}
}
Hope this helps.
I'd like to know is it possible to:
While f1 key is pressed show tooltips of all buttons in wrappanel.
Code:
myButton.ToolTip = new ToolTip() { Content = "[CTRL + 1]" };
And I think I can handle 'while f1 is pressed', but have no idea how to show tooltip right under button (right now, when f1 is pressed, tooltip appears near cursor position).
Thanks in advance!
You can set ToolTipService.Placement="Bottom" on your Button to show tooltip at bottom.
ToolTipService.SetPlacement(myButton, System.Windows.Controls.Primitives.PlacementMode.Bottom);
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F1)
{
((ToolTip)button1.ToolTip).PlacementTarget = button1;
((ToolTip)button1.ToolTip).Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
((ToolTip)button1.ToolTip).IsOpen = true;
}
}
I have a WPF ListBox operating in single selection mode. I am adding drag and drop to move items around. Currently the ListBox selection responds to both left button pressed and then with mouse moves with left button down. So after I wait for the MinimumVerticalDragDistance to start a drag operation, a different item could be selected. Dragging either the unselected orginal item or dragging the new selected item is confusing. Adding 'e.Handled=true' in xxx_MouseMove or xxx_PreviewMouseMove does not do anything. Any ideas on suppressing this selection due to mouse moves with left button down?
The best kludge I came up with is to cancel the ListBox's "Selection by dragging" in the IsMouseCapturedChanged event.
public partial class MainWindow : Window
{
Rect? dragSourceGestureRect;
bool busy;
public MainWindow()
{
InitializeComponent();
listBox.ItemsSource = Enumerable.Range(1, 9);
listBox.PreviewMouseLeftButtonDown += listBox_PreviewMouseLeftButtonDown;
listBox.IsMouseCapturedChanged += listBox_IsMouseCapturedChanged;
listBox.MouseMove += listBox_MouseMove;
}
void listBox_IsMouseCapturedChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (busy)
return;
if (!listBox.IsMouseCaptured)
dragSourceGestureRect = null;
else if (dragSourceGestureRect.HasValue)
{
busy = true;
{
//tell the ListBox to cancel it's "Selection by dragging"
listBox.ReleaseMouseCapture();
//Now recapture the mouse for canceling my dragging
listBox.CaptureMouse();
}
busy = false;
}
}
void listBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var center = e.GetPosition(listBox);
dragSourceGestureRect = new Rect(
center.X - SystemParameters.MinimumHorizontalDragDistance / 2,
center.Y - SystemParameters.MinimumVerticalDragDistance / 2,
SystemParameters.MinimumHorizontalDragDistance,
SystemParameters.MinimumVerticalDragDistance);
}
void listBox_MouseMove(object sender, MouseEventArgs e)
{
if (!dragSourceGestureRect.HasValue || dragSourceGestureRect.Value.Contains(e.GetPosition(listBox)))
return;
dragSourceGestureRect = null;
var data = new DataObject(DataFormats.UnicodeText, "The Data");
DragDrop.DoDragDrop(listBox, data, DragDropEffects.Copy);
e.Handled = true;
}
}