Results 1 to 7 of 7

Thread: back color of MDI Parent form

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Location
    Winnipeg
    Posts
    1

    Question back color of MDI Parent form

    What is the secret to changing the backcolor property of an MDI Parent form in VB.NET?

    Changing this property does not change the back color of an MDI Parent form.backcolor
    Regards,

    Al Williams
    www.luckydogsystems.com

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you could try handling the Paint event in a new Thread, here's a quick working example i knocked up....
    VB Code:
    1. [Color=Blue]Private[/COLOR] [Color=Blue]Sub[/COLOR] Form1_Paint([Color=Blue]ByVal[/COLOR] sender [Color=Blue]As[/COLOR] [Color=Blue]Object[/COLOR], [Color=Blue]ByVal[/COLOR] e [Color=Blue]As[/COLOR] System.Windows.Forms.PaintEventArgs) [Color=Blue]Handles[/COLOR] [Color=Blue]MyBase[/COLOR].Paint
    2.           [Color=Blue]Dim[/COLOR] t [Color=Blue]As[/COLOR] [Color=Blue]New[/COLOR] Threading.Thread([Color=Blue]AddressOf[/COLOR] pnt)
    3.           t.Start()
    4.       [Color=Blue]End[/COLOR] [Color=Blue]Sub
    5. [/COLOR] [Color=Blue][/COLOR] [Color=Blue]
    6. [/COLOR] [Color=Blue][/COLOR] [Color=Blue][/COLOR]    [Color=Blue]Sub[/COLOR] pnt()
    7.           [Color=Blue]Dim[/COLOR] bmp [Color=Blue]As[/COLOR] [Color=Blue]New[/COLOR] Bitmap([Color=Blue]MyBase[/COLOR].Width, [Color=Blue]MyBase[/COLOR].Height)
    8.           bmp.SetResolution(1, 1)
    9.           [Color=Blue]Dim[/COLOR] g [Color=Blue]As[/COLOR] Graphics = Graphics.FromImage(bmp)
    10.           g.FillRectangle([Color=Blue]New[/COLOR] SolidBrush(Color.AntiqueWhite), g.ClipBounds)
    11.           g.Dispose()
    12.           [Color=Blue]MyBase[/COLOR].BackgroundImage = bmp
    13.           Application.DoEvents()
    14.       [Color=Blue]End[/COLOR] [Color=Blue]Sub
    15. [/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    This works too and is a little easier


    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

    Dim ctl as Control
    For each ctl in me.controls
    If type of ctl is mdiclient then
    ctl.backcolor = color.fromknowncolor(knowncolor.control)
    Enf If
    Next

    End Sub

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    Originally posted by Hole-In-One
    This works too and is a little easier


    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

    Dim ctl as Control
    For each ctl in me.controls
    If type of ctl is mdiclient then
    ctl.backcolor = color.fromknowncolor(knowncolor.control)
    Enf If
    Next

    End Sub

    a Form isn't a Control , so For each ctl in me.controls wont find the Form , but even if it could , you cant set the Color of an MDI Form with " .backcolor " , they want to change the backcolor of an MDI Form ....
    What is the secret to changing the backcolor property of an MDI Parent form in VB.NET?
    the only way to change it is through graphics or some serious Subclassing.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    As crazy as it sounds Hole-In-One's code does work I found the samething here:
    http://www.dotnet247.com/247referenc.../13/66667.aspx

    Although I used it in the ControlAdded event to avoid looping too often, although it is the exact samething.
    VB Code:
    1. Private Sub Form2_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles MyBase.ControlAdded
    2.         If TypeOf e.Control Is MdiClient Then
    3.             e.Control.BackColor = Me.BackColor
    4.         End If
    5.     End Sub

    Sorry i was a bit slow and didn't see your post Hole.
    Last edited by Edneeis; Nov 14th, 2003 at 03:21 PM.

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    What, were we all surprised to learn a Form is actually derived from Control?

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