Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

What type of code should I use if I have to print information in a panel on a status bar? There is text on it, however. The fact remains that along with the information contained in the labels. I also need to print the information that appears in my labels...

Thanks...

Posted

I'm not exactly sure what you were saying.. maybe I'm just tired. If you could explain better it would be appreciated.

 

Regardless of that here's a few snippets of code that may help you (assuming I understood what you said even partially).

 

'Get each label inside the panel and print it's text.
Dim c As Control
For Each c In Panel1.Controls
   If TypeOf c Is Label Then
       Console.WriteLine(c.Text)
   End If
Next

'Print the text inside a panel.
Console.WriteLine(Panel1.Text)

'Change the StatusBar's text.
StatusBar1.Text = "Some text."

Gamer extraordinaire. Programmer wannabe.
Posted

Sorry, I'll rephrase....

I created a status bar in a MdiParent form. This form is linked to a MDIChild form.

When you open the MdiParent form, 5 child forms open along with it. These child forms have 2 buttons and 2 labels. Anytime I press a button, a number appears in the label....

What I am trying to do is to have that number appear in one of the status bar panels.

The problem that I am having is that there already is text on the panel. I'll attach the solution so that you can have a look see. I hope that may help......

I apologize for my not being to explain it well. I am pretty new at this and don't yet know the lingo....

ch11ex5.zip

Posted

Well, you can either create another statusbar panel and have the text displayed in that panel, or you can just do a simple:

 

sbrMenu.Panels(0).Text = "Customers Processed: " + someNum.ToString

 

Is that what you are getting at, how do you set text in a statusbar panel?

Gamer extraordinaire. Programmer wannabe.
Posted

You have to specify the form the statusbar is on..

 

frmParent.sbrMenu.Panels(0).Text = "Customers Processed: " + someNum.ToString

 

frmParent = the name of your parent form.

Gamer extraordinaire. Programmer wannabe.
Posted

I am sorry, nothing happened.

This is what I wrote:

 

Private iNumber1 As Integer

Dim frmParent as New frmMdiParent

 

Then, in the button click event I wrote the following:

 

iNumber1 += 1

lblInline.Text = iNumber1.ToString()

frmParent.sbrMenu.Panels(1).Text = "Customers in line " + iNumber1.ToString

 

Nothing happens there., it doesn't print in the panel

 

By the way, VB asked me to declare frmParent as New frmMdiParent

 

Sorry if I seem like a dummy. This is the first time for me studying VB

Posted

*scratch*

 

I'm a little baffled as well. I've tried several different ways that should work but they just aren't (including making and calling a public function inside mdiParent to set the statusbar). There might be something with MDI forms that I'm not aware of. I'm sure it's something simple, but unfortunately I haven't played with .NET controls and forms enough to know what it is. :(

Gamer extraordinaire. Programmer wannabe.
  • *Gurus*
Posted

You need a reference to the main form to be able to change stuff on it. Since you're trying to change it from an mdi child, this is made slightly simpler. Here's the code:

 

DirectCast(Me.MDIParent, frmParent).sbrMenu.Panels(1).Text = "blah"

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 7 months later...
Posted

The problem here is that sometimes when you attempt to access the MDI parent's status bar from the child form, that the form does not yet have its MDIParent property set. For example you instantiate a child form as follows:

 

dim frm as new frmSomething

frm.MDIParent = me

 

The first line fires the constructor which also fires the load event so anything in those that expects to be able to set the statusbar will not know the MDIParent. That is defined on the next line of code.

 

the simple answer is to add a reference to the parent form in the constructor.

i.e dim frm as new frmSomething(me) and use the overloaded constructor to set a private class member. That way the parent is known about from the word go.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...