jimday1982 Posted August 6, 2003 Posted August 6, 2003 My program currently imports pictures into my program, but I am trying to allow the user to be able to draw a yellow, semi-transparent square on the image, to hi-lite it. I have a toolbar with a toggle button for drawing the square and that's where I stand at this point. Can anyone point me in the right direction? Thank you. Quote
*Experts* mutant Posted August 6, 2003 *Experts* Posted August 6, 2003 (edited) The best way would be to draw in the paint event, then you can use GDI+ to draw the square using FillRectangle with a color set to yellow with alpha blending. For example: (in paint event) e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(100, 0, 255, 255)), 100, 100, 100, 100) 'draw a rectangle using solid brush with alphablending Also, do you want the user to be able to draw more than one rectangle? Edited August 6, 2003 by mutant Quote
jimday1982 Posted August 6, 2003 Author Posted August 6, 2003 That brings up a good point. The user should have the ability to draw multiple squares on the picture. I should also mention that this code is going into a case statement inside the click event for a toolbar. My main concern is that the user should be able to draw the square on the picture box by clicking and dragging the mouse. Any other ideas or insight is GREATLY appreciated. Quote
*Experts* mutant Posted August 6, 2003 *Experts* Posted August 6, 2003 (edited) Sorry, I mistyped my last sentence in my previous post :) (edited now). If you want the user to be able to draw multiple boxes then this how I would suggest doing it. Create an array list which will store Rectangle objects, then everytime a rectangle is drawn add its coordinates and size in a form of Rectangle object to the list of rectangles. Then in the Paint event of the picture box simply go through every rectangle in the array list and draw it, like this: Dim rect As Rectangle For each rect in RectList 'RectList in this example is the array list holding all rectangles e.Graphics.FillRectangle(ColorYouWant, rect) 'get the rect and draw it Next Edited August 6, 2003 by mutant Quote
jimday1982 Posted August 6, 2003 Author Posted August 6, 2003 Ok thanks! However, there are 2 errors (probably my fault) that I'm wondering if you can help me with. First, I get an underline under "e.graphics" and it says that "graphics" is not a member of system.windows.forms.toolbarbuttonclickevenargs. The second is that the directcast operand must have a reference type, but system.drawing.rectangle is a value type. Any ideas? Thanks. Quote
*Experts* mutant Posted August 6, 2003 *Experts* Posted August 6, 2003 This goes in the paint event of your picturebox you want to draw onto, not in the click event. I corrected the typo in the code so it should work now. Quote
jimday1982 Posted August 6, 2003 Author Posted August 6, 2003 Thanks Mutant. You have a private message. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.