CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2004
    Posts
    158

    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...

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    530

    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

  3. #3
    Join Date
    Apr 2004
    Posts
    158

    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.

  4. #4
    Join Date
    Apr 2004
    Posts
    158

    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?

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332

    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?

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    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?

  7. #7
    Join Date
    Apr 2004
    Posts
    158

    Re: Need help with 2 small problems, please.

    Quote 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.

  8. #8
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Need help with 2 small problems, please.

    Quote 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
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  9. #9
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Need help with 2 small problems, please.

    Quote 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..
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured