reflect mouse on label to button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishal1082
    New Member
    • Apr 2009
    • 92

    #1

    reflect mouse on label to button

    first, i don't know what could i possibly write for the "question" field...

    i have a button, and i put a label over it, i did that, and transparency and other things are not a problem for me, the problem is, when i take mouse over the label, the button no more has the "effect" which comes when mouse is over it (blue colored in vista/7) so what i wanna do is, somehow make button think the mouse is over it when the mouse is actually over the label (that label is over button), and make it blue..., sorry if you don't get my english :( i don't know how to explain this.
  • vishal1082
    New Member
    • Apr 2009
    • 92

    #2
    forgot to add, i cannot use draw (OnPaint) text over button cause it looks something like this:

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Why are you using a label at all?
      Why are you not using the text feature of the button?

      Comment

      • vishal1082
        New Member
        • Apr 2009
        • 92

        #4
        i want to place the text at different locations, not just in middle..., and it will NOT have only a single line of text (like OK, Cancel or anything else).

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Change the TextAlignment property. You can place it in 9 different positions, not just the middle.

          You can put a newline in your text to give it line breaks.

          I just think your approach of a label over the button is a hack that is already causing you issues. Either use it as-is, or use a custom-draw function.

          forgot to add, i cannot use draw (OnPaint) text over button cause it looks something like this:
          Then make your custom draw routine more elaborate to do what you want.

          Comment

          • vishal1082
            New Member
            • Apr 2009
            • 92

            #6
            the line breaking is a little complexed, i have seen every possibility i could use, and the only way i see is labels..., i cannot draw(OnPaint), cause as you can see in above post, the draw'ed text dose not look good, while label is good..., so......

            Comment

            • vishal1082
              New Member
              • Apr 2009
              • 92

              #7
              okay, so i did some tweaking in custom drawing, the problem in drawing is it draws the text more than just 1 time, thats why it looks ugly... so i need a way to clear the old written text when its writing it again, i tried the Clear method in e.Graphics of button OnPaint event, it clears all the graphics but also put a static backround (that it asks in args), but as you can see the button is not only single colored, so... i dont know what to do :| help?

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                OnPaint should only occur when an area needs to be refreshed/redrawn, such as when an object has been obscured by another window, then returns to visibility.

                It really shouldn't be drawing more than once. Sounds like you may be calling it manually as well as the OS calling it - or some other logic problem.

                Comment

                • vishal1082
                  New Member
                  • Apr 2009
                  • 92

                  #9
                  well i don't know, i never call the Refresh or raise event manually in code, the problem what i see is, it is not erasing the previous written text on the button...

                  Code:
                  e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                  e.Graphics.DrawString("Sample Drawing...", Font, Brushes.Navy, new PointF(0, 0));
                  //TextRenderer.DrawText(e.Graphics, "Sample Drawing...", Font, new Point(0, 0), Color.Navy);
                  this is the code i write in OnPaint, the g.DrawString, or TextRenderer both work, and i dont see any difference in both...

                  Comment

                  • tlhintoq
                    Recognized Expert Specialist
                    • Mar 2008
                    • 3532

                    #10
                    But this isn't liquid ink that soaks in and bleeds. As long as the location is the same, and the font is the same, you are drawing the exact same pixels over each other. You could draw it 100 times and it wouldn't become a thicker line.

                    As a test put in a property that you can test for. The string itself perhaps. If that string is already written, then don't write it again.

                    Comment

                    • vishal1082
                      New Member
                      • Apr 2009
                      • 92

                      #11
                      If that string is already written, then don't write it again.
                      How can i check if the string is already written there....

                      But this isn't liquid ink that soaks in and bleeds. As long as the location is the same, and the font is the same, you are drawing the exact same pixels over each other. You could draw it 100 times and it wouldn't become a thicker line.
                      I understand but i dont know why and how this is happening, i managed to somehow print text just once it looked good, but when i take mouse over button, it then flickers, so the way i managed to print once was not good...

                      Comment

                      • tlhintoq
                        Recognized Expert Specialist
                        • Mar 2008
                        • 3532

                        #12
                        If that string is already written, then don't write it again.
                        How can i check if the string is already written there....
                        Add a property to check. A button already has text property. You can check to see what the .Text of a button is. But if you set it then that becomes the text on the button through the built-in Text writing methods.

                        You don't like the built-in text writing methods.

                        So you could *override* the .Text property to use your methods.
                        Or create a new property so as to not interfer with the .Text property.
                        Maybe make a "Caption" property for example.

                        Then you check the new Caption property to see if it is already the same as the text being passed in. If it is, just return without doing anything.

                        Comment

                        • tlhintoq
                          Recognized Expert Specialist
                          • Mar 2008
                          • 3532

                          #13
                          I'm just curious... What is it that you want to do better/different than the built-in text of a button? The built-in features let you change font, color, size, direction, placement. What does the built-in feature lack that you need?

                          Additionally the built-in features are aware of system wide themes and preferences. If a user has set their system preferences to larger fonts because they have poor vision then a button already reacts to that. Are you going to write your custom methods to do this as well, or are you going to have your program ignore system-wide user preferences?

                          Comment

                          • vishal1082
                            New Member
                            • Apr 2009
                            • 92

                            #14
                            i didnt understand what u meant by doing the property stuff...

                            Additionally the built-in features are aware of system wide themes and preferences. If a user has set their system preferences to larger fonts because they have poor vision then a button already reacts to that.
                            No, i m not going to take that in account, i will ignore "system-wide user prefences'. Actually, i m developing a application sort of Organizer, it has a calander-type interface, when u click on a date it shows events on the date, i wanna display the events in like.. a button for a event... now i have to display the time of event, reoccurence, title and discription, but i cant use label cause then the "effect" of button when mouse is over it is not working..., i use button cause i want that "glow" effect of button.

                            Comment

                            • tlhintoq
                              Recognized Expert Specialist
                              • Mar 2008
                              • 3532

                              #15
                              Sounds like a very ambitious project to tackle this early in your learning.

                              i didnt understand what u meant by doing the property stuff...
                              Do you know what a property is?
                              Have you ever written something that looks like this?
                              Code:
                              private string _caption;
                              public string Caption
                              {
                                  get
                                  {
                                       return _caption;
                                  }
                                  set
                                  {
                                        if (value != _caption)
                                        {
                                            // Then it is a new value
                                            DoCustomDraw(value);
                                        }
                                        _caption = value;          
                                  }
                              }
                              By the way, that was a hint about your need for a caption property.

                              Comment

                              Working...