Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

status bar 1

Status
Not open for further replies.

NICKYSUWANDI

Programmer
Jan 8, 2004
80
ID
i had problem in mdi form, please someone help me.
1. in my mdi form had statusbar control, when i active my
child form and work in childform, i want update some
message to statusbar in parent form, how to do that?
2. still in mdi form, ehen i active my child form,theres
anybody know how much time spent till child form actived?
3. i had made statusbar with 3 panel (message,user,datetime),
theres anyway to know which panel is selected when mouse
hover it.

sorry, maybe my question is very confused, i am just newb

Thanks
Nicky
 
Hello,

1. Check MDIParent property
2. Depends how big the form is, should be pretty much instantaneous with decently configured machin3
3. Look at mouse events - Should have a sender ojbect passed in - cast the sender to type Panel and check Name property
Good Luck!

Have a great day!

j2consulting@yahoo.com
 
1.
As SBendBuckeye says

2.
(a)Get the current time
(b)Load the child form
(c)Check difference between current time now and the time saved in (a)

3.
SBendBuckeye, the Sender parameter is the StatusBar itself, so that wouldn't really help. The only thing that I can think of is to use OwnerDraw for the Panels, and to place a control that has Mouse activity properties.


Hope this helps.
 
friends, thanks for u suggestion, but this don't solve my problem, just make me headache (i am newbie). can u give detail with sample. And for second question, i need to know the spent time to display the progress bar status (not after the form actived).


Thanks

Nicky
 
What you are asking for is not quite as straightforward as you may think. There are a number of solutions, but I think that the easiest is to "cheat"

Don't use a status bar.

On the MDI Parent form

Place a Panel
call it Panel1
set its Dock style to Bottom
set its height to that of a status bar

In Panel1
Place a Panel
call it panelLeft
set its Dock style to Left
Place a second Panel
call it panelMiddle
set its Dock style to Left
Place a third Panel
call it panelRight
set its Dock style to Fill

In panelLeft and panelRight
Place a Label
call them labelLeft, labelRight respectively
set their Dock style to Fill
delete the default Text property for them

In panelMiddle
Place a Label
call it labelMiddle
set its Dock style to Left
delete its default Text property
set its width to 0

Now you have your status bar (the middle panel will be the progress bar you wanted)

In MDI Main Form
Code:
'This handles your Mouse Hover requirement
  Private Sub label_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles labelLeft.MouseHover, labelMiddle.MouseHover, labelRight.MouseHover

    Dim lbl As Label = CType(sender, Label)
    Select Case lbl.Name
      Case "labelLeft"
        MessageBox.Show("This is the left panel")
      Case "labelMiddle"
        MessageBox.Show("This is the middle panel")
      Case "labelRight"
        MessageBox.Show("This is the right panel")
    End Select

  End Sub

  Private Sub panel_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles panelLeft.MouseHover, panelRight.MouseHover, panelMiddle.MouseHover

    Dim pnl As Panel = CType(sender, Panel)
    Select Case pnl.Name
      Case "panelLeft"
        MessageBox.Show("This is the left panel")
      Case "panelMiddle"
        MessageBox.Show("This is the middle panel")
      Case "panelRight"
        MessageBox.Show("This is the right panel")
    End Select

  End Sub

Code:
'This handles the start of the ProgressBar

  Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click

    Dim cf1 As New ChildForm1
    cf1.MdiParent = Me
    cf1.Text = "Child Form 1: "
    labelMiddle.Width = panelMiddle.Width \ 2
    cf1.Show()

  End Sub

In Child Form
Code:
'This handles the end of the ProgressBar

  Private ParentProgressUpdated As Boolean = False

  Private Sub ChildForm1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

    If Not ParentProgressUpdated Then
      Dim parentform As Form1 = CType(Me.MdiParent, Form1)
      parentform.labelMiddle.Width = parentform.panelMiddle.Width
      ParentProgressUpdated = True
    End If

  End Sub

Code:
'This updates panelRight (i.e. labelRight)

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim parentform As Form1 = CType(Me.MdiParent, Form1)
    parentform.labelRight.Text = Me.Text

  End Sub


Hope this helps.
 
thanks earthandfire, you had solve my first problem.


Thanks

Nicky

 
Nicky, I'm glad that solved your problem.

Just looking through the code again, I forgot to add (although you have probably noticed that yourself) that you need to set the BackColor of labelMiddle to Blue or whatever colour you want your "pretend" ProgressBar to be.


Hope this helps.
 
One final thought. If you are feeling brave, you could get a more realistic ProgressBar by editing the Windows Form Designer Region in the Child form.

Code:
'In MDI Parent
 Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click

    cf1 = New ChildForm1(Me)
    cf1.MdiParent = Me
    cf1.Text = "Child Form 1: " + cf1Count.ToString
    cf1.Show()

  End Sub

Code:
In the Child Form - changes shown in bold
#Region " Windows Form Designer generated code "

  Public Sub New(ByVal CalledBy As Form1)
    MyBase.New()

    [b]'This line MUST come BEFORE the call to InitializeComponent()
    MyParent = CalledBy[/b]

    'This call is required by the Windows Form Designer.
    InitializeComponent()
    [b]ShowLoadProgress()[/b]

    'Add any initialization after the InitializeComponent() call

  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  Friend WithEvents Button1 As System.Windows.Forms.Button
  Friend WithEvents NumericUpDown1 As System.Windows.Forms.NumericUpDown
  Friend WithEvents Button2 As System.Windows.Forms.Button
  Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.Button1 = New System.Windows.Forms.Button
    Me.NumericUpDown1 = New System.Windows.Forms.NumericUpDown
    Me.Button2 = New System.Windows.Forms.Button
    Me.ListBox1 = New System.Windows.Forms.ListBox
    CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    '
    'Button1
    [b]ShowLoadProgress()[/b]
    '
    Me.Button1.Location = New System.Drawing.Point(48, 32)
    Me.Button1.Name = "Button1"
    Me.Button1.TabIndex = 0
    Me.Button1.Text = "Button1"
    '
    'NumericUpDown1
    [b]ShowLoadProgress()[/b]
    '
    Me.NumericUpDown1.DecimalPlaces = 2
    Me.NumericUpDown1.Increment = New Decimal(New Integer() {1, 0, 0, 131072})
    Me.NumericUpDown1.Location = New System.Drawing.Point(152, 24)
    Me.NumericUpDown1.Maximum = New Decimal(New Integer() {15000, 0, 0, 0})
    Me.NumericUpDown1.Minimum = New Decimal(New Integer() {15000, 0, 0, -2147483648})
    Me.NumericUpDown1.Name = "NumericUpDown1"
    Me.NumericUpDown1.TabIndex = 1
    Me.NumericUpDown1.Value = New Decimal(New Integer() {775, 0, 0, 131072})
    '
    'Button2
    [b]ShowLoadProgress()[/b]
    '
    Me.Button2.Location = New System.Drawing.Point(56, 88)
    Me.Button2.Name = "Button2"
    Me.Button2.TabIndex = 2
    Me.Button2.Text = "Button2"
    '
    [b]ShowLoadProgress()[/b]
    'ListBox1
    '
    Me.ListBox1.Location = New System.Drawing.Point(168, 72)
    Me.ListBox1.Name = "ListBox1"
    Me.ListBox1.Size = New System.Drawing.Size(352, 199)
    Me.ListBox1.TabIndex = 3
    '
    'ChildForm1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(608, 309)
    Me.Controls.Add(Me.ListBox1)
    Me.Controls.Add(Me.Button2)
    Me.Controls.Add(Me.NumericUpDown1)
    Me.Controls.Add(Me.Button1)
    Me.Name = "ChildForm1"
    Me.Text = "ChildForm1"
    CType(Me.NumericUpDown1, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private MyParent As Form1

  Private LoadProgress As Integer = 1

  Private Sub ShowLoadProgress()

    'only a few controls on this form - pretend there are more
    For a As Integer = 0 To 1000
      For b As Integer = 0 To 100000
        Dim c As Double = a * b
      Next
    Next

    'update progress bar on MDI Parent
    LoadProgress += 1
    MyParent.labelMiddle.Width = (MyParent.panelMiddle.Width \ [b]5[/b]) * LoadProgress
    MyParent.labelMiddle.Refresh()

  End Sub

Something to think about - but if you do use this be careful, editing the designer's region can be risky.
 
thanks, i already add the backcolor, i give a star

thanks

nicky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top