|
-
December 14th, 2004, 01:44 PM
#1
Remove Form picture and color text on Cmd
First problem is I have assigned a bitmap picture to my form and I cant get rid of it even when I change the background color.
Second problem, how can I change the text color on a command button?
Last edited by Cimperiali; December 16th, 2004 at 03:39 PM.
Reason: Title changed to match the question...
-
December 14th, 2004, 05:26 PM
#2
Re: Need help with 2 small problems, please.
Easy way to change font colour of a command button is to choose the Microsoft Forms 2 Object Library and use the command button provided there. That has a font colour/forecolour property. Granted, other properties / methods of it are pretty naff....
getting rid of pic:
Code:
Private Sub cmdPicOff_Click()
Picture1.Picture = Nothing
End Sub
or do you mean this:
Code:
Private Sub cmdPicOff_Click()
Me.Picture = Nothing
End Sub
Cheers
-
December 15th, 2004, 05:33 AM
#3
Re: Need help with 2 small problems, please.
Thanks very much, the one I was after was.
Form1.picture = nothing
As for the command buttons text color, it seems a little over my head
Microsoft Forms 2 Object Library
Looks like some awful foreign language to me.
-
December 15th, 2004, 06:45 AM
#4
Re: Need help with 2 small problems, please.
I’ve noticed that the above code removes the picture from the form at runtime but is there anyway to remove it from the form properties?
-
December 15th, 2004, 07:31 AM
#5
Re: Need help with 2 small problems, please.
To delete the picture from within the IDE, put the cursor in the Picture property of the properties window, and press the Delete key.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
December 15th, 2004, 09:15 AM
#6
Re: Need help with 2 small problems, please.
The Forms 2.0 controls seem rather buggy, and it would be an added dependency anyway.
Here is a way to get any color text you want for your command buttons. Remember to first set the Style of your button to Graphical during design time, or it won't work. Once this sub is called, the "real" caption for the button is actually cleared (to make room for the new one), so it don't work twice for the same button unless you include the optional caption in the call. This method also places the caption in the original position, instead of being lower as is the usual case with the Graphical Style.
Code:
Private Sub ColorCaption(Ctrl As CommandButton, Color As Long, Optional NewCaption As String)
Dim P As PictureBox
Set P = Controls.Add("VB.PictureBox", "P", Me)
If NewCaption = vbNullString Then NewCaption = Ctrl.Caption
P.AutoRedraw = 1
P.BorderStyle = 0
P.Width = Ctrl.Width
P.Height = Ctrl.Height
Set P.Font = Ctrl.Font
P.BackColor = Ctrl.BackColor
P.ForeColor = Color
P.CurrentX = P.Width \ 2 - P.TextWidth(NewCaption) \ 2
P.CurrentY = P.Height \ 2 - P.TextHeight(Chr$(65)) \ 2
P.Print NewCaption
Ctrl.Caption = vbNullString
Ctrl.Picture = P.Image
Set P = Nothing
Controls.Remove "P"
End Sub
Call the sub like this:
Code:
ColorCaption Command1, vbRed
Let me know how it works out...
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
December 15th, 2004, 11:08 AM
#7
Re: Need help with 2 small problems, please.
 Originally Posted by WizBang
To delete the picture from within the IDE, put the cursor in the Picture property of the properties window, and press the Delete key.
Thanks, that done the trick. Why-o-why isent that in any of my books?
I havent used the cmdbutton change text color code yet, Im trying to understand how it works first.
-
December 15th, 2004, 02:27 PM
#8
Re: Need help with 2 small problems, please.
 Originally Posted by dajunka
I’ve noticed that the above code removes the picture from the form at runtime but is there anyway to remove it from the form properties?
in design, in properties of the form, double click the word (Bitmap) next to the picture property, and press delete key.
in runtime, set FormX.Picture = 0
-
December 15th, 2004, 02:36 PM
#9
Re: Need help with 2 small problems, please.
 Originally Posted by dajunka
I havent used the cmdbutton change text color code yet, Im trying to understand how it works first. 
Because the standard buttons are a little bit retarded its a trick..
a standard button can either have a picture or it can have text. now, suppose you opened up ms paint and wrote the word QUIT in bright pink and saved it as a bitmap, then you added it onto the button and set the style to graphical.. the button would show a picture, and the picture would be a picture of the word "QUIT" in pink..
you starting to see how this trick works?
well that code paints the word automatically.. instead of you painting it and then saving it and loading it onto the button, it sets up a drawing object, then draws some coloured text onto it.. then sets the picture of the button to that picture that the drawing object holds..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|