Mouse right in textbox - c#

I everyone,
I have development this application, ... my objective is user, if click on right side of the mouse the url is paste to textbox.
MenuStrip
But when i click in right side, appear the menustrip of textbox. My question is I can disable this "menustrip"?!?
I send my code at the moment:
private void TxtUrl_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
TxtUrl.Paste();
}

This should work for your code:
private MouseButtons e_Button = new MouseButtons();
private void TxtUrl_MouseDown(object sender, MouseEventArgs e)
{
e_Button = e.Button;
if (e.Button == System.Windows.Forms.MouseButtons.Right)
TxtUrl.Paste();
}
private void cms_Opening(object sender, CancelEventArgs e)
{
if (e_Button == System.Windows.Forms.MouseButtons.Right)
e.Cancel = true;
}

Related

c# winform I can't access the data I moved in the drag drop event

private void lbxMevcutOlmayanUnvanlar_DragOver(object sender, DragEventArgs e)
{
if (e.KeyState == 1)
{
e.Effect = DragDropEffects.Copy;
}
}
private void lbxMevcutOlmayanUnvanlar_DragDrop(object sender, DragEventArgs e)
{ MevcutOlmayanUnvanlarDataSource.Rows.Add((DataRow)e.Data.GetData(typeof(DataRow)), (DataRow)e.Data.GetData(typeof(DataRow)));//I cannot access the data in e.data
}
private void lbxMevcutUnvanlar_MouseDown(object sender, MouseEventArgs e)
{
Point point = new Point(e.X, e.Y);
int sira = lbxMevcutUnvanlar.IndexFromPoint(point);
if (e.Button == MouseButtons.Left)
{
lbxMevcutUnvanlar.DoDragDrop(lbxMevcutUnvanlar.Items[sira], DragDropEffects.Copy);
}
}
enter image description here
enter image description here
The data comes in rows one below the other. actually it should come as columns under the name of "bipkod" and "bipaciklama".

How to Show ContextMenuStrip Above the Mouse Postion?

I'm trying make a contextMenuStrip with Notify Icon, But I can't put the location of this Context above the mouse Position. it's show at same position mouse
Context menu strip position Image
private void ntfy2_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
contextMenuStrip1.Show(Cursor.Position.X, Cursor.Position.Y); //Show at Postion Mouse
}
}
Does this code help you?
private void ntfy2_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var relativeClickedPosition = e.Location;
var screenClickedPosition = (sender as Control).PointToScreen(relativeClickedPosition);
contextMenuStrip1.Show(screenClickedPosition);
}
}
#DuckFterminal if my post helped you enough, please click on bird of acceptance, ok? :)

C# Drag and Drop picturebox 2

I have a problem. I have a group of picturebox to be dragged into one picturebox. How to disable a specific picturebox after being dragged?? So, it can't be dragged anymore.
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.All);
}
private void pictureBox2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void pictureBox2_DragDrop(object sender, DragEventArgs e)
{
if ((e.Data.GetDataPresent(DataFormats.Bitmap)))
this.pictureBox2.Image = (Bitmap)(e.Data.GetData(DataFormats.Bitmap));
}
Instead of dragging the PictureBox's Image, drag the PictureBox.
When dropped, set it's Tag property to true.
In the MouseDown event, check if the Tag property is null, and drag only if it is.
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && pictureBox1.Tag == null)
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.All);
}
private void pictureBox2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(PictureBox)))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void pictureBox2_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(PictureBox)))
{
var picturebox = ((PictureBox)e.Data.GetData(typeof(PictureBox)));
picturebox.Tag = true;
this.pictureBox2.Image = picturebox.Image;
}
}

Drag a WPF window around the desktop with a button

I have this code for dragging my Window with its MouseDown Event.
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
But I want to do this using a Button, because my form is transparent. And Using the same function for that button's MouseDown event will not work.
How can I achieve this?
You have to use PreviewMouseDown instead of MouseDown event.
And do not forget to mark the event "Handled" in the end.
XAML code:
<Button x:Name="Button_Move" PreviewMouseDown="Window_Main_MouseDown"/>
C# code:
private void Window_Main_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
{
this.DragMove();
e.Handled = true;
}
}
Use border instead of Button. Because DragMove only work on PrimaryMouseButton event. Not work on Click event
XAML
<Border Background="Blue" MouseLeftButtonDown="Border_MouseLeftButtonDown">
</Border>
CODE
private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
My Finally Code was here:
private Point startPoint;
private void btnChat_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
startPoint = e.GetPosition(btnChat);
}
private void btnChat_PreviewMouseMove(object sender, MouseEventArgs e)
{
var currentPoint = e.GetPosition(btnChat);
if (e.LeftButton == MouseButtonState.Pressed &&
btnChat.IsMouseCaptured &&
(Math.Abs(currentPoint.X - startPoint.X) >
SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(currentPoint.Y - startPoint.Y) >
SystemParameters.MinimumVerticalDragDistance))
{
// Prevent Click from firing
btnChat.ReleaseMouseCapture();
DragMove();
}
}

Double click to Windows form in C#

How can I detect, which mouse button have double clicked the form i.e. Left, Right or Middle?
Updated:
I am using .NET2.0
Store the last clicked button in MouseUp event and then check that in the double click event. Sample code:
MouseButtons _lastButtonUp = MouseButtons.None;
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
_lastButtonUp = e.Button;
}
private void Form1_DoubleClick(object sender, EventArgs e)
{
switch (_lastButtonUp)
{
case System.Windows.Forms.MouseButtons.Left:
MessageBox.Show("left double click");
break;
case System.Windows.Forms.MouseButtons.Right:
MessageBox.Show("right double click");
break;
case System.Windows.Forms.MouseButtons.Middle:
MessageBox.Show("middle double click");
break;
}
}
Have a look at MouseDoubleClick and MouseEventArgs and MouseButtons Enumeration
MouseDoubleClick is one of the Form events.
In Whatever_Click or DoubleClick event, you can check the MouseEventArgs e, which contains what key was pressed.
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
Console.WriteLine("Left Mouse Button was clicked!");
else if (e.Button == MouseButtons.Middle)
Console.WriteLine("Middle Mouse Button was clicked!");
}
Other buttons include MouseButtons.Right, MouseButtons.Left
in form_MouseDoubleClick event you can trace
void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Do Operation
}
}

Categories