Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

Transparency Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gwoodhouse@gmail.com - 16 May 2007 15:43 GMT
Hello all,

Ive been trying to make a control which will allow me to draw
transparent masks over whatever is behind the control irrelivant of
what that control/image may look like.

My implimentation at the very basic level has a 2d byte array, each
element of the array corresponding to the opacity of the "Cell" at
that location.

On mouse move the redraw method is called:
{
           offScreenGraphics.Clear(Color.Transparent);
           for (int x = 0; x < GRIDLENGTH; x++)
               for (int y = 0; y < GRIDHEIGHT; y++)
               {
                   SolidBrush solidBrush = new
SolidBrush(Color.FromArgb((opacity[x, y] * 62), Color.White));
                   offScreenGraphics.FillRectangle(solidBrush,
this.Left + (x * CELLWIDTH), this.Top + (y * CELLHEIGHT), CELLWIDTH,
CELLHEIGHT);
               }

           this.CreateGraphics().DrawImage(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Width, memoryBitmap.Height), 0, 0,
memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel);
}

This gives me the problem of having the correct amount of opacity
drawn every move of the mouse, basically making the opacity layers
stack until each "Cell" is a completly opaque.

I'm wondering if the Invalidate() method could be used to "Clear" the
previous layer before drawing the new one, but Invalidate() only
carries itself out on the end of a paint method and i have no idea how
to force a blank paint command. See the below code for an example
{
           Invalidate();
           // Force a paint cycle here before the .DrawImage() method
is called.
           offScreenGraphics.Clear(Color.Transparent);
           ...
           this.CreateGraphics().DrawImage(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Width, memoryBitmap.Height), 0, 0,
memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel);
}

Any help would be greatly appreciated.
Chris Dunaway - 16 May 2007 17:15 GMT
On May 16, 9:43 am, "gwoodho...@gmail.com" <gwoodho...@gmail.com>
wrote:
> to force a blank paint command. See the below code for an example
> {
[quoted text clipped - 10 lines]
>
> Any help would be greatly appreciated.

Invalidate will cause the Paint event to be fired, so you could clear
the offscreen buffer and then invalidate.  Move the painting code to
the paint event.  You should not call this.CreateGraphics() as you are
doing, because you are creating a graphics object every time and then
not disposing of it.

Instead, you should do your painting in the paint event because the
paintEventArgs class has a Graphics object that you should use to do
your painting. Instead of this.CreateGraphics().DrawImage(...), you
would use e.Graphics.DrawImage(...).

See this site for additional information:

www.bobpowell.net

Chris
gwoodhouse@gmail.com - 18 May 2007 16:14 GMT
Thanks,

That site really helped.

Graeme

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.