473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Transparency Control

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.

May 16 '07 #1
2 4269
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
{
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.
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


May 16 '07 #2
Thanks,

That site really helped.

Graeme

May 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic...
0
by: Jim H | last post by:
This is a cross post from windows.forms. I'm not sure where to post it. I have an application that uses transparency. My video settings are 1600x1200 and 32 bit color. I can make the main...
11
by: Noozer | last post by:
Does anyone know if we will be able to put transparent backgrounds on UserControls in VB 2004?
1
by: | last post by:
How do I control the layering of 4 forms of identical size and position to cause the desired form to be second from the top.. Form1 has my welcome screen etc.and the code for file manipulations...
7
by: Al_C | last post by:
Hi, I create a form, then place a picturebox on it. Then I set the picturebox image to a .gif that I have edited in GIFConstructionSet to create a transparent background for. But when I run the...
12
by: Patrick Dugan | last post by:
I know that I can change the opacity of an entire form, but is there a way to control opacity to specific controls or components? For example I want to create a form that is semi-transparent...
6
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the...
4
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text...
5
by: Marco Trapanese | last post by:
Hi! I need to create a user control with transparent background. Picturebox for example doesn't show any other control under it even if it has the background color set to transparent. Which...
3
by: Martijn Mulder | last post by:
When I populate a ToolStrip with ToolStripButtons with a .png-image on it, will Windows understand the transparency of the .png file?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.