I am trying to enable scrolling on a picturebox. I have everything working except for one nagging little detail. The focus shifts in an inexplicable way to the wrong scroll bar with the first click of the arrow key. The picture box has two scrollbars which become visible when the picture being displayed is too large. If the picture fits inside the box no scrollbars show and the vertical arrow keys behave the same as page up/down keys.
On the mouse-down event over the picture box I set the focus to the picture box object so the user can scroll with the mouse wheel. The user can then move the image one of three ways. They can click and hold and drag it up/down/right/left, or they can scroll with the mouse wheel vertically or they can use the arrow keys to scroll in all four direction. If they use the arrow keys I check PreviewKeyDownEvent on the scroll bars for which key and if it is an up/down or right/left arrow key I set the focus on either the horizontal or vertical scroll bar.
The problem is (I see this in the debugger) that when the down key is pressed (as an example) the PreviewKeyDownEvent handler runs and sets the focus (verticalBar.Focus() in this case) I see the focus shift to the vertical scroll bar, but as soon as the scope leaves the event handler it shifts to the opposite scroll bar (horizontal in this case)
I am writing a form into a third party application so I could see focus going to some default control being caused by some outside function. The odd thing is that it always goes to the opposite scroll bar from what I just set; vertical if I want horizontal and horizontal if I want vertical. Once the focus is on either scroll bar a second click on the an arrow key will shift the focus to the correct scroll bar and things will then work appropriately after that.
If the focus is already ON one scroll bar or the other it will work as expected. Focus will shift back and forth between them appropriately. But if focus starts on the picture box it will always be set to the wrong bar on the first click.
I am new to C# and GUI stuff in general so any advice will be much appreciated.
thanks
Related
I'm making an online cinema UWP app and i need to implement horizontal "gallery" with movies. The app will be used on PC, Xbox and touch devices, so i need the scrolling to be working with mouse, arrow keys and touch scrolling with swipes.
Currently I'm using ListView with ScrollViewer, but it doesn't give me the intended result. I want mouse wheel to scroll vertically, but when pointer enters the area of ListView, it starts to scroll the View horizontally. Disabling horizontal scrolling, well, breaks everything, so this pure implementaion is not an option.
I like the way MS made horizontal gallery in Microsoft Store app. It's scrollable with touch swipes and keyboard, but mouse wheel does nothing. Instead, the view shows round arrow buttons on the sides of this horizontal list like this:
I want to make something like that, but can't find any tips for controlling the scroll manually. Maybe there's any similar controls I don't know about or docs for making such control?
It should not be a big deal.
Set the VerticalScrollMode="Disabled" , VerticalScrollBarVisibility="Disabled", HorizontalScrollMode="Auto" and HorizontalScrollBarVisibility="Auto". Then set those two buttons to left and right with vertically centered alignment.
Use the ChangeView Method in the Click event handler to programmatically scroll through the contents. That's it.
My gridview is horizontally scrollable using mouse wheel by default. I need a feature which will enable the same thing using right and left arrow keys.
First of all I tried to handle KeyDown event for Gridview, it didn't work. Then I found this event Window.Current.Dispatcher.AcceleratorKeyActivated, and it captured all the keys I pressed. So the next step was what to do with scrollviewer. I tried to put my gridview in Scrollviewer in xaml, but it wasnt what I wanted. And the scrollviewer which is by default in gridview, doesn't have any functions which will enable the same thing which is done by mouse wheel. I wanted to perform PointerWheelChanged, but I didnt know what to give as eventargs. Please help me, i'm new to WInRT
P.S. I need this scrolling when the(parent) window has got the focus, but gridviewItem has not. Because if I select an item, i can switch between selected items using arrow keys. (I will not have item selection in my final app).
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.
I have a silverlight application in which I have to click on some pictures, if I hover over them for 3 seconds approx.
The problem is that if the pictures are a bit small in size, and the mouse moves a little, it moves out of the respective picture clicking area and selects another picture.
I have tried using a custom image in place of the default mouse cursor, but can this mouse be enlarged in some way so that it has a larger clicking area under it and not only the tip of the mouse pointer?
I think you're thinking about this the wrong way around. The mouse pointer simply defines a coordinate on the screen, rather than an area. If you want mouseover/click etc to be more generous, and give a wider area of interaction, you should make the target area larger.
So in the case of some small image, you can surround it with a larger area to handle the mouseover or click events, for example by surrounding it by a transparent border (note that elements with a transparent background will receive mouse events, unlike elements with no background).
In Excel, middle mouse button click work as a toggle. That is, if you press it once, it will allow you to scroll in your chosen direction till the time you click it again.
However, in Infragistics Ultragrid, this scrolling functionality is available only while middle mouse button remains pressed. How can I make Infragistics Ultragrid middle mouse button click work as in excel?
Otherwise also, what is the way to do it in winforms?
It's not as complicated as you might think. Clicking either the mouse wheel or middle button (depending on the type of Mouse the user has) fires off a MouseWheel event which must be handled and processed like any other event.
You'll need to configure a small "scrolling state machine" for you application. By this, I mean that the user is either scrolling in, say, a NormalMode, where using scroll bars or flicking up/down on the mouse wheel produces the same effect (scrolling up/down). Or, the application is in a HoverScrollingMode which occurs whenever the user has clicked the middle button (or mouse wheel) and is moving the mouse north or south of the click point.
I can't give you a programming example without seeing how your application currently handles other types of mouse events, but your overall strategy is to handle these MouseWheel events, use them to switch your application state (into, say, HoverScrollingMode) and then programmatically move the viewport up/down depending on the current position of their mouse.
Hope this helps, and good luck!