|
Add some controls to overlay transparent form and avoid refreshing it's content with common Refresh()/Invalidate() methods,
use UpdateLayeredWindow() instead. For correct controls rendering add code like
Bitmap temp_bmp = new Bitmap(bitmap);
foreach (Control ctrl in this.Controls)
{
ctrl.DrawToBitmap(temp_bmp, ctrl.Bounds);
}
hBitmap = temp_bmp.GetHbitmap(Color.FromArgb(0)); // grab a GDI handle from this GDI+ bitmap
to the PerPixelAlphaForm::SetBitmap() method. Every System.Windows.Forms controlhas method DrawToBitmap().
Actually, i used this way to render simple controls - labels, i don't know would it work with more complex
user controls, but i can't see why it should not
|
|
|
|
|
Thanks, I was wondering about this.
Works perfectly
Edit: Ok, I take that back sorta.. The actual clickable region is MUCH smaller than the visible control (a button in this case)...
modified on Sunday, August 24, 2008 2:37 PM
|
|
|
|
|
Thanks, this is just what I needed to complete my design. It appeared that the bitmap was not getting refreshed each time the procedure was called. The actual Form.BackgroundImage needs to be present underneath so the region cut out from your controls, e.g. so this background image can bleed through around the controls.
In order to achieve transparency of the form controls, just override the controls in question and make sure that the regions are set to the way you need along with the ctrl.BackColor = Color.Transparent.
Without spending too much time on this, ensure that the 'bitmap' you are using originated from the 'this.BackgroundImage' build-in Form property.
<br />
public void SetBitmap(Bitmap bitmap, byte opacity = 255) {<br />
}<br />
So just I just changed all references outside this function and used the pre-existing container for the Bitmap/Image with one already build into the Form control itself.
So what you get is something like this: <substitued class="" name="" mainform="" from="" perpixelalphaform="">
partial class MainForm: Form
{
Bitmap bkgrnd = null;
...
public MainForm()
{
InitializeComponent();
bkgrnd = lib.LoadBitmapResource(2005);
this.BackgroundImage = bkgrnd;
this.CenterToScreen();
}
...
private void RefreshFormTimer_Tick(object sender, EventArgs e)
{
if (bkgrnd != null)
SetBitmap(bkgrnd);
}
-Latency
modified on Monday, January 24, 2011 5:52 AM
|
|
|
|
|
I want mesure a length of a line by using pixel.Can u send me C# coding for that
fbgsd asgtdfg
|
|
|
|
|
I've compiled the source by using the bat file but I'm still not able to get the Images to show up. What am I missing?
|
|
|
|
|
Check point 1...'Drag & Drop an image file from windows...", just drag one of the images in the sample zip onto the compiled window or call the following when the application is loaded:
SetBitmap(New Bitmap("full path to your image.png"))
Cheers
|
|
|
|
|
(Sorry for the poor English)
Hi,
I got a strange problem.
In my form i add something like :
[DllImport("user32.dll")]<br />
private static extern int SetParent(IntPtr hWndChild, int hwndNewParent);<br />
<br />
[DllImport("user32.dll", EntryPoint="FindWindowA")]<br />
private static extern int FindWindow(string lpClassName, string lpWindowName);<br />
<br />
private int GetDesktopWnd() {<br />
return FindWindow("Progman", null);<br />
}<br />
<br />
private void button1_click(object sender, System.EventArgs e) {<br />
SetParent(pngForm_.Handle, GetDesktopWnd);<br />
}
So when I click button1 my pngForm_ is now drawed on the desktop.
This worked great with 1 monitor.. But now I'm dual-monitoring and I got a bug when I try to move the pngForm_ when it's on the desktop. By example I hit the form when it's on monitor 1, and the form go on monitor 2 at the same position, and after it's impossible to move it.
I have made a lot of test, and i thinks it's due to the cp.ExStyle. In Fact when I remove the WS_EX_LAYERED it works..
Any idea to repair that ?
-- modified at 8:51 Saturday 7th October, 2006
|
|
|
|
|
Isn't it easier to use Forms.Opacity?
|
|
|
|
|
Đm, moebiusproject đúng là thằng ngu chẳng hiểu cái đ*'o gì cả!
|
|
|
|
|
No....because that won't give you an alphablended gui. it will just have 1 level of transparency
|
|
|
|
|
Hi,
This is some great code, I pissed around for ages trying to get this working before I stumbled across this page.
Now, it works just fine, the only thing is that forms descended from a PerPixelAlphaForm don't work in the VS2005 designer, you just get:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
Error creating window handle.
This doesn't stop the project from building or running though, but it's a pain not being able to use the designer.
Any ideas?
Thanks!
|
|
|
|
|
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
if(Site != null)
{
if(!Site.DesignMode)
{
cp.ExStyle |= 0x00080000; // This form has to have the WS_EX_LAYERED extended style
}
}
else
{
cp.ExStyle |= 0x00080000; // This form has to have the WS_EX_LAYERED extended style
}
return cp;
}
}
This will let you view the form in design mode. Not much use though as i havn't wokred out how to add controls yet.
|
|
|
|
|
try to recompile sources, then designer should handle it. If not try using VS 2008 Express, in my case it works fine.
|
|
|
|
|
Someone said "make the main form's Owner the shadow form",but I don't kown how to do this,Please help me!
thanks a lot!
|
|
|
|
|
I can't add Controls.Please help me.
my MSN:wangsongqing2003@hotmail.com Mail:wang.songqing@staples.sh.cn
|
|
|
|
|
Hi dear
Can you recognition coordinate of circle in bitmap?
i searching a algorithm for do this task but i cann't find
I want search a sample picture in another picture .
for example I give a circle picture to program then program search this picture in another picture ,if find get me coordinate of circle picture.
Thank
|
|
|
|
|
I was wondering if there was a way to get the same functionality using direct X. I see how you can use alpha blending for 3d objects, but how would you do it for a 2d png image and the desktop?
#teve
|
|
|
|
|
Since you called it "Form" (PerPixelAlphaForm) shouldn't we be able to add controls to it like labels and stuff?
Right now its only use seems to be the display of pictures over the desktop with full alpha support which is good, but rather limiting.
Is there any other project which implements full alpha support as a form background?
Luís Ferrão
|
|
|
|
|
Alpha blend windows don't support controls, so I don't support them either.
Not that I'm aware of, but feel free to implement it yourself and share it with us!
----
Rui Lopes
|
|
|
|
|
Actualy i did, by seemlessly creating another form on top of yours with a transparency key. The later form works as a placeholder for every control. The result is close to perfect but with only one issue:
If the user clicks outside a control on the top form, it activates your form. I can't find a way to avoid mouse clicking getting the focus to your form.
I do try to catch the mouse click event but when I do so, it's already too late as the background form already got the focus.
There is also another strange behaviour to your form. I have a form that inherits from yours. If i set the "ShowInTaskBar" to false, it actualy hides the entire form!
The workaround I found is to set it to false directly in the PerPixelForm constructor.
Thank god, code-project and yourself I have the source code =P
Luis Ferrao
|
|
|
|
|
basically...if you set the owner of the new form to the transparent form, i've found that it works like you want it to
|
|
|
|
|
Can you please post an example?
I'm a little new to all this and I'm not understanding what you mean. For example, I tried making a PerPixelAlphaForm and then another form with all my controls on it and then using Controls.Add() to add that form as a control onto the PerPixelAlphaForm but I got an exception
I would really like to know how to make a fully functional form with standard control on it where the background to the form is perpixelalphablended with the desktop.
Is this possible with C#?
|
|
|
|
|
Ya I'll tell ya how to do it.
Create a form based on the perpixelalphablended deal and load it up with your background png.
Next create another dummy form. Make this form the exact same size as the perpixelalpha form. Add all the controls that you want on top of this dummy form.
Now, in the contstructor of your dummy form create a region that specifies all the areas where you controls are and set it to the form like shown below.
<br />
public Form1()<br />
{<br />
System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath();<br />
<br />
p.AddRectangle(new Rectangle(0,0, 803, 24));
p.AddRectangle(new Rectangle(53, 122, 60, 40));
<br />
this.Region = new Region(p);<br />
}<br />
OR the other way... NOT using Regions. Make your dummy form a nice color like 255,0,255 and then set the transparency key to 255,0,255 also. This will work better than regions actually, because when you move your form you wont see the ugly dialog background color behind the controls.
Then position your dummy form exactly over top of your perpixel form. Then write some funky code to move each form at the same time when dragged.
If someone has a better way to it (I doubt it), then I CHALLENGE you to post the code here.
To move the windows simultaneously was easier than I thought. Gotter going perfectly. Keep checking www.clubdjpro.com for the DJRipper. Then you will see what it is capable of.
Then yer all good.
Cheers,
Greg
-- modified at 12:50 Tuesday 24th October, 2006
|
|
|
|
|
i have been messing around with your code for a whole day now and i still cant do i want.
i am trying to get the output of your code to go into a panel background, that way i can have a transparent alpha blended background and still have labels and stuff on it that are set to transparent so that the background can be seen.
Ive tried but i am new to this area of .net
That and i am implementing your code into a vb.net project
Thanks
Goran
|
|
|
|
|
i complete the work but i have a problem when i minimize the main form the others form not minimize
if i make it minimize i can't make all of them maximize the main form only will be max. and the others with not appear
MAZRO3
|
|
|
|