Form is not laid out correctly - c#

I have a WinForms form hosted in VB6 application (I am not sure if this is significant). Sometimes form controls are layouted incorrectly (primarily Anchor property doesn't work). If I just resize a form by mouse - the form is drawn as it should. Is there any method that may solve my layout problems without manual form resizing? I tried PerformLayout, Invalidate and Refresh methods... but they don't solve my problem.

You could handle the form's Layout event to layout the controls the way they should be.

Related

How do I know that a MDI child form has visually changed?

I have MDI WinForms application written in C#. Normally only one MDI child form is visible and all others are in background. Child forms content may occasionally change in background (for example, web browser control may be displaying a page that is dynamically changing every N seconds, chart controls are being filled with data as time goes on).
I want to show small previews of child forms when user hovers a mouse over or clicks on a special button in a toolbar of the main form. I can successfully use PrintWindow function as described here to make screenshots of child MDI forms. This works even for non-active child forms. The only problem is that taking every screenshot may take significant time (about 100-120 ms), probably because of the complex structure of the forms, so that if I make screenshots right before I want to show the previews then this creates a noticeable delay, especially when there are a lot of child forms (e.g. 10-15).
I want to optimize this and re-create screenshots only when it is really needed. Here is what I mean. Initially would I create screenshots for all the forms, store them in a "cache" and show previews. Later, when I need to create previews again, I would like to determine somehow that visual content of MDI form has changed (or change is pending) and re-create the screenshot only in that case, and otherwise use "cached" screenshot.
I tried to implement this by overriding of WndProc function of the child form class and looking for some messages like WM_PAINT or WM_SETREDRAW. But when I log all messages I see neither WM_PAINT nor WM_SETREDRAW even while the form is active (in foreground) and the web browser control on it constantly updates its page. Probably those event are sent directly to the controls of the form, but not to the form itself.
I don't want to traverse every form and connect to "changed" events of all the controls, because all of them are very different and not all have such notification events.
I guess that every control when it wants to change its visual representation sends some notification to OS to force self repaint. So, is there any way to detect such notification from any control inside MDI child form?
UPDATE:
I found WinAPI GetUpdateRect function that should return a rectangle that needs to be redrawn. I thought that if it returned non-empty rectangle then that would mean the screenshot needs to be updated. I tried to call it before the call to PrintWindow, but it always returns empty rectangle.

WinForms in Mono - Problems with form repainting

I have a WinForms Application. I need it to run also in Mono.
I have a problem with form repainting. There are many controls in the form. When I resize the form or when I try to update it (it needs to be updated on timer tick), the repainting does not work . Sometimes the controls are placed right, but it flickers, sometimes the the controls do not move or resize at all, some of the controls (buttons) seem to be disabled, some of them even disappear or are displayed twice.
In .NET I had similar problems, but enabling double-buffering on form solved them. But it seems that it does not work in Mono at all and I really don't know what to do.
On resize I need to move and resize the controls and redraw pictures in PictureBoxes.
I also have a problem with the above mentioned timer - the tick event fires only once and then almost everything on the form stops working, but I think it may be connected with the repainting problem.
If someone had an advice on how to correctly repaint a WinForms form in Mono, I would appreciate it.

Windows Forms Resizing And Overlapping UserControls

I have a Windows Form with 9 identical user controls that are directly adjacent to one another. On my screen the form looks fine, but when running a coworkers machine, the window gets resized and the user controls overlap. Does anyone know how i can prevent them from overlapping? I don't mind that the window is resizing on different machines, I just don't want any lost information or partially hidden elements.
Thank you in advance.
You could use a FlowLayoutPanel. It won't work in every situation, depending on what kind of controls you intend to place inside it. I'm not sure what your user control look like, but I just added a FlowLayoutPanel and added about a dozen buttons inside it, and it takes care of
adjusting the layout for me when the end-user resizes the form, maintaining padding around each button and avoiding overlapping.
If your user controls can flow around each other, and it doesn't matter if they are side by side or one over the other, you may want to check this out.

How do I create transparent labels over a Video control

I'm pretty much out of ideas here... for everything else, setting the background color to Color.Transparent or setting the TransparencyKey works fine...
I have an mp4 Video which I need to play as a "background" of my form. To do this, I'm currently using the WMP control. My problem: I can't add any controls on top of it, since they always render a background. Which looks ** on the video...
Any suggestions?
A hack I've used successfully in a similar situation:
Create a separate, borderless, transparent form (transparency works best at the Form level)
Host button controls on that form
Launch the control form when your video form launches
Wire event handling such that the floating form always moves, resizes etc. whenever the main form changes
Calculate position of the floating for based on parent form's specs
Always push the floating form to the top, above the parent form
Told you it was a hack. But if you get all the events and calculations wired up it should work fine.
P.S. I also recall having to do a poll timer with a function that made sure every 250 millis or so that the Z-order of the two forms was what you wanted. (Switching apps and windows changed the z-order unexpectedly and w/o events, thus the polling solution.)
P.S. II It is very easy to prototype the feasibility of this solution. Just create a separate app with the above-mentioned specs and move it over your video. (You will need to retain the Form border to be able to move/resize the window easily.)
Try rendering your labels using GDI+:
You can see sample here: (the Using GDI+ for drawing images with transparency part):
http://www.broculos.net/en/article/how-use-transparent-images-and-labels-windows-forms

Control sizing and position will change when form will resize in win form application c#

suppose i have label and button on textbox and i want that if i resize my win form then my label and button size and position will change. i got the solution in wpf but i am working with win form apps. here i am giving the url from where you can see what kind of output i am looking form. the url is http://i.stack.imgur.com/QeoVK.png. please see the image and tell me how can i implement the same output in win form apps. please help me with code snippet in c#.thanks.
You should make yourself familiar with the Anchor and Dock properties of the controls. They are great tools for this kind of work.
Note though that they will alter the size of the controls only, they will not affect font size.
consider that window forms and WPF are very different, especially about the UI management and controls nesting / UI composition.
I have seen some articles describing what you are trying to do now in windows forms, long ego, it's something called control scaling if I recall well.
Use Anchor and Dock properties for simple stuff and SizeChanged event for more complicated stuff. UI positioning API is much more limited than WPF and you will probably have to do stuff like scaling manually.

Categories

Resources