Keeping a mdi child maximized

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Weiss

    Keeping a mdi child maximized

    Hey guys, quick question. I am trying to create a form that is always
    maximized and is an MDI Child. When another form opens I want it to
    open (windowed) on top of this form which is still maximized. Is this
    possible?

    -Ivan

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Herfried K. Wagner [MVP]

    #2
    Re: Keeping a mdi child maximized

    * Ivan Weiss <ivanjay@optonl ine.net> scripsit:[color=blue]
    > Hey guys, quick question. I am trying to create a form that is always
    > maximized and is an MDI Child. When another form opens I want it to
    > open (windowed) on top of this form which is still maximized. Is this
    > possible?[/color]

    Why do you use an MDI environment? Maybe that's not the best choice for
    your purpose.

    --
    Herfried K. Wagner [MVP]
    <http://www.mvps.org/dotnet>

    Comment

    • Ivan Weiss

      #3
      Re: Keeping a mdi child maximized

      I am still working on a workaround to a problem I had before. I want to
      use a background image I have for my MDI Container and since there is no
      way to do that I was thinking of filling a form with a picturebox and
      just keeping it maximized which would make it appear like a background
      image in all functionality.

      -Ivan

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Ivan Weiss

        #4
        Re: Keeping a mdi child maximized

        As a further response I think an MDI environment is preferred because it
        just gives a much more professional feel to an app and makes it look
        like a familiar program (providing ease of use for my users)

        -Ivan

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Stephany Young

          #5
          Re: Keeping a mdi child maximized

          Au contraire!!!!!! !!

          I don't know who you have been talking but displaying a background image on
          the MDI parent client area can certainly be done.

          Try googling for 'mdi background image'.

          "Ivan Weiss" <ivanjay@optonl ine.net> wrote in message
          news:eE%23MSSCy DHA.2000@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          > I am still working on a workaround to a problem I had before. I want to
          > use a background image I have for my MDI Container and since there is no
          > way to do that I was thinking of filling a form with a picturebox and
          > just keeping it maximized which would make it appear like a background
          > image in all functionality.
          >
          > -Ivan
          >
          > *** Sent via Developersdex http://www.developersdex.com ***
          > Don't just participate in USENET...get rewarded for it![/color]


          Comment

          • Ivan Weiss

            #6
            Re: Keeping a mdi child maximized

            I have found one example in c++ but the problem is that it uses pointers
            so trying to convert it to VB.Net would be very difficult. It seems to
            be a widely asked topic but difficult to answer on how to apply and
            stretch a background image. Do you know of any examples or code
            snippets to help?

            -Ivan

            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • Stephany Young

              #7
              Re: Keeping a mdi child maximized

              Here we go!!!!!!!

              As you have found out, the BackgroundImage and BackColor properties of a
              form appear to be redundant when dealing with a form where the
              IsMdiContainer property is set. When the IsMdiContainer property is set, the
              form displays a sunken client area with a raised border. This area is
              actually a control of type 'MdiClient' with a default BackColour of
              SystemColors.Ap pWorkspace and it covers all of the normal client area of the
              form that is not occupied by other controls. I cannot emphasise enough, that
              you MUST differentiate between this MdiClient control and the client area of
              the form. If you fail to do so you will find yourself in deep brown stuff.

              The following assumes that the BackColor property of the form is set to the
              desired colour, the BackgroundImage property of the form is set to the
              desired image and that the IsMdiClient property of the form is set.

              You will need 3 variables with module scope:
              Private m_MDIClient As MdiClient
              Private m_OriginalBackg roundImage As Image
              Private m_IgnoreSetBack groundImage As Boolean

              The first thing you need to do is obtain a reference to the MdiClient
              control of the form and store it the appropriate variable. You can use your
              favourite algorithm for doing this. The form will have only one such
              control. Once you have it, you need to set its BackColor property to that of
              the form. This MUST be done in the forms constructor.

              In the forms Load event handler, code:
              Me.SetStyle(Con trolStyles.User Paint, True)
              Me.SetStyle(Con trolStyles.Resi zeRedraw, True)
              Me.SetStyle(Con trolStyles.Doub leBuffer, True)
              Me.SetStyle(Con trolStyles.AllP aintingInWmPain t, True)

              The next thing you need is a procedure to do the work:
              Private Sub UpdateBackGroun d()

              Dim g As Graphics

              If Not (m_OriginalBack groundImage Is Nothing) Then
              If m_MDIClient.Wid th > 0 And m_MDIClient.Hei ght > 0 Then
              Dim b As BitMap = New BitMap(m_MDICli ent.Width,
              m_MDIClient.Hei ght)
              Dim g As Graphics = Me.CreateGraphi cs.FromImage(b)
              g.Clear(Me.Back Color)
              g.DrawImage(m_O riginalBackgrou ndImage, New
              Point((m_MDICli ent.Width - m_OriginalBackg roundImage.Widt h) / 2,
              (m_MDIClient.He ight - m_OriginalBackg roundImage.Heig ht) / 2))
              m_IgnoreSetBack groundImage = True
              Me.BackgroundIm age = b
              m_IgnoreSetBack groundImage = false
              End If
              End If

              End Sub

              In the forms BackgroundImage Changed event handler, code:
              If Not m_IgnoreSetBack groundImage Then
              m_OriginalBackg roundImage = me.BackgroundIm age
              UpdateBackGroun d()
              End If

              In the forms Resize event handler, code:
              If Not (m_MDIClient Is Nothing) then UpdateBackGroun d()



              "Ivan Weiss" <ivanjay@optonl ine.net> wrote in message
              news:OlBJSqIyDH A.4064@tk2msftn gp13.phx.gbl...[color=blue]
              > I have found one example in c++ but the problem is that it uses pointers
              > so trying to convert it to VB.Net would be very difficult. It seems to
              > be a widely asked topic but difficult to answer on how to apply and
              > stretch a background image. Do you know of any examples or code
              > snippets to help?
              >
              > -Ivan
              >
              > *** Sent via Developersdex http://www.developersdex.com ***
              > Don't just participate in USENET...get rewarded for it![/color]


              Comment

              • Ivan Weiss

                #8
                Re: Keeping a mdi child maximized

                Stephany,

                You are my hero if this works. I cannot tell you how long I have been
                trying to paint the client area. However, I am not sure I understand
                this part of your instructions:

                The first thing you need to do is obtain a reference to the MdiClient
                control of the form and store it the appropriate variable. You can use
                your
                favourite algorithm for doing this. The form will have only one such
                control. Once you have it, you need to set its BackColor property to
                that of
                the form. This MUST be done in the forms constructor.

                I am very new to this level of programming and it is kind of above my
                skill but I want to learn so if you do not mind please just bare with
                me. There seems to be no good book or resource to teach this stuff...

                How do I get a reference to the MDIClient?
                Than you are saying to set its backcolor to the backcolor of the form?
                Both of these must be done in the constructor?

                -Ivan

                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • Ivan Weiss

                  #9
                  Re: Keeping a mdi child maximized

                  Stephany,

                  I think I figured out how to do what you said. I put the following code
                  in the constructor:

                  Dim ctl As Control

                  For Each ctl In Controls
                  If TypeOf ctl Is MdiClient Then
                  m_MDIClient = ctl
                  m_MDIClient.Bac kColor = Me.BackColor
                  End If
                  Next

                  However, in form load I am getting an error saying:

                  An unhandled exception of type 'System.NullRef erenceException ' occurred
                  in Elite Corporate Toolbox.exe

                  Additional information: Object reference not set to an instance of an
                  object.

                  for the line:

                  If m_MDIClient.Wid th > 0 And m_MDIClient.Hei ght > 0 Then

                  any ideas?

                  -Ivan

                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  • Stephany Young

                    #10
                    Re: Keeping a mdi child maximized

                    The line where the error is thrown should not be in the forms Load event
                    handler.

                    If you read the instructions again, you will see that that block of code
                    should be in a Private Sub named UpdateBackgroun d.

                    Taking into account your comments in your previous post, I'm going to assume
                    that you need to be taught how to suck eggs, so:

                    The constructor for the form is the Sub New procedure that can be found in
                    the generated block which is collapsed by default. You will see a comment
                    about where to place additional code.

                    Because there is only 1 MdiClient control for a form with IsMdiContainer
                    set, you can exit the For ... Next loop immediately you have dealt with it.
                    This saves iterating for the rest of the controls on the form. none of which
                    we are interested in. Place an Exit For directly preceding the End If.

                    I assume that you have set the IsMdiContainer property at design time. If
                    that is not set then there will be no MdiClient control.

                    If you coded it exactly as I described then it will run.

                    "Ivan Weiss" <ivanjay@optonl ine.net> wrote in message
                    news:OupDqePyDH A.3744@TK2MSFTN GP11.phx.gbl...[color=blue]
                    > Stephany,
                    >
                    > I think I figured out how to do what you said. I put the following code
                    > in the constructor:
                    >
                    > Dim ctl As Control
                    >
                    > For Each ctl In Controls
                    > If TypeOf ctl Is MdiClient Then
                    > m_MDIClient = ctl
                    > m_MDIClient.Bac kColor = Me.BackColor
                    > End If
                    > Next
                    >
                    > However, in form load I am getting an error saying:
                    >
                    > An unhandled exception of type 'System.NullRef erenceException ' occurred
                    > in Elite Corporate Toolbox.exe
                    >
                    > Additional information: Object reference not set to an instance of an
                    > object.
                    >
                    > for the line:
                    >
                    > If m_MDIClient.Wid th > 0 And m_MDIClient.Hei ght > 0 Then
                    >
                    > any ideas?
                    >
                    > -Ivan
                    >
                    > *** Sent via Developersdex http://www.developersdex.com ***
                    > Don't just participate in USENET...get rewarded for it![/color]


                    Comment

                    • Ivan Weiss

                      #11
                      Re: Keeping a mdi child maximized

                      I did all of that as you showed and the line that is throwing that error
                      is not in the forms load event but in the updatebackgroun d procedure
                      that we created.

                      I declared the 3 variables at the top of the form as shown here:

                      Public Class mdiMain
                      Inherits System.Windows. Forms.Form

                      Private m_MDIClient As MdiClient
                      Private m_OriginalBackg roundImage As Image
                      Private m_IgnoreSetBack groundImage As Boolean

                      #Region " Windows Form Designer generated code "

                      Public Sub New()
                      MyBase.New()

                      'This call is required by the Windows Form Designer.
                      InitializeCompo nent()

                      'Add any initialization after the InitializeCompo nent() call

                      Dim myAppName As String
                      Dim myAppVersion As String
                      Dim ctl As Control

                      myAppName = Application.Pro ductName()
                      myAppVersion = Application.Pro ductVersion
                      Me.Text = myAppName + " " + myAppVersion

                      For Each ctl In Controls
                      If TypeOf ctl Is MdiClient Then
                      m_MDIClient = ctl
                      m_MDIClient.Bac kColor = Me.BackColor
                      Exit For
                      End If
                      Next

                      End Sub

                      Yet it is still throwing that exception as I showed before saying I dont
                      have an instantiated reference...

                      -Ivan

                      *** Sent via Developersdex http://www.developersdex.com ***
                      Don't just participate in USENET...get rewarded for it!

                      Comment

                      • Stephany Young

                        #12
                        Re: Keeping a mdi child maximized

                        Can you post your forms Load event handler and a stack trace at the error
                        point please.


                        "Ivan Weiss" <ivanjay@optonl ine.net> wrote in message
                        news:ex7$sEVyDH A.3520@tk2msftn gp13.phx.gbl...[color=blue]
                        > I did all of that as you showed and the line that is throwing that error
                        > is not in the forms load event but in the updatebackgroun d procedure
                        > that we created.
                        >
                        > I declared the 3 variables at the top of the form as shown here:
                        >
                        > Public Class mdiMain
                        > Inherits System.Windows. Forms.Form
                        >
                        > Private m_MDIClient As MdiClient
                        > Private m_OriginalBackg roundImage As Image
                        > Private m_IgnoreSetBack groundImage As Boolean
                        >
                        > #Region " Windows Form Designer generated code "
                        >
                        > Public Sub New()
                        > MyBase.New()
                        >
                        > 'This call is required by the Windows Form Designer.
                        > InitializeCompo nent()
                        >
                        > 'Add any initialization after the InitializeCompo nent() call
                        >
                        > Dim myAppName As String
                        > Dim myAppVersion As String
                        > Dim ctl As Control
                        >
                        > myAppName = Application.Pro ductName()
                        > myAppVersion = Application.Pro ductVersion
                        > Me.Text = myAppName + " " + myAppVersion
                        >
                        > For Each ctl In Controls
                        > If TypeOf ctl Is MdiClient Then
                        > m_MDIClient = ctl
                        > m_MDIClient.Bac kColor = Me.BackColor
                        > Exit For
                        > End If
                        > Next
                        >
                        > End Sub
                        >
                        > Yet it is still throwing that exception as I showed before saying I dont
                        > have an instantiated reference...
                        >
                        > -Ivan
                        >
                        > *** Sent via Developersdex http://www.developersdex.com ***
                        > Don't just participate in USENET...get rewarded for it![/color]


                        Comment

                        • Dursun

                          #13
                          Re: Keeping a mdi child maximized

                          Did anybody had an answer to this question. Because I am
                          having the same problem without the dll part.

                          Thanks,
                          [color=blue]
                          >-----Original Message-----
                          >Au contraire!!!!!! !!
                          >
                          >I don't know who you have been talking but displaying a[/color]
                          background image on[color=blue]
                          >the MDI parent client area can certainly be done.
                          >
                          >Try googling for 'mdi background image'.
                          >
                          >"Ivan Weiss" <ivanjay@optonl ine.net> wrote in message
                          >news:eE%23MSSC yDHA.2000@TK2MS FTNGP11.phx.gbl ...[color=green]
                          >> I am still working on a workaround to a problem I had[/color][/color]
                          before. I want to[color=blue][color=green]
                          >> use a background image I have for my MDI Container and[/color][/color]
                          since there is no[color=blue][color=green]
                          >> way to do that I was thinking of filling a form with a[/color][/color]
                          picturebox and[color=blue][color=green]
                          >> just keeping it maximized which would make it appear[/color][/color]
                          like a background[color=blue][color=green]
                          >> image in all functionality.
                          >>
                          >> -Ivan
                          >>
                          >> *** Sent via Developersdex http://www.developersdex.com[/color][/color]
                          ***[color=blue][color=green]
                          >> Don't just participate in USENET...get rewarded for it![/color]
                          >
                          >
                          >.
                          >[/color]

                          Comment

                          Working...