Setting a C# Form to a Negative Location - c#

I am working on a tool for Windows that will interface with CloudApp using its API. I found some articles on here about how to achieve the Region capture which I used to modified to fit my exact needs. Everything is going very well, but I am having trouble with a multi-monitor setup. The reason for the trouble, is that I run one monitor in 1920x1080 and the second is 1080x1920.
The overall flow is that I create an image of the entire screen (3000, 1920), then I show it as the background in a form. The issue is I can't get that form to start at a negative point so it moves everything down.
If I look at the raw image I capture before I do the region selection, all is well:
http://img.paronity.com/KsiA
The issue is when I go to bring up the region form. In order for it to be the background of the form and be in the correct place, I would need the form's upper left X,Y to be (0,-670). No matter which method I try, I am unable to achieve this.
Is there any way to achieve the negative point that I am missing? For sake of being complete, I made a very simple form which outputs its "top" coordinate when you move it, and when I move it to the upper portion of the vertical monitor, I get negative points for it so I know they are valid.
Let me know if any part of my code would be helpful and I will post it. I just wasn't sure it was going to be necessary. Thanks in advance!

Sorry for the post. It is possible to do. The issue was that I was setting the size of the form in the constructor for the form. I wasn't aware this wouldn't work. Once I set it on the form load event instead, it moved it into the right place.
Thanks #dognose! You saying your test worked made me think that is was probably a scope/placement issue and it was! Thanks for everyone looking at this question!

Related

Simple Taskbar NotifyIcon

I have a software that needs to trigger a little popup image by the taskbar. I have found some classes to help my cause, however, they're too complex and I wanted to ask here first if there's a better option for my scenario.
This is what I found:
http://www.codeproject.com/Articles/36468/WPF-NotifyIcon
But I don't need all those functions. I can't seem to find a simple way to achieve my goal.
All I need is a 200x100 rectangle image to pop-up by the bottom right corner, and open a URL when right clicked. It should open the webpage using the system's default browser. However, I need to do a few more things in addition, so a method like Object_clicked() would really help me a lot. Simply, I want a clickable notification image to popup for x seconds, but I don't know an easy way to do it.
Should I try to go with the link I found, or is there a simpler way?

Windows Forms Panel control slowly creeping

So I'm working on a card maker for a TCG. I seem to have encountered a very odd glitch and can't find a decent workaround. I have several panels that contain various controls for determining the different variables of the card, like so:
However, I've noticed that if I go into the Form1.cs file and change code--any code at all, from adding/removing comments to deleting and restoring a semicolon--and then go back into the design view, the design view window goes black for a moment whilst it redraws everything, and then pops back into place...except that the right-hand side of various panels has been bumped to the left about 5 pixels. It doesn't seem like much, but after multiple changes, multiple swapping back and forth between windows I get this:
...which of course is hideous and unusable. For a long time I couldn't determine why some panels did it and others did not, but finally while reworking the Keywords tab you can see in the screenshot, it dawned on me that it was any panel that I have set to anchor both on the left and right hand sides of the parent control. This is to allow the user to resize the window to their heart's content. I currently have a kludge in place in which I modified Form1.Load() to hard-code the size of the affected panels. This is of course entirely against the whole point of using a visual editor in the first place.
The hierarchy of the controls goes Form1->SplitContainer->SplitContainer.Panel2->TabControl->StatsTab->StatsPanel. This unfortunately doesn't appear to be a code-based problem since I don't write any code to affect this. The redraws apparently actually change the StatsPanel.Size property, and if I cycle back and forth I can watch it sloowly decrement.
So, does anyone know what might be wrong? I don't like to jump to "oh Microsoft has a glitch in their editor" but I can't find anything else that I am doing or setting that could be causing it. Any help would be most appreciated.

Taking screenshot of a partially hidden window in a programmatic way

Is it possible to get a screenshot of a window that is not on the top, i.e. if it is partially hidden by another window, without bringing it to the top?
Unfortunately, it's not trivial to take a screen-shot in C# at all, you can create a graphics object based on the current window or viewport and capture that, but its not what you're asking for.
This
Screenshot of Hidden Window
might help, but you'd have to do this with Interop code anyway.
I dare say that it's not a common thing that is supported as really, one program has no business knowing what's being displayed in another program; it's potentially a nasty exploit.
You dont need to take screenshot, if it is your application you can use Control.DrawToBitmap(Bitmap bitmap, Rectangle targetBounds); of the form object.
If it is other application window, you can try un-managed way to get the UI of window. I dont remember all the methods but I have tried and it was working. Probably GetWindow and SendMesage with WM_PRINT / WM_PRINTCLIENT

WPF - Resizing chromeless windows using attached behaviors,..Any suggestions?

Who fancies a challenge?
I'm currently working on the ControlTemplate for a chromeless Window which will be a part of a reusable theme assembly. I want the behaviors for moving, closing, minimizing and restoring to be implicit so I've written attached behaviors for this functionality which I've then included in the template.
Now,..I've come to resizing and I've come to a junction. For better or worse I'm handling the mouse move in the behavior and finding whether the cursor is inside the resizing 'zones'. I'm far enough to change the cursor appropriately but now I've gotten to actually resizing the window there are three options I've come across.
I could hand-ball the affair and adjust the Left & Top and Width & Height as needed. This is the simplest option and is easily achievable using attached behaviors but it seems like moderately heavy lifting and I understand that WPF will continue to render as the window is adjusted causing flickering,..which sucks.
The second option is to get a message hook and listen for WM_NCHITTEST and the like but the solutions I've found so far involve me sub-classing Window and I don't want to force consumers of the theme to use any controls that aren't framework provided.
The last option is to somehow draw a rectangle on the screen showing the are the Window will take up as the mouse is dragged and then resize on MouseUp,..which seems doable but it's not something I've done before so some pointers on that would be cool.
So,..what should I do? The Win32 route seems like my best option so far but I'd rather not if someone has a 'purer' solution that works. I'm happy to get suggestions with option 3 and anything right up to .Net 4 in case some dynamic magic might be possible.
Thanks in advance.

Windows Forms advanced visual effects

I have an design idea about the appearence of a small program , which is basically a windows form with a combo and one button.What i would like to do is the following.When i click on the .exe of the program to start it , i would like to have an non-standart start up of the window.To be more specific i will give you an example - i click on the .exe , upon which some dots appear in a random matter all over the screen , after those points appear they start moving in a spiral way so finally they merge into the standart square windows form shape.So my question is - is there a free API or anything similar with the help of which its easily doable or there would be a lot of work needed from myself to create those API's ?
Thanks in advance
This will be extremely difficult to do.
It will also be very annoying for the end-users.
In short I see two options:
Render your form to a bitmap and render peices of the bitmap to a full-screen layered window. You'll have to call UpdateLayeredWindow repeatedly to get the animation working but that should be a good lead. I could see getting 10-20 fps with this method.
Take a screenshot of the desktop, create a full screen borderless topmost window, render the screenshot, then render your animation on top. This will prevent any other windows from recieving input while the animation is playing.
Either way your users will hate you.
As SLaks has already said, that will be pretty annoying for the end-users.
If you ask whether it is doable, I would say yes, everything is doable in programming, it all depends on the effort you're ready to put into.
As a very simple algorithm, here are some steps I would go through for your achievement:
Create a System.Windows.Forms.Form;
Set Form.ShowInTaskBar= false;
Set the Form.TransparencyKey property;
Set the Form.ControlBox= false;
Set Form.TopMost= true;
Drop a PictureBox control on your Form;
On the Form.Load event, take a screenshot of the current desktop and set it as the image of your PictureBox.
Then, build an animated GIF, and superpose it to your form.
You will most likely appreciate, I guess, the following link which discusses about C# Winforms Animation.
Disclaimer: This is an arbitrary algorithm off the top of my head. Besides, I illustrated the steps I would go through in order to achieve such objective, though I have never ever performed WindowsForms animation.
Althouth this might be cool to program, users are conservatives and "always anxious" about program startups, so, as already mentioned, this might become pretty annoying for the end-users.
I hope this helps you through anyway!

Categories