473,769 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a Linear Gradient Panel

In my WinForms app I've long been able to create a linear gradient effect by
just intercepting the PaintEventHandl er event. But I'd now like to create an
inherited user control, specifically of a panel.

I thought I was on the right track and did achieve the effect ... until I
started putting some controls on the panel. Then I got an "Invalid
parameter" error but don't understand what it's referring to.

Based on examples I've found, I've tried two approaches but neither work.
Hopefully someone will know why.

Here are the two approaches:

protected override void OnPaintBackgrou nd(PaintEventAr gs e)
{
Graphics gfx = e.Graphics;
Rectangle rect = new Rectangle (0, 0, this.Width, this.Height);

LinearGradientB rush lgb = new
LinearGradientB rush(this.Clien tRectangle,
gradientColorOn e, gradientColorTw o, lgm);
e.Graphics.Fill Rectangle(lgb, this.ClientRect angle);

lgb.Dispose();
e.Dispose();
gfx.Dispose();
}
protected override void OnPaintBackgrou nd(PaintEventAr gs e)
{
using(LinearGra dientBrush lgb = new
LinearGradientB rush(this.Clien tRectangle,
this.GradientCo lorOne,
this.GradientCo lorTwo,
this.GradientMo de)) //.Rotation))
{e.Graphics.Fil lRectangle(lgb, this.ClientRect angle);
}

base.OnPaint(e) ; //right, want anything handled to be drawn too.
}

Incidentally, dragging a TextBox onto the panel DOES work. But none of the
other basic controls seem to. I don't know if that gives a clue.

--
Robert W.
Vancouver, BC
www.mwtech.com

Apr 15 '06 #1
1 6296
I seem to have solved the problem. I'm not sure how but it works properly
now, at least in run-time mode. If anyone wants a copy of the source code
they can download it here:
http://pocketpollster.com/downloads/PanelGradient.zip

Something I don't understand is what makes an inherited user control like
this one display correctly in design-mode. Before it was but now it isn't.
Maybe someone could explain this to me.

--
Robert W.
Vancouver, BC
www.mwtech.com

"Robert W." wrote:
In my WinForms app I've long been able to create a linear gradient effect by
just intercepting the PaintEventHandl er event. But I'd now like to create an
inherited user control, specifically of a panel.

I thought I was on the right track and did achieve the effect ... until I
started putting some controls on the panel. Then I got an "Invalid
parameter" error but don't understand what it's referring to.

Based on examples I've found, I've tried two approaches but neither work.
Hopefully someone will know why.

Here are the two approaches:

protected override void OnPaintBackgrou nd(PaintEventAr gs e)
{
Graphics gfx = e.Graphics;
Rectangle rect = new Rectangle (0, 0, this.Width, this.Height);

LinearGradientB rush lgb = new
LinearGradientB rush(this.Clien tRectangle,
gradientColorOn e, gradientColorTw o, lgm);
e.Graphics.Fill Rectangle(lgb, this.ClientRect angle);

lgb.Dispose();
e.Dispose();
gfx.Dispose();
}
protected override void OnPaintBackgrou nd(PaintEventAr gs e)
{
using(LinearGra dientBrush lgb = new
LinearGradientB rush(this.Clien tRectangle,
this.GradientCo lorOne,
this.GradientCo lorTwo,
this.GradientMo de)) //.Rotation))
{e.Graphics.Fil lRectangle(lgb, this.ClientRect angle);
}

base.OnPaint(e) ; //right, want anything handled to be drawn too.
}

Incidentally, dragging a TextBox onto the panel DOES work. But none of the
other basic controls seem to. I don't know if that gives a clue.

--
Robert W.
Vancouver, BC
www.mwtech.com

Apr 15 '06 #2

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

Similar topics

5
2434
by: Woody Splawn | last post by:
I have a webform where I would like to have the background color for the webform be a gradient in blue. How do I do this? What is the easiest way? What is the way most used by other developers? Do you draw it with code or attach a .gif file as a background or what? Does one way or the other have an effect on speed? Thank You
13
2074
by: Crirus | last post by:
The main ideea: I havea 513x513 array of values....I draw a sort of map using that values for colors... so I have a realistic lanscape (map). I want to zoom about 60 times that map...and the zoomed area to be drawn on full screen. I want to draw it smoth not a square of 60 pixels x 60 pixels with one color, because I can see blocks and it's not good. There is a way to interpoate the colors between rectangles to show a smoth zoom?
0
957
by: Patrick Dugan | last post by:
I am using Visual Studio 2005 with Visual Basic. I am trying to create a vertical color-gradient rectangle. I want the rectangle to go from red on top to blue on the bottom. This is the routine I am using: ''''''''''''''''''''''''''''''''''' RectHeight = 50
0
1268
by: Robert W. | last post by:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like is used in PowerPoint when one wants to rearrange the order of the slides. Specifically, a thin black line is shown between thumbnails to indicate where an item will be dropped. As the user moved away I'd erase it by simply drawing another line using the BackColor of the panel. This worked great! But I've recently switched to using a Gradient panel and so now...
3
6864
by: Robert W. | last post by:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like is used in PowerPoint when one wants to rearrange the order of the slides. Specifically, a thin black line is shown between thumbnails to indicate where an item will be dropped. As the user moved away I'd erase it by simply drawing another line using the BackColor of the panel. This worked great! But I've recently switched to using a Gradient panel and so now...
4
5889
by: Jon Slaughter | last post by:
I'm drawing a linear gradient and its very "banded". The colors are far enough part that it should be plenty smooth enough but I always get the same number of bands regardless. I've tried to set g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality;
9
8145
by: Eric Lindsay | last post by:
How do you provide a consistent gradient fill as a background in a liquid layout? If I make a gradient fill image say 1000 pixels wide (and repeat it down the page) to suit a typical computer display, then only a small portion of the gradient will show if the viewpoint is a smaller PDA or phone display. On the other hand, if viewed full screen on a 1920 pixel wide display, I would run out of gradient on one or both sides of the page....
1
1863
by: Bryon | last post by:
My current code paints a rectangular area at the top (under the menu and tool strip) and bottom (top of the status strip) of the main form with a linear gradient. The problem is that when the form is resized or maximized for that matter, the form still displays the last areas that were painted with gradient. Basically the form does not erase the last graphics that were painted to the form and just paints over it with the new. My code is...
1
2594
by: DaveD | last post by:
Let's say I have a collection ("items") of objects that each have a "string Name" property. I understand I can create a loop like this: foreach (string name in names) { var item = (from x in items where name == x.Name select x).First(); // Work on item } Is there a way to make that query more efficient? (My assumption is
0
9420
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
10205
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...
1
9984
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,...
0
9851
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...
0
8863
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, 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...
0
6662
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
5293
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...
1
3949
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
3
2811
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.