In my WinForms application I have Chart control with those settings:
chartArea.CursorX.IsUserEnabled = true;
chartArea.CursorX.IsUserSelectionEnabled = true;
chartArea.AxisX.ScaleView.Zoomable = false;
where chartArea is main (and only) ChartArea object in my Chart control.
What I am trying to do is posibility of selecting area (it is possible already), and when mouse is over this area, if I left click chart cotrol inside that selected area, I wan't it too zoom in.
First problem here is how to detect if I am over selected area ? with chart.HitTest() i can get HitTestResult.PointIndex field value and compare it with selection range. But this only works, if mouse is exactly over DataPoint. So it doesn't work for SeriesChartType.FastLine which I am using.
If this gets somehow solved, next will be problem with selection cancelation after mouse click (before Click or MouseXXX events are called).
SOLVED
I've found axis.PixelPositionToValue() method, which gives me every info I need, because from MouseMove event arguments I have pixel position.
For click events problem I'll write another question.
http://www.bigresource.com/VB-Using-MsChart-MouseOver-Event-to-display-the-contents-of-array-that-populated-chart-ydWJntrg8c.html
Though this is VB.NET, the concept is the same. I think.
Related
My UWP application contains a map with several POI. I am trying to change the mouse cursor from an arrow to a hand when hovering over specific poi to indicate its clickable.
This would change the cursor as soon as it enters the map still, as a simple test, I added a PointerEntered event for the mapcontrol and within it I have the following to change the cursor:
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 0);
It appears though the cursor does change however immediately gets overridden back to the pointer cursor.
Edit: Just realised When a poi is clicked (i.e. is selected) the cursor changes to a hand even when not over the map control until the poi is unselected. No good as I would like the cursor to change dynamically when hovering over a poi and revert back to cursor when moved away.
Change pointer cursor when hovering over map elements
I'm afraid you can't edit the default cursor for map element, Because it has handled internally, it will not fired, even you has listen PointerEntered event, it consumed by the control and not passed up the control chain. If you do want this feature, the better way is post this feature with windows feed backhub app.
I don't know if it works just like WinForms, I had to do something like this to click on labels (couldn't use link-labels), what I used was in the Mouse_Move event of the label and it was basically
if (Cursor.Current == Cursors.Default)
{
Cursor.Current = Cursors.Hand;
}
and similar changes and behaviors due to the various conditions. This however got me a small issue: this statement changes the mouse graphic anytime you move on the control, but personally on Windows settings I use the trail graphic function for the mouse (leaving a trail of pointers whenever I move the mouse on the screen), what I suggested you disables this function, or better, it conceals it, since it "recreates" the mouse graphic for every move you do onto the control, and thus it "undoes" the graphic for the mouse and recreates it as a Hand (in my instance). If it doesn't concern you though, it works just fine.
Just I repeat myself: I use this on WinForms, but since it's C# I suppose it just will work(?)
I am currently using MSCharts in one of my windows forms. One of the quirky things about MSCharts is that you cannot trigger a MouseWheel event in the chart unless the chart has focus. To combat this, most people are saying that one should add a MouseEnter event to the chart and then Focus() the chart to allow one's MouseWheel events to fire (see here: Enabling mouse wheel zooming in a Microsoft Chart Control).
Let's say that I pull up a completely different window (call it Window A) that just so happens to be partially in front of my chart (call it window is Window B). If I accidentally move the mouse over the chart in Window B for even 10 milliseconds, Window B will take focus and Window A will be placed behind it, which is incredibly frustrating.
I've explored different options.
Setting Window B's TopMost property to true. The problem with this is that the user has to either close the window or minimize it to hide it. If there are a lot of windows up, it seems to be just as frustrating as the initial issue.
Instead of giving the MouseEnter event the ability to Focus(), let the MouseClick or MouseHover event to Focus(). The problem with MouseClick is that the user will always have to click on the chart first to zoom, which isn't bad, but can be annoying. MouseHover is okay, but the time that the event considers to be a hover is really short.
In the end, I want it so that I can put my mouse over the chart and scroll in without having to do anything (mouse clicks, or anything else). In addition to this, I don't want the form that contains the chart to jack the focus back to it if I accidentally move my mouse over it for just a second.
EDIT:
It seems that according to #TaW, the chart doesn't need focus to trigger MouseWheel events in Window 10. This is not the case in Windows 7, unfortunately.
This may seem slightly hacky, but it works in this case:
This works through the use of the FindForm method. I never knew it was a thing until now. You can read more about it here: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform(v=vs.110).aspx
myChart.MouseEnter+= delegate(object sender, EventArgs args) //add a mouse enter event to your chart
{
if (!chart.Focused) //if chart isn't focused
{
if (chart.FindForm().ContainsFocus) //check if the form the chart is in contains focus
chart.Focus(); //if the chart isn't focused, but the form is focused, focus on the chart
}
};
This will still give the chart focus when you move your mouse into it and it will not allow the form that contains the chart to jack the focus from the form you're in.
This question already exists:
Closed 10 years ago.
Possible Duplicate:
Click and drag image to image grid?
I have a few image boxes in my form and I was wondering how can I would place a grid across the form that have a bunch of lines so the whole grid is a bunch of 64 x 64 squares. I need it so I can select an image and place it onto a specific square using the mouse and be able to go through the whole grid and check for example how many of one specific image is on the grid. To give you a better idea of what I'm doing is that I have a few image boxs which contain different 64 x 64 images. There is another image box that shows the image I clicked on last, which is like a brush because whenever you left click a box in the grid it pastes it into that specific box in the grid. I also need it so I can right click the box and delete the image in the box the mouse is over. Finally I need to be able to read all the images in the box and output it into a file that I can later open. I'm using it to create land in a game, which the program will output the needed texture and and where ground level is for the boxs which make up the whole terrain. What I need to know is what kind of thing should I do to be able to do this? I've been trying the past few hours on how I make the boxs and how to know where the mouse is and stuff and I'm completely stuck. A simple idea would be helpful. I actually don't know what control(s) I should use for this so an idea that doesn't involve any grid controls is still very helpful.
I don't know if it's the best possible idea, but you could use FlowLayoutPanel with WrapContent set to true and FlowDirection = LeftToRight. I dont know about Drag&Drop operation though (never done it with FlowLayoutPanel, buth there are some nice tutorials out there).
You can track your mouse position using mouse events. If you don't want to do that:
You can get absolute position at any time using:
Point currentPos = System.Windows.Forms.Cursor.Position;
Then, to get relative position on your (current) control:
Point relativeLoc = this.PointToClient(currentPos)
... and then, to get control over which your mouse is on FlowLaoutPanel:
Control c = flowLayoutPanel1.GetChildAtPoint(relativeLoc);
I am working on a custom control based on a ListView control. The goal of the control is to show the events name in the first column and the event duration on a timeline on the second column. I've implemented the custom drawing for the timeline section and it all works.
Now I would like to implement a "zooming" feature. Where the user would be able to click somewhere on the second column drag the mouse and upon release the timeline would be zoomed in with starting and end times matching the mousedown/mouseup events.
Currently when I click/drag the mouse, a normal selection box appears. I would like to overide that such that I get don't get a box but more of a vertical area (so the selection is only based on the timeline axis).
I really don't know where to look and how to overide the drawing the selection box. Any pointers/sample code would be appreciated.
Well if you don't need multi selection option setting MultiSelect property to false disables rubber band selection.
When my mouse moves to the bottom of Combobox popup list, the list automaticly start to scroll down. But when I'm the bottom and goes to the top, there is no autoscrolling effect so I want to disable this behaviour, couse it only work in one way, down..
I cannot find any property, so I try to get mousemove event on that dropdown-list to cancel it, or make it handled, but it is triggered only on combobox itself, not on the list.
I also try to create something on top of that list, such as invisible panel which gets mouse move events instead of that dropdown-list, but I cannot find anything useful, couse that list is always at the top of everything.
Another idea was to find an event which is executed when items which are shown in popup list are changed and stop it when the mouse didn't grab the scrollbar, or click it, but this is also immposible. No events triggered. there is only selectedchanged event, but this is trigger on select not on the scrool.
Is there any solution to do this?
Finally I found the answer!!!
I had about 26 lines in my Combobox List, that was liitle to big so I wanted to show only 7 of them per time.
I found DropDownHeight property, and set it: Property ItemHeight was set to 13, couse the Font.Size was 8,25 (default). 7*13 = 91. And set it.
.
And it works almost perfectly, but there was a problem with autoscrooling. (which I asked above)
Finally I realised that last line (here is NNN) is not fully shown. And when mouse Enters this line, the ComboBox Control want to show me whole line and scrolls it UP.
I started to change size and find out, that the line is being shown totally when it is set to 93 (= 7*13 + 2). Why 2? Probably because a bottom and top border. And now there is no autoscrolling...
I also find, that another possibility is to set:
ComboBox1.IntegralHeight = False;
ComboBox1.MaxDropDownItems = 7;
And this works only when there was no changes in DropDownHeight, default value in my case was 106 ( = 8*13 + 2) couse the default value of MaxDropDownItems is 8.