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?
Printable View
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?
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:
or do you mean this:Code:Private Sub cmdPicOff_Click()
Picture1.Picture = Nothing
End Sub
CheersCode:Private Sub cmdPicOff_Click()
Me.Picture = Nothing
End Sub
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. :)
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?
To delete the picture from within the IDE, put the cursor in the Picture property of the properties window, and press the Delete key.
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.
Call the sub like this: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
Let me know how it works out...Code:ColorCaption Command1, vbRed
Thanks, that done the trick. Why-o-why isent that in any of my books?Quote:
Originally Posted by WizBang
I havent used the cmdbutton change text color code yet, Im trying to understand how it works first. :sick:
Quote:
Originally Posted by dajunka
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
Because the standard buttons are a little bit retarded its a trick..Quote:
Originally Posted by dajunka
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..