Results 1 to 5 of 5

Thread: [2008] MDI form gradient

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    526

    Post [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Public Class Form1
    2.  
    3.     Private WithEvents client As MdiClient
    4.  
    5.     Private Sub Form1_Load(ByVal sender As Object, _
    6.                            ByVal e As EventArgs) Handles MyBase.Load
    7.         Me.client = Me.Controls.OfType(Of MdiClient).First()
    8.     End Sub
    9.  
    10.     Private Sub client_Paint(ByVal sender As Object, _
    11.                              ByVal e As PaintEventArgs) Handles client.Paint
    12.         Using Brush As New Drawing2D.LinearGradientBrush(Me.client.Bounds, _
    13.                                                          Color.FromArgb(0, 58, 140), _
    14.                                                          Color.FromArgb(0, 215, 255), _
    15.                                                          Drawing2D.LinearGradientMode.Vertical)
    16.             e.Graphics.FillRectangle(Brush, Me.client.Bounds)
    17.         End Using
    18.     End Sub
    19.  
    20. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    526

    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).

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim bounds As New Rectangle(Point.Empty, Me.client.Size)
    2.  
    3. Using Brush As New Drawing2D.LinearGradientBrush(bounds, _
    4.                                                  Color.FromArgb(0, 58, 140), _
    5.                                                  Color.FromArgb(0, 215, 255), _
    6.                                                  Drawing2D.LinearGradientMode.Vertical)
    7.     e.Graphics.FillRectangle(Brush, bounds)
    8. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2004
    Location
    India
    Posts
    526

    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
  •  



Click Here to Expand Forum to Full Width