?
Solved

Statusbar Panel Picture

Posted on 2003-03-16
22
Medium Priority
?
277 Views
Last Modified: 2010-04-07
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
Comment
Question by:RainUK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
22 Comments
 
LVL 1

Expert Comment

by:hazgod
ID: 8148305
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
 
LVL 5

Author Comment

by:RainUK
ID: 8150255
I just tried it, doesn't work. Am lost for ideas, I assume this is a simple one..?
0
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8200285
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Author Comment

by:RainUK
ID: 8204569
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
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8216091
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
 
LVL 5

Author Comment

by:RainUK
ID: 8216163
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
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8218370
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
 
LVL 5

Author Comment

by:RainUK
ID: 8233530
Its just an image control, there is nothing fancy, just used to represent when someone has logged on to my program.
0
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8234053
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
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8234063
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
 
LVL 5

Author Comment

by:RainUK
ID: 8237220
Can you post some example code, because I tried what you are suggesting and I still get the same result. Stretched picture.
0
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8243861
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
 
LVL 5

Author Comment

by:RainUK
ID: 8243883
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
 
LVL 5

Author Comment

by:RainUK
ID: 8243887
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
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8246558
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
 
LVL 5

Author Comment

by:RainUK
ID: 8247597
Is there another way apart from the picture box hack? Surely there must be some WIndows API?
0
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8250512
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
 
LVL 5

Author Comment

by:RainUK
ID: 8667665
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
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8671126
You know, I've used that before and forgot all about it.  :)
0
 

Expert Comment

by:CleanupPing
ID: 8900030
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
 
LVL 1

Expert Comment

by:FunkyMeister
ID: 8904854
CleanupPing, actually, the request from RainUK is above.
0
 

Accepted Solution

by:
Chmod earned 0 total points
ID: 8908365
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question