Transparent overlay which does not scroll with its parent - winforms

I would like to have a form which has a few controls as transparent overlays over a bitmap. This bitmap is subject to transform matrix (zoom & scroll). I'm trying to achieve a look similar to GoogleMaps where the controls do not move when the background image is panned/zoomed.
I've tried to mimic this in my OnPaint. However, when the window is scrolled only the newly exposed area gets invalidated so my control doesn’t repaint.
I've tried to calculate where the old control was, invalidate that area, and also invalidate the area where it's supposed to have been. When I do this it flickers and you can still see the image as its scrolled.
I tried to put a ButtonControl on my display window. However, it always scrolls with its parent control. I tried to capture the scroll events and then adjust the position of the ButtonControl. This also has a delay update effect so it looks not so good.
Any ideas would be greatly appreciated.

It sounds to me like you need to Invalidate() your control wich handles the OnPaint event.

Unfortunately, you get the flicker because the Auto-scrolling mechanism sets its position, and then you restore it. The result is two messages being sent to the button.
Place your bitmap and scroll logic in a separate control that fill the entire form. That means both your bitmap control and the button are child controls of the form.
Alternatively, draw the button yourself. You will then of course need to do some work on getting it to respond to mouse clicks etc. The ControlPaint class has methods that help you mimic the appearance of Windows controls.

Related

RichTextBox scroll to end not working when not visible

I have a WPF RichTextBox in my application that sits in Grid. It gets updated every second or two as it displays logs (though sometimes there are no logs for up to a minute depending on the load).
The grid is not always visible, as it sits in its own tab. If the user is on another tab, the logger is not visible.
My problem is that I want the RichTextBox to scroll to the end every time a new paragraph is added. It seemed simple as there is a 'ScrollToEnd' method on the RichTextBox control and so I call that method every time text is added to the control.
The problem is that that method only works if the control is visible, if the user is on another tab, the RichTextBox will not scroll to the end and it looks weird when you click on the tab with the logger and after a couple of seconds or longer it scrolls to the bottom when it should already be at the bottom.
Is there a way around this annoying "feature" of the control? I would like to ALWAYS have the RichTextBox be at the bottom unless the user is manually taking control of the scroll bar.
Thanks!
By default, the TabControl actually doesn't change its contents visibility, it removes them from the view completely when you change tabs and then "re-attachs" them when you navigate back to the previous tab.
That's why the Visibility change doesn't get fired. Instead, you should handle the Loaded event, which should get fired right before the view is re-rendered.
Is there a reason you cannot simply call ScrollToEnd in response to the text box becoming visible? That seems like the simplest approach. Did you try it and run into an issue?
Edit: If you are using a TabControl, each TabItem has an IsSelected property you can bind to from the ItemContainerStyle. You could probably scroll your text box in response to the tab becoming selected.
As a separate note: if you are planning to make a custom control for this, here are some things to consider.
I wrote an auto-scrolling version of a FlowDocumentScrollViewer. (I never needed a RichTextBox specifically, but they display similar content.) I can tell you that there are a lot of things to account for, such as knowing when and when not to auto-scroll based on what the user is currently doing.
For example:
If the user takes over the scrolling themselves via the scrollbar or mousewheel, you don't want the control to fight with them.
If they start selecting text, you don't want to scroll it away from them mid selection.
If they scroll to the bottom, you probably want it to start auto-scrolling again.
Also, determining what the user is doing to begin with can sometimes be a complex process on its own.

wpf user control to display on top of current view

I wish to have a user control in my application. The behavior should be similar to a tooltip. That means, when I move the mouse inside my view, this user control also moves.
How to achieve this.
I do not wish to have draggable canvas, just that the top and left of the control change. Actually what i wish to achieve is quite similar to a magnifier. But instead of displaying a digital zoom image I wish to display a cropped image inside the magnify viewer.
You can also use the Adorner class. Hope this solves your problem.
Adorner Class Description (MSDN)

Silverlight Custom Loading Screen Like MBProgressHUD

Just wondering if anybody has any advice on making a custom loading indicator/HUD for silverlight that resembles the MBProgressHUD for the iphone.
https://github.com/jdg/MBProgressHUD
All I want is a busy indicator, like the one that comes with the silverlight toolkit but to style it like the MBProgressHUD with a spinning loading indicator.
Any ideas?
Thanks
Just create a custom control with appropriate animations and elements arranged in a circle (see rotate transforms).
You may wish to use a timer in the code behind but if you do, be sure to un-hook the event handler when the progress indicator is no longer displayed or you will leak memory.
If you then want to use it as the one in the silverlight toolkit just use your control in a controltemplate for the busy indicator in the silverlight toolkit. Alternatively just create your own version of the control (Alignment set to center, visibility to show/hide, a background which fills the screen if you need it to disable clicking on the form behind, but it as the last item in your layout-root so it's on top).

Need to know when the window is resized by user

I created a user control in Silverlight, so now I can siply reuse it multiple times anywhere I want. This control also uses a popup. When the popup is opened, I programatically set its position so it looks like anchored to the control. But when this popup is already visible and user changes size of Internet Explorer window, the contens of page are moved and the popup is not moved. [Obviously.] So it doesn't look like anchored to the control anymore. How to fix it? Which event to handle?
I expect there is some event which is fired when user changes size of the window. Or even better an event which can inform me when the owning control is repositioned, so I know the new position of the control (which I need to know in order to compute the coordinates for the popup). Since I want it to work as a user control, I would prefer a local event on the control itself (i.e. without messing with any global page/window stuff). Please help me to find the right event.
Update: It seems to me now that LITERALLY I need to know when the owning control is moved. Because there can also be other reasons why it's moved (other than abovementioned change of the window's size).
I think you are looking for the SizeChanged event. You can subscribe to that to know when to resize your popup.
If your control is moved because of another control, this may not help though. As it may not resize, just be arranged in a new location.
If that's a problem, you can use the LayoutUpdated to determine if anything changed inside an element. For this you'd need to attach a handler to the RootVisual or something above your element.

Clip a wpf Popup at bounds of a main window

From what I understand, the popup exists within it's own visual tree. However, I've noticed a few properties, Clip and ClipToBounds. What I am wanting to do is Visually clip a popup at the right and bottom edges of a window regardless of the fact that the popup is independent of the bounds of the window. I'm not using XAML, but if somebody knows how to do it in XAML, then that's fine. I can get to the main window using System.Windows.Application.Current.MainWindow. Is it possible from this to get a value that I can use to clip the popup? I'm assuming that if there is a value that I can use, then I would be able to bind the clipping of the popup to that value. This is really not necessary since after the popup initially opens, if the window gets moved or resized, the popup closes. So I would really only need to clip the popup when it opens. The reason I would like to do this is because although I am using a popup, I don't want it to appear as a popup that exists outside of the window. FYI this is for a popup calendar for a custom datebox. Any ideas, as well as clarification of misconceptions that I may have, would be greatly appreciated.
Furthermore, the popup can be launched from a user control that is not directly on the Main Window. So in that case it would be easier to use a popup. As apposed to a UC inside the XAML
I know this is a year old post, but in case any others come here looking for answers... If you don't need the popup to be outside of your window, why use a popup at all? It'd be far easier to simply use a control in a canvas (for instance) and control it via its Visibility property. Then you'd automagically get your clipping.

Resources