draw label caption text as the inverse of the underlying form?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: draw label caption text as the inverse of the underlying form?

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

    draw label caption text as the inverse of the underlying form?

    i have a form with a picture on it, and im lookinga t allowing the user to vary the picture. im deliberately choosing pictures of an average colour value, like sunsets and beaches; the whole picture is roughly belonging to one colour channel, so i can set the label caption to a complementing colour channel for it to stand out; light yellow on dark blue for example

    but i'd like to know if it's possible, (even by drawing the text on a per-pixel basis?) to render text onto the image as the inverse of the colour underneath it.. hence a picture that was part red, part blue, would have text that was part cyan (on the red part) and part yellow (on the blue bits)

    for exampl:


    how can i render font text onto the form so that the text is the inverse of the form's background image?
    "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

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: draw label caption text as the inverse of the underlying form?

    As you cannot use caption prowerty of labels with more than one forecolor,
    I think you should draw directly on a pictureBox, using getpixel api to get
    the aroundcolor (left-top-right-bottom pixels around your text), and setpixel
    to draw...
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: draw label caption text as the inverse of the underlying form?

    If you are using Picture boxes then you can use a combination of Drawmode and pictureBox.Print method to achieve what you are looking for..
    "Hint : Drawmode = Not Xor Pen"

    Ever seen when a setup package created using PDWizard is executed and it shows a small progress window which displays what percentage of setup has been completed..

    Open your VB IDE and open the Setup1 project (ideally present at "C:\Program Files\Microsoft Visual Studio\VB98\Wizards\PDWizard\Setup1").. search for UpdateStatus function and you will see how it is done..

    I leave the research up to u..

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: draw label caption text as the inverse of the underlying form?

    '*****
    Great, vb_the_best! and you are really fast...
    > UpdateStatus <
    A pity I cannot rate you as have to spread around...
    '****

    A small simplified example...drag drop the "Hello" picture
    around the bacKground one...(see picture for a preview. The
    text is printed on a small picturebox...)
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by Cimperiali; June 9th, 2005 at 08:25 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

    Re: draw label caption text as the inverse of the underlying form?

    mmmmhhhhh. it's close, but not quite there..

    vb_da_best, i know why you suggest what you do; the text percentage is overpainted by a rectangular shape and as the shape passes over the text, it is inverted.. it cant be used for what i want thought, because it is the shape that is inverting rather than the text.. i want text to invert over a picture :/

    cimperiali's method is close, but uses a hotspot per letter, and requires painting messages per character.. it would take a long time to write the code that types properly kerned text.. hrmm

    ive slapped a background picture on my form, and drawn a solid Shape onto the form, then set the pen style to 6 - Invert (its the same as Not Xor) and the shape renders perfectly, the inverse of what is under it! however, i cannot find ANY way of making this work for anything other than a Shape, even though the help text indicates that DrawMode is applied to all objects. Ive tried Form1.Print "Some text" but the text is not drawn with inverse on, even though the form's drawmode is set to Invert

    ..

    so on we quest...
    Last edited by cjard; June 9th, 2005 at 11:15 AM.
    "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

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Thumbs up Re: draw label caption text as the inverse of the underlying form?

    ok.. this is what i figured out..
    Drawmode works for all the Graphic operations (Line, Pset, etc) but does not work for Print (MSDN Says that)..

    But now as I have learnt from my past experience that nothing is impossible, so here is what i did after some research and head scratching..

    Took me some time to find out the exact method, and Cimp's sample was of great help.. And Cjard's ratings acted as motivators for me..

    check out the sample attached (lot of APIs) and see if this will help..
    Attached Files Attached Files
    Last edited by vb_the_best; June 9th, 2005 at 04:00 PM.

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

    Re: draw label caption text as the inverse of the underlying form?

    that works great! im fiddling with the text rendering options to make it look a bit more pretty, but it's just what I want! Cimp; stick this in the faq thread!
    "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

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: draw label caption text as the inverse of the underlying form?

    >Cimp; stick this in the faq thread

    Done.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center