I have made a card game built of pictureboxes. The empty places a card can be put in is an empty picture box with a transparent background and a 3d border. And then I have a current card which is also a picturebox which is moved by a MouseMove event.
As soon as I drag a card over the transparent PictureBoxes there is a card left all over the place where the card has been until I stop the mouse and let the picture refresh. This is also the case when I have the background of the current card set to transparent although a card is set to be the image (so it does not really matter there as it goes away if I set the background to green).
Is there any workaround for this? I tried DoubleBuffered but with no success. Thanks!
It isn't clear from your description what your code looks like. But heads up on your next problem after you get this one fixed: transparency effects for controls do not work in Windows Forms when controls overlap. You'll see the background of the parent, you won't see the content of the picture box that's overlapped by your moving card.
This isn't a problem with WPF, it has a very different rendering model. But as long as you want to stick with Windows Forms, you need to make this work with the form's OnPaint() event. Draw the card table, then the stock, then draw the moving card. When the card moves, call Invalidate() to force the form to be repainted, now showing the card in its new position.
In other words, don't fix your current problem. Redesign your program.
you can call
Application.DoEvents();
in pictureBox.Move events; so all the background pictures will redraw themselves.
Related
I'm creating a launcher for a game I'm working on.
I don't want the square edges of the Control, so I decided to try the route in making the control transparent, and having the PictureBox image I created as what you will mainly see as the background of the App itself.
I have the Control Transparency working, however, even though I've set the PictureBox.BackColor to Transparent, it still shows a Black background.
Basically, I just wanted my launcher to look a little "3d" with the logo and the edges coming out a little bit. So the control is technically larger than the picturebox to make room for parts coming out a bit.
Can anyone tell me where I'm going wrong?
The scenario is that i want the user to create a shape in a small panel that opens (the added shape can later be placed on the canvas), but for a better reference, i want the user to be able to move the semi-transparent panel somewhere on the canvas and then draw with the accurate reference.
Please tell me:
Which panel type to use
How to make it moving by clicking the mouse on the move button (not the whole panel as dragging will be used for drawing lines) and move it around.
How to make it semi transparent.
How to make it appear and disappear (this should be pretty simple)
How to somehow limit its movement inside the canvas so it cannot move on the ribbon
And I really really hope there will be something built-in in WPF that i'll be able to use, and i will not have to do it the hard way i.e. create a rectangle, and do customized hit testing on it to allow the user to draw on top of that rectangle, make that rectangle transparent, and add graphics items for the buttons and controls on that rectangle "panel".
I am asking this because i have never seen such feature in any Windows application and i have no idea what to use for this purpose and how to implement it. The closest thing to what i want is in Adobe Acrobat Pro, which is the small preview of the page that appears when i double click with the middle mouse button. It doesn't move, nor it is transparent or can be drawn upon, but scale and shape wise i want something similar.
You should be able to place a second Canvas inside of your main canvas, and place whatever UserControl you'd like with your "view" inside of it.
You'll have to handle the mouse click/drag for moving it around yourself, but otherwise, it should be very straightforward.
I want to display a very small image on the top left corner of the windows desktop, it will be a picture of a small note and when you mouse over it, the window will show.
How can I do this in C#?
There should be no borders or regular window graphics
The image will be partially transparent
When a mouse over event occurs a window will display
The image will always overlay other windows
Thanks
I'll try to point you to the right direction for each of those requirements, you can do more research on how to exactly achieve each one using google or stackoverflow.com
You need to create a widows form, and add the image as the background of the form, or add an image control to the form.
after you have that, you can use the following to get your desired effects.
No Border
Set form's FormBoarderStyle propery to None
Transparency
Set Opacity property of the Form to something less than 100%
Mouse over
Use MouseHover or MouseEnter events of the form
Overlay other windows
Set TopMost property of the form to true.
I have a picturebox with a fixed sized image (256x256) generated by the program. I have another smaller image as a resource. What I want to do is when my cursor is over the image and I hold down the mouse button, the smaller image "anchors" with the mouse pointer so it moves around with it. If I let go of the mouse button, the smaller image will stay in that position on top of the bigger image. The smaller image is basically a marker, something like an X or O.
I was thinking of having a second picturebox on top of the first picturebox but I can't make it transparent. Or redrawing the image with the smaller image on top of it and reloading the image into the picturebox, but I'm not sure how to do that and I think it's going to be pretty slow redrawing it each time I move the mouse.
So how can I have a marker image move around on top of a bigger image and have it stay there?
Create your control for this instead of using PictureBox. PictureBox should be used ONLY for fixed images on the form, nothing else.
Instead, derive your control from UserControl. Turn on double buffering for it. In OnPaint method, first draw your background picture, then your marker picture after it. Don't worry, it WON'T be slow and it WILL work as it should.
When you release the mouse, update background picture by drawing your marker picture on it.
Since every sentence here is a little discovery by itself, hope you'll have a good time coding your little game :)
I am using c# winforms to show an Image. The displaying of the image is done using a user control. Now I want to provide the user to draw lines, put other small images, write text etc over the image on an overlay control. How can I provide this functionality? If I use another user control to show the overlay control with transparent back, will that work?? any other solution will be welcome.
You might try approaching this with a canvas (Panel) that handles painting the image as the background and all the annotations/markup afterwards. This will make the foreground appear to be transparent. I expect you'll want to set Control.DoubleBuffer for performance.
You might experiment with setting the style ControlStyles.AllPaintingInWmPaint. Also, try overriding Control.OnPaintBackground and do nothing, and override Control.OnPaint and do all your painting inside there.
If performance is still unacceptable, pay close attention to the PaintEventArgs.ClipRect property. This is the only area you need to paint. The trick is figuring out which of your annotations/overlays intersect with this rectangle and painting them in the correct order.
Either this canvas or a higher level control will need to track mouse movement so you know where to draw the lines, paste images, etc.