How to make Transparent Paint application to draw on screen? - c#

I want to create a app that lets you draw on screen like Epic Pen. I searched on google on how to do it but all I found was only how to draw static shapes (rectangles etc.) on the screen, not brushstrokes like in MSPaint. I thinked of making the form transparent by using TransparencyKey but it just lets clicks through it.. Is there any way for me to do this, without taking a screenshot and drawing on it? I want users to be able to switch between pen mode (draw on screen) and cursor mode (normal clicking). Example video of Epic Pen:

Related

Transparent Control, Transparent PictureBox background, but PictureBox Showing Black Background

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?

Specific Draw region within Game Window

Part of the problem I am having with what I am trying to do is trying to explain to others what I want. What I am trying to accomplish is an in-game pop-up menu or window which has its own Draw area. For example lets say I have a pop up window with multiple objects stacked on top of each other, such as button, but there are too many to fit on the window so you need a scroll bar to move them into view. What I want to do is make these object only Draw inside of the window:
http://imgur.com/8IWNEqN
The black area with scribbled pink is the main game window and the centre image is the pop up windows, the dark blue squares being the objects inside. Any code, suggestions, and mainly theory will be appreciated. I've tried drawing them only when they're inside the window and this works but it doesn't look very smooth, I want the object gradually disappearing as they move out the window, not just vanishing when they touch the borders, and especially not slipping out of the window.
Thanks.
Before you do any rendering in XNA you can set the ViewPort on the GraphicsDevice. This lets you restrict where things are being rendered.
For example, if you want to render something to a 100x100 pixel area at the top-left of your screen you might do:
// Create the rectangle
var clipRectangle = new Microsoft.Xna.Framework.Rectangle(0,0,100,100);
// Set the rectangle when you call SpriteBatch.Begin:
mSpriteBatch.Begin(SpriteSortMode.Immediate, renderStates.BlendState,
samplerState,
depthStencilState,
rasterizerState,
null, matrix,
clipRectangle);

How to create moveable "free floating" panel that can freely move over the canvas and is partially transparent

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.

Making scribbles on a monochrome image

Imagine there's a picturebox which loads a monochrome image. And there is a need to make few color scribbles on it. I have no background with graphics. Would it be just a pen drawing pixels or something more complex I don't know.
Target language is C#. Technology: WinForms.
I think the easiest way to achieve what you want would be to create a very lightweight retained mode drawing system. Keep track of all the positions where the user has scribbeled and draw dots/circles/lines/rubberducks/whatever at these positions in the PictureBox's Paint event. On mousedown+move events, call the PictureBox' Invalidate() function. The original picture must either be painted underneath or in the class' OnPaintBackground (which IMO is more elegant).
This tutorial should get you started:
https://web.archive.org/web/20121006140255/http://www.bobpowell.net/backtrack.htm

Transparent pictureboxes flickers when moved with mouse

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.

Categories

Resources