PROKA Posted September 26, 2005 Posted September 26, 2005 I know how to draw rectangles. The problem is that when I draw another rectangle, it doesn't show what's behind him ( the old rectangles ). How can I draw a 'transparent rectangle' See attached files (VB.NET) Quote Development & Research Department @ Elven Soft
Machaira Posted September 26, 2005 Posted September 26, 2005 Umm, there's no attached files. Quote Here's what I'm up to.
*Experts* DiverDan Posted September 26, 2005 *Experts* Posted September 26, 2005 Hi Proka, It sounds like you're filling the rectangle instead of just drawing the lines? Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Leaders snarfblam Posted September 26, 2005 Leaders Posted September 26, 2005 I'm not sure exactly what you are looking for but you can fill rectangles with semi-transparent colors by using the Color.FromARGB function, specifying a value from 0 to 255 for opacity, red, green and blue values and then call Graphics.FillRectangle using a SolidBrush created from your ARGB color. 'I haven't tested this code Dim MyBrush As New SolidBrush(Color.FromARGB(128, 0, 0, 255)) MyGraphics.FillRectangle(MyBrush, New Rectangle(0, 0, 100, 100)) 'It should draw a 50% opaque blue rectangle 100 px by 100 px at 0,0. Quote [sIGPIC]e[/sIGPIC]
*Experts* DiverDan Posted September 27, 2005 *Experts* Posted September 27, 2005 As a note, alpha channel "semi-transparent" colors as suggested by marble eater are only supported from Windows 2000 and up. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Leaders snarfblam Posted September 27, 2005 Leaders Posted September 27, 2005 DiverDan, not for the sake of contradicting you, but for the sake of posting accurate information, I'm going to point out that although "Layered Windows" (used for semi-transparent forms) is only supported on Windows 2000/Xp and up, other semi-transparency using Windows Forms is a feature of the GDI+ library included with the .Net Framework and is fully supported in any .Net application. Try using the Graphics object and controls with semi-transparent BackColors on the Win9x/NT platforms and you will still see the nifty semi-transparent effects. Quote [sIGPIC]e[/sIGPIC]
*Experts* DiverDan Posted September 27, 2005 *Experts* Posted September 27, 2005 I didn't know that, thanks marble eater! Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
PROKA Posted September 27, 2005 Author Posted September 27, 2005 (edited) Sorry, here's the attachment Edited March 13, 2007 by PROKA Quote Development & Research Department @ Elven Soft
Machaira Posted September 29, 2005 Posted September 29, 2005 Well, that project doesn't compile for me and I don't have the time to figure out the fix. What version of VB was that done in? I'm using the most recent beta of VB.NET 2005 EE. Quote Here's what I'm up to.
Leaders Iceplug Posted October 4, 2005 Leaders Posted October 4, 2005 Ok, PROKA, here is what is wrong with your display. You are drawing one rectangle in the form's Paint event. This in itself will only guarantee that one rectangle will be visible on your form. When you create a new rectangle in MouseUp, you invalidate the region where you place the rectangle, so, even though: you may not have a rectangle in this region and you can successfully place it so that the old rectangle is not invalidated The fact remains that you are only drawing one rectangle in the Paint event. So, when the rectangles that you have drawn overlap, the one you are drawing now is the one that will dominate. Furthermore, the region of the rectangle is invalidated, therefore giving it an "opaque center". I suggest that you create your own graphics object. Dim GFX As Graphics In Form_Load or somewhere on the form that runs first: GFX = Me.CreateGraphics() Now, instead of invalidating your display, which clears out a hole on the display, just draw the rectangle. GFX.DrawRectangle(Pens.Gray, RcDraw) This solution will cause your rectangles to disappear when the form disappears or is obscured. If you want to keep the rectangles persistent, then keep an array of rectangles, go back to this solution you have already, with the Invalidate and the drawing in the Paint and, in the Pait event, use e.Graphics.DrawRectangles to draw a bunch of rectangles. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
PiggyBank1974 Posted November 8, 2005 Posted November 8, 2005 you can make a color have an alpha channel: do something like this: e.Graphics.FillRectangle(color.fromargb(127.5,255,255,255), New Rectangle(0, 0, 100, 100)) this will generate a filled rectangle that is 50% transparent. the pig.. Quote
Leaders snarfblam Posted November 9, 2005 Leaders Posted November 9, 2005 A similar reply has already been posted. Also, this thread has had no new posts for over a month and should be considered inactive. I hope that I am not out of line when I recommend refreshing yourself on the Posting Guidelines. Quote [sIGPIC]e[/sIGPIC]
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.