This one's a hairy one to explain. What I've got is a class called "VistaGroup Box" that I put some nice-looking Vista-style gradients in the background and made to look like the ribbon categories you see in Office 2007. I got it working great, and created a few more controls, including a "VistaButto n", which is primarily transparent when the cursor does not hover over it. However, when I added a standard Panel in the VistaGroupBox and put my button inside the Panel (I want the Panel to auto-scroll), the VistaButton's transparent background started as though it were in the upper-left-hand corner of the VistaGroupBox, which was not where the button actually was at all! The button draws correctly when outside the Panel.
So, what I've got is this: - VistaGroupBox
-
+-Panel
-
+-VistaButton
In order to draw my transparent controls, I've made a function that does this: (Some controls, like Button, don't have transparency support at all - I got this from the Mono implementation) -
public delegate void InvokePaintDelegate(Control c, PaintEventArgs e);
-
public delegate void InvokePaintBackgroundDelegate(Control c, PaintEventArgs e);
-
/// <summary>
-
/// This function looks like a mess primarily because of the #if ... #endifs. The problem is, the "BROKEN WINDOWS"
-
/// section is how WINDOWS does it, which is a problem for going through multiple transparent areas for whatever reason.
-
/// MY_CORRECT works if you're only going from user drawn transparency to user drawn transparency - that is, none of your
-
/// controls use Control.OnPaintBackground (like a Transparent Panel). WINDOWS_HACK works in all conditions - too bad it uses
-
/// a bit more memory due to the image creation.
-
/// </summary>
-
/// <param name="c">The control to paint the parent to</param>
-
/// <param name="pevent">The PaintEventArgs from the OnPaintBackground call</param>
-
/// <param name="InvokePaint">The control's InvokePaint method - because it is protected.</param>
-
/// <param name="InvokePaintBackground">The control's InvokePaintBackground method - because it is protected.</param>
-
public static void DrawParent(Control c, PaintEventArgs pevent, InvokePaintDelegate InvokePaint, InvokePaintBackgroundDelegate InvokePaintBackground)
-
{
-
PaintEventArgs parent_pe;
-
GraphicsState state;
-
Rectangle clipRect;
-
-
Graphics g;
-
#if BROKEN_WINDOWS
-
IntPtr hdc = pevent.Graphics.GetHdc();
-
g = Graphics.FromHdc(hdc);
-
if (c.Region != null)
-
g.Clip = c.Region;
-
else
-
g.Clip = new Region(c.ClientRectangle);
-
clipRect = new Rectangle(pevent.ClipRectangle.X + c.Left, pevent.ClipRectangle.Y + c.Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
-
#elif MY_CORRECT
-
g = pevent.Graphics;
-
clipRect = new Rectangle(pevent.ClipRectangle.X + c.Left, pevent.ClipRectangle.Y + c.Top, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height);
-
#elif WINDOWS_HACK
-
Image img = new Bitmap(c.Parent.Width, c.Parent.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
-
g = Graphics.FromImage(img);
-
clipRect = new Rectangle(c.Location, c.Size);
-
g.Clip = new Region(clipRect);
-
#endif
-
-
parent_pe = new PaintEventArgs(g, clipRect);
-
-
state = g.Save();
-
#if !WINDOWS_HACK
-
g.TranslateTransform(-c.Left, -c.Top);
-
#endif
-
InvokePaintBackground(c.Parent, parent_pe);
-
g.Restore(state);
-
-
state = g.Save();
-
#if !WINDOWS_HACK
-
g.TranslateTransform(-c.Left, -c.Top);
-
#endif
-
InvokePaint(c.Parent, parent_pe);
-
g.Restore(state);
-
-
#if BROKEN_WINDOWS
-
g.Dispose();
-
pevent.Graphics.ReleaseHdc(hdc);
-
#elif WINDOWS_HACK
-
g.Dispose();
-
pevent.Graphics.DrawImage(img, new Rectangle(new Point(0,0), c.Size), new Rectangle(c.Location, c.Size), GraphicsUnit.Pixel);
-
img.Dispose();
-
#endif
-
}
-
You can see that I've got 3 preprocessor directives here, each should be used exclusively. BROKEN_WINDOWS behaves exactly like the Windows default, WINDOWS_HACK works properly, except I'm creating images, and so it tends to be a bit slow.
Anyone got some time to help me figure this one out?
0 2870 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve Koon |
last post by:
Any thoughts on getting this project to work or suggesting another method
would be appreciated.
Steve
==========================================
Project:
A Windows Form which acts as a Whiteboard. The Form contains 3
|
by: Sushil Srivastava |
last post by:
Hi Guys,
Would you be able to help me using C# GUI (with user interface component) in
my MFC application. I have used managed extension, COM-interops, etc but
problem is this C# component has user interface. how should have get window
handle from managed windows?
Thanks in advance.
Sushil
|
by: Mark Deibert |
last post by:
I'm a former VB6 coder. Quit a few years ago. Now I'm back and trying
to teach myself VB.NET. I don't remember having this much difficulty
learning VB6. I'm totally stuck on something and need your expert
guidance.
I just want to load a GIF with a transparent background into a
container with a transparent background. So I can move the GIFs over
and under each other. You know, as in basic game stuff. I can load the
transparent GIF no...
|
by: Brian Henry |
last post by:
Hello,
I want to make a control that has a scrollable Gantt type display (not
really one but will look similar to one) this is going to be custom drawn (i
already have the drawing procedure completed for the overriden onpaint
event) but the problem is this can be a very long scrollable viewport (part
that scrolls inside the control) while the control will be relatively
800x600 in size)... i tried to do this with a panel scrolling inside...
|
by: Adam Maltby |
last post by:
Hi,
I need to do a transparent label but with a difference.
I have drawn on my form a custom background using CreateGraphics as I needed an ellipse looking fill in a rectangle - so the actual background colour of the form is still set to "control" colour.
If I use the background transparent setting instead of seeing my drawn on background and it's gradient i see the forms background colour. If the label was on a solid coloured bit of...
| |
by: Lucile |
last post by:
Hi All,
I am trying to obtain some sort of a "Model" based on horizontal &
vertical lines (like a frame) drawn on a form or on a PictureBox. For
frames configuration purposes, I created a white background image; and
that works fine. But the "Model" will be used to cut off pieces of a
given image with MS Office. I would therefore like that the lines be
appearent on the image to be cut; but the the underlying control be
transparent (so as...
|
by: Adam Clauss |
last post by:
I have a completely user-drawn user control in which I enabled transparency
(follownig suggestions at
http://www.c-sharpcorner.com/UploadFile/Nildo%20Soares%20de%20Araujo/TransparentControls11152005074108AM/TransparentControls.aspx)
The user control does not contain any other controls; I manually draw
contents in the OnPaint override I created.
My problem is that the control does not always draw itself properly.
Sometimes NONE of the...
|
by: NickP |
last post by:
Hi there,
I have a usercontrol that inherits from Windows.Forms.Button.
In the OnCreateControl method I set the style of the control so that it supports transparent backcolor and set the background color to transparent.
.....
Protected Overrides Sub OnCreateControl()
|
by: Kevinst |
last post by:
Hello there,
I have got a problem and several approaches but none is really staisfying:
Lets assume we have a form. On its surface we have got several animations (like a blinking light).
This form is not owner drawn. Everything is drawn by child controls.
Now we want to go ahead and create an animation that is on top of everything of that form. Lets assume this animation was an arrow that is moving from the top left corner to the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |