473,666 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:
{
offScreenGraphi cs.Clear(Color. Transparent);
for (int x = 0; x < GRIDLENGTH; x++)
for (int y = 0; y < GRIDHEIGHT; y++)
{
SolidBrush solidBrush = new
SolidBrush(Colo r.FromArgb((opa city[x, y] * 62), Color.White));
offScreenGraphi cs.FillRectangl e(solidBrush,
this.Left + (x * CELLWIDTH), this.Top + (y * CELLHEIGHT), CELLWIDTH,
CELLHEIGHT);
}

this.CreateGrap hics().DrawImag e(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Wi dth, memoryBitmap.He ight), 0, 0,
memoryBitmap.Wi dth, memoryBitmap.He ight, GraphicsUnit.Pi xel);
}

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.
offScreenGraphi cs.Clear(Color. Transparent);
...
this.CreateGrap hics().DrawImag e(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Wi dth, memoryBitmap.He ight), 0, 0,
memoryBitmap.Wi dth, memoryBitmap.He ight, GraphicsUnit.Pi xel);
}

Any help would be greatly appreciated.

May 16 '07 #1
2 4279
On May 16, 9:43 am, "gwoodho...@gma il.com" <gwoodho...@gma il.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.
offScreenGraphi cs.Clear(Color. Transparent);
...
this.CreateGrap hics().DrawImag e(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Wi dth, memoryBitmap.He ight), 0, 0,
memoryBitmap.Wi dth, memoryBitmap.He ight, GraphicsUnit.Pi xel);

}

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.CreateGrap hics() 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.CreateGrap hics().DrawImag e(...), you
would use e.Graphics.Draw Image(...).

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
4514
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 that is completely transparent in certain areas (so that the web page background shows through)? I save my graphics as gif files. I would appreciate, if possible, a simple example so that I can see the code. Thanks. -- Nathan Sokalski...
0
1369
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 dialog transparent but other controls and child windows are not transparent, I see the colored box around my control. If I switch my color depth to 16 bit everything is fine. Why does it work on some forms but not others. I can even make my main...
11
1424
by: Noozer | last post by:
Does anyone know if we will be able to put transparent backgrounds on UserControls in VB 2004?
1
1641
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 etc. etc Form2 has a foreground image of a decorative picture frame (,png image) with a transparent center, and a tab control for the user to select .bmp pictures to view. Form3 has a "picturebox" into which is loaded the user.bmp file image
7
2557
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 code, what should be transparent is not really transparent. Is there a property in the picture box I need to tweak? I though the whole idea was to put the transparency information right in the gif file. Suggestions, clues, pointers? Any of the...
12
3772
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 (maybe looks like a sheet of green glass) but has elements or graphics on top that I want to be opaque. Perhaps I want the sheet of glass to have writing or other graphics "painted" on the surface. Is there some way to mix varying transparencies...
6
3651
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 purpose to improve it. Frankly, I am not clear about the exact meaning of some pixel format (max, gdi, etc.) and I hope I have put them under the right "case". I have made only some superficial test and it seems to work. Note that the purpose is...
4
9349
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 written on the glass pane. i need to be able to see the control or form that is underneath the RichTextbox, and at the same time to be able to write and erase text to the RichTextbox. i'm assuming that it is the backcolor that hides what is...
5
2077
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 control should I use? Thanks Marco / iw2nzm
3
4214
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
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6192
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.