Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Statusbar Panel Picture

Easy question, for you peeps, I have a status bar control and have added a picture to one of the panels, the only problem is that it always appears stretched (Horizontally) how do I insert a picture/icon into the panel and keep its aspect ratio even if the text in the same panel changes/or the form and panel get resized. Just some simple code will do.. thx
0
RainUK
Asked:
RainUK
1 Solution
 
hazgodCommented:
Private Sub Form_Resize()

with (name of the picturebox)

  .width = required size
  .height = required size

end with

this will sort out the prolem with resizing.

you need the same code in the on change event to sort out the other problem
0
 
RainUKAuthor Commented:
I just tried it, doesn't work. Am lost for ideas, I assume this is a simple one..?
0
 
FunkyMeisterCommented:
Check the AutoSize for that Panel, what is it set to, and what's the minimum width?  Also what is the Alignment set to and the Style?  (It shouldn't be set to sbrText.)

Try setting the AutoSize off for that panel and setting the width of the panel manually.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
RainUKAuthor Commented:
Hi funkymeister

Well I cannot set the style to any other otherwise it doesn't allow me to put text in there as well?

Current settings:

Alignment = sbrLeft
Style = sbrText
Bevel = sbrInsert
AutoSize = sbrContents

ideas?
0
 
FunkyMeisterCommented:
Yes:

AutoSize = sbrNoAutoSize

Manually set the width you need.

Alignment = sbrCenter

Should solve the issues when you manually force the size of the panel.

I did this for another reason.  The MinWidth setting on the panel will decide how large the picture gets.

0
 
RainUKAuthor Commented:
I need function to work out the text length in pixels or twips. Do you have one? Or am I on the wrong track?
0
 
FunkyMeisterCommented:
Is the picture alone in the panel?  If so, get the value of the picture itself.  What you could do:

With <Statusbarname>
.Panels(x).Width = .Panels(x).Picture.Width
End With

That would set the panel to the width of the picture, but the problem really lies in if the picture's height IS scaled (prior) to the size of the needed height of the panel (it's a must to resize it prior).  A really GOOD idea is to use an image list and store them all in there and then you can swap images directly.

What exactly are you doing with the picture anyways?  (Just so it makes more sense.)  And where is the picture from (is the program making it or loading it from some user specified location)?
0
 
RainUKAuthor Commented:
Its just an image control, there is nothing fancy, just used to represent when someone has logged on to my program.
0
 
FunkyMeisterCommented:
Ah, so the picture changes when you're not connected and when you are?  Yes, it'd be best to use an Image List and aim the panel's picture at the Image Listitem depending on whether or not they're connected.  Keep them all the same size though.  Should be fine.  Just note in the above example, the (x) should be the panel # you're working with.
0
 
FunkyMeisterCommented:
One thing to consider, most panel status bars are merely people using the Panels' picture and drawing in it, setting the width of the panels size to a specific amount (and not having Autosize on) and drawing lines or patterns, etc to fill it to 100% and when it's done and the bar isn't supposed to show, they merely turn the picture's visibility off or clear it to the background color of the panel.
0
 
RainUKAuthor Commented:
Can you post some example code, because I tried what you are suggesting and I still get the same result. Stretched picture.
0
 
FunkyMeisterCommented:
Okay, I did this:

Made a form (called "StatusBarForm", added a status bar (called "StatusBar"), 39 pixels high, set the form to pixels (for ease).

Made a ImageList called "Images", added 2 32x32 pictures to it.

Edited the "StatusBar" Panel(1), set it's Minimum Width to 32.

Set it's alignment to sbrCenter, it's AutoSize to sbrNoAutoSize and hit Ok.

Added this to the form:


Option Explicit

Private iCount As Long
Private Sub Form_Load()
iCount = 1
StatusBar.Panels(1).Picture = Images.ListImages(Count).Picture
End Sub

Private Sub StatusBar_PanelClick(ByVal Panel As ComctlLib.Panel)
iCount = iCount + 1: iCount = IIf(iCount > Images.ListImages.Count, 1, iCount)
StatusBar.Panels(1).Picture = Images.ListImages(iCount).Picture
End Sub


It cycles through the pictures in panel 1 when you click on the panel.  The picture WILL stretch if you don't have the status bar's height set accordingly OR you don't scale it to match the area it offers.  If the picture is stretched, try taking it into a paint program and making it larger/smaller (but keep it's dimensions so they'll work).  A good idea is to hit Print Screen and paste the running program's form into the paint program and measure it's height (so you can see how "inner tall" it is, since there's not much of an easy way to get it).
0
 
RainUKAuthor Commented:
Hi FunkMeister,

I see okay, but my problem is that in the same status bar panel I need text as well. An example is the MS internet explorer, in the status bar bottom right panel, you get a picture of a globe and the word 'internet'.
I just basically want to replicate this.
0
 
RainUKAuthor Commented:
Here's another 50 to push a solution from someone, surely someone out there has done this simple one before? EVen with a little API.
0
 
FunkyMeisterCommented:
Actually, IE's little globe there next to the "Internet" are two panels, what they've done is fixed the sizes on the entire status bar.  And when you maximize the window, the program realigns everything to where they need to be.

Another "cheat" that can be done, is to put a picturebox right over the status bar.  Right over a panel, it won't move with the panel, you'll have to do that for it, which is easy, the Panel(x).Left will tell you where on the status bar, the panel sits.  Then merely move the picture there.  Use two non-raised panels and place the picturebox over it.  Typically 2 to 3 pixels lower is fine.  The top of the status bar will tell you where it starts, to place the picturebox centered in the status bar, do this:

Picturebox.Left = StatusBar.Panels(X).Left + ( StatusBar.Panels(X).Width-Picturebox.Width)\2
Picturebox.Top = StatusBar.Panels(X).Top + ( StatusBar.Panels(X).Height-Picturebox.Height)\2

Then make sure that on a form resize, you re-align them.

Make a function that "sets up" the status bar, then you can call it on initial setup and on form resize.
0
 
RainUKAuthor Commented:
Is there another way apart from the picture box hack? Surely there must be some WIndows API?
0
 
FunkyMeisterCommented:
Not really, unless you want to build the entire statusbar from scratch (building it from nothing but pure API calls, after the form is made, then dealing with resizing, paint calls, etc).  And that just for a picture is overkill.

Most likely that's your quickest and less painful setup.
0
 
RainUKAuthor Commented:
Hi FunkyMeister

There is a much simpler way, after trawling the net again. I used the SetParent API and simply put it into the statusbar panel.
Its a one liner API call.


Please delete this question and refund points
0
 
FunkyMeisterCommented:
You know, I've used that before and forgot all about it.  :)
0
 
CleanupPingCommented:
RainUK:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
FunkyMeisterCommented:
CleanupPing, actually, the request from RainUK is above.
0
 
ChmodCommented:
PAQ'd & points refunded.

If you need a refund, you have to post a request in CS - As RainUK has now done.

Chmod
Community Support Moderator @Experts Exchange
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now