|
-
Jan 5th, 2009, 02:29 AM
#1
Thread Starter
Fanatic Member
[2008] MDI form gradient
Hello Everyone,
A week ago I had made a post as to how can I change a form's backcolor to gradient one. I did get help from you guys and a small code which did the job.
The code (VB.Net) -
e.Graphics.FillRectangle(New Drawing.Drawing2D.LinearGradientBrush(New PointF(Me.Width, 0), New PointF(Me.Width, Me.Height), Color.FromArgb(0, 58, 140), Color.FromArgb(0, 215, 255)), New RectangleF(0, 0, Me.Width, Me.Height)) 'fade from left to right
This code changes the form's background to a gradient one. It workes fine.
Now I want this to take place in an MDI form which will be a container for other forms.
If I turn option IsContainer = False then it works but otherwise it does now.
Can anyone tell me how can I change backcolor of MDI Form to a gradient one ?.
Thank you ,
Cheers,
GR
-
Jan 5th, 2009, 03:04 AM
#2
Re: [2008] MDI form gradient
You need to get a reference to the MdiClient control that is embedded in your parent form and hosts the child forms. You then handle the Paint event of that, rather than the form. The following code uses the improved drawing code that I posted in that last thread of yours. Note the use of the OfType and First extension methods to get the MdiClient reference.
vb.net Code:
Public Class Form1 Private WithEvents client As MdiClient Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As EventArgs) Handles MyBase.Load Me.client = Me.Controls.OfType(Of MdiClient).First() End Sub Private Sub client_Paint(ByVal sender As Object, _ ByVal e As PaintEventArgs) Handles client.Paint Using Brush As New Drawing2D.LinearGradientBrush(Me.client.Bounds, _ Color.FromArgb(0, 58, 140), _ Color.FromArgb(0, 215, 255), _ Drawing2D.LinearGradientMode.Vertical) e.Graphics.FillRectangle(Brush, Me.client.Bounds) End Using End Sub End Class
-
Jan 5th, 2009, 09:24 AM
#3
Thread Starter
Fanatic Member
Re: [2008] MDI form gradient
Thanks for the code buddy. I did use it but it has a problem. A small area below the toolbar (if present) or the menubar is not painted. The edge of the form are also not painted (a bit).
-
Jan 5th, 2009, 05:50 PM
#4
Re: [2008] MDI form gradient
The edges are not painted because the MdiClient has a sunken 3D border. You can see that in the designer even with the normal grey colouring for the background, although it's not so obvious with less contrast.
As for the unpainted section below a MenuStrip and/or ToolStrip, that's my fault because I didn't test my code with those items present. Change it to the following and it will handle menus and tool bars:
vb.net Code:
Dim bounds As New Rectangle(Point.Empty, Me.client.Size) Using Brush As New Drawing2D.LinearGradientBrush(bounds, _ Color.FromArgb(0, 58, 140), _ Color.FromArgb(0, 215, 255), _ Drawing2D.LinearGradientMode.Vertical) e.Graphics.FillRectangle(Brush, bounds) End Using
-
Jan 7th, 2009, 11:13 AM
#5
Thread Starter
Fanatic Member
Re: [2008] MDI form gradient
Thanks a lot for the code dude. I appreciate your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|