I have a picture on background in a picture box and i have another picturebox small one above the first.now second picbox is not visible its hidden i want that if user clicks and holds mouse button small picturebox displays and as soon he removes hold i.e releases click picturebox vanishes.
now i thought of doing in click event i should make small one visiable but how to check if click is pressed not released?
sorry if i messed up with question
Use the mouse down event:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
}
there you can set the focus on whatever you want
and when you release:
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
}
Why not use the MouseDown event in that case?
Related
I just started working on C# with Visual Studio & Windows Forms Applications. I was trying to create a Calculator and I was wondering if I could change the cursor type on a button which is disabled, I can't figure out how to do it, please help me thank you!
Edit: here's the code I tried to do, it only works if the button's enabled...
private void txt_current_operation_MouseHover(object sender,EventArgs e) {
txt_current_operation.Cursor=Cursors.Hand;
}
Hack Answer
Assuming the Button is contained by the Form, you can handle the MouseMove event of the Form and change the cursor from there:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Rectangle rc = txt_current_operation.RectangleToScreen(txt_current_operation.ClientRectangle);
this.Cursor = rc.Contains(Cursor.Position) ? Cursors.Hand : Cursors.Default;
}
If the Button was contained by a Panel, or some other container besides the Form, then you'd change to the MouseMove event of that container instead.
Demonstration:
I have done a bit of research but cannot seem to find what I am looking for.
What I want to do is make a "custom" button in a windows form. This would basically just be a matter of changing the default "grey" background to a custom image. A custom image would also be used for when hovering over and clicking the button.
This is not just a matter of changing the background image as the image I want to use has rounded edges with a transparent background and I want custom image for hovering / clicked. I want everything else about the button to behave in the same manner as a normal button.
Is this possible?
It is called owner-drawn button
refer to:
Mick Dohertys' .net Tips and Tricks - Tips / Button
GlowButton - A Glowing Button Control
A shiny orb button in GDI+
The solution I found was to set the FlatStyle of the button to Flat and set all the borders to 0. I then had a problem with the focus of the button (it displayed a little border). To solve this I followed this tutorial:
http://dotnetstep.blogspot.com/2009/06/remove-focus-rectangle-from-button.html
With this in place all I had to do was add events to the button so that the image was changed when a certain action was carried out on it:
private void button1_MouseLeave(object sender, EventArgs e)
{
this.button1.Image = Properties.Resources._default;
}
private void button1_MouseEnter(object sender, EventArgs e)
{
this.button1.Image = Properties.Resources._hover;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
this.button1.Image = Properties.Resources._clicked;
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
this.button1.Image = Properties.Resources._default;
}
Hope this will help someone else!
I have a user control with 2 buttons, that should only be visible when the mouse is inside the area of the control.
I'm showing the buttons like this:
private void Node_MouseEnter(object sender, EventArgs e)
{
btn1.Show();
btn2.Show();
}
And hiding like this:
protected override void OnMouseLeave(EventArgs e)
{
if (this.ClientRectangle.Contains(this.PointToClient(Control.MousePosition)))
return;
else base.OnMouseLeave(e);
}
private void Node_MouseLeave(object sender, EventArgs e)
{
btn1.Hide();
btn2.Hide();
}
The problem is that sometimes (random situations) the MouseLeave event is not fired, and the buttons stay visible, even with the mouse outside the control.
Is it possible that multiple events get in conflict ?
As this link states:
Mouse move messages are not accurate enough, they don't guarantee that every traversed pixel is reported. When you have a child window close to the edge of its parent, it is quite easy to not get the MouseEnter for the parent when you move the mouse fast enough.
So, the solution was to listen only for the MouseEnterevent, and when this event is fired, i send a notification to the other controls, to hide its buttons.
Is not the most elegant solution, but it works as expected.
How do I handle right click in RichTextBox in C#?
For example:
When I right-click mouse over a RichTextBox the program will display a MessageBox.
You have to catch Mouse_Down event, not Mouse_Click as follows:
private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show("you got it!");
}
}
Subscribe to the MouseClick event and check the MouseEventArgs.Button property to see which button was clicked.
What have you tried for yourself?
click RichTextBox in design mode .Right click and select properties and Then navigate to MouseDown Event.Double click that event and you will be directed to Code behind page and there you can write your code.
Is it possible that in a ListView whenever an Item has been selected (e.g mouse 1 left click or Key down or key up, left right) that item gets activated (Like when you hit enter or double click!). What event or properties of ListView will do this, if any?
UPDATE
I found out it will work if ListView.Activation is set to OneClick but thi is only for the mouse, I want the same with keyboard arrows too.
You can do that by listening the the ItemSelectionChanged event and simply calling the code that runs whenever an item is double-clicked.
Alternatively you can call ItemActivate event that fires when an item is double-clicked using this bit of code, although I'd recommend the first method:
private void ListView1_ItemSelectionChanged(Object sender, ListViewItemSelectionChangedEventArgs e)
{
ListView1_ItemActivate(sender, e);
}
You, have mouseclick and mousedoubleclick events in the listview control for this purpose.
Implement the following events with whatever you want your listview to do.
KeyDown , KeyUp, KeyPress, MouseDown, MouseUp, MousePress, MouseHover, MouseEnter, MouseClick, MouseDoubleClick
those are only a few select examples.
Lets say your listview is named listView1
to Subscribe to one of the events, do this
private void Form1_Load(object sender, EventArgs e)
{
listView1.KeyDown += new KeyEventHandler(listView1_KeyDown);
}
void listView1_KeyDown(object sender, KeyEventArgs e)
{
throw new NotImplementedException();
}
Enter your content at the throw statement