Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
  • *Experts*
Posted (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 by mutant
Posted
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.
  • *Experts*
Posted (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 by mutant
Posted
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.
  • *Experts*
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...