Is there a way to offset Hint window position?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #48744
    Hamilton
    Participant

      Hi IPSteven,

      I haven't used TsAlphaHints but the generic code may allow you to do what you're after:

      http://docwiki.embarcadero.com/CodeSamples/en/OnShowHint_(Delphi)

      Regards,

      Hamilton.

      #48745
      Hamilton
      Participant

        That link doesn't appear to be working so hopefully Embarcadero don't mind me posting their sample code:

        Code:
        procedure TForm1.DoShowHint(var HintStr: String; var CanShow: Boolean; var HintInfo: THintInfo);
        begin
        if HintInfo.HintControl = SpeedButton3 then
        begin
        with HintInfo do
        begin
        HintColor := clAqua;{ Changes only for this hint. }
        HintMaxWidth := 120;{Hint text word wraps if width is greater than 120. }
        Inc(HintPos.X, SpeedButton3.Width); { Move hint to the right edge. }
        end;
        end;
        end;

        procedure TForm1.FormCreate(Sender: TObject);
        begin
        Application.ShowHint := True;
        Application.OnShowHint := DoShowHint;
        end;

        #48746
        IPSteven
        Participant

          Hamilton,

          Thanks for the reply.

          That works if you're not using the AlphaSkins HintManager.

          When using the AlphaSkins HintManager

          TsCustomHintWindow.ActivateHint

          which is called after the OnShowHint event appears to ignore the HintPos position information entirely and calculate its own coordinates.

          I'm hoping there is a way to do this (create the offsets) that doesn't involve hacking the AlphaSkins code because that creates maintenance issues later on.

          #48759
          Hamilton
          Participant

            Hi IPSteven,

            I traced through the code and can see that the TsAlphaHints component has it's own OnShowHint method; if you put the code to manipulate the hint position (and color etc) in that event handler rather than the Application.OnShowHint method then everything will work as you expect. I tested setting the absolute and relative position and both worked as you would expect.

            Aside: Setting the color in the OnShowHint method did not work but that is probably part of the design, I didn't use the SkinManager to see if this could be controlled as it is outside the scope of the OP.

            Anyway good luck!

            Regards,

            Hamilton

            #48764
            IPSteven
            Participant

              Hamilton

              Thanks for pointing out that the TsAlphaHints component has it's own OnShowHint method.

              I was calling my on function by doing:

              Application.OnShowHint := MyShowHint;

              I used my function MyShowHint() to manually control the wrapping of my hint text.

              I moved my code into the HintManger.ShowHint() and the default position of the hint window changed! Its actually usable.

              I tried again to offset the hint window's X position – and it wasn't working.

              In tracing out the code I found that is TsHintManager.OnShowHintApp is being called after ShowHint()

              Code:
              procedure TsHintManager.OnShowHintApp(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
              begin
              FHintPos := HintInfo.HintPos;
              if Assigned(FOnShowHint) then FOnShowHint(HintStr, CanShow, HintInfo, HintFrame) else inherited;
              if (FHintPos.x HintInfo.HintPos.x) and (FHintPos.y HintInfo.HintPos.y) then FHintPos := HintInfo.HintPos else begin
              end;
              end;

              the code shows that unless I change both the X & Y coordinates that the changes are discarded!

              Testing verified that the HintPos can be changed as long as I change both X & Y coordinates by at least +/- 1.

              Thanks for your help in unraveling this, much appreciated.

              #48780
              Hamilton
              Participant

                My pleasure.

                Another workaround is to set the HintPos values specifically; in sAlphaHints1ShowHint instead of manipulating HintInfo.HintPos if you just set HintPos specifically that will work too, and you won't have to change both the x and y coords if you do this (but it may have other side effects I haven't considered so perhaps your original solution is best after all). Anyway just throwing it out there!

                Serge: can you please fix the bug that IPSteven pointed out; the line of code should be:

                Code:
                if (FHintPos.x <> HintInfo.HintPos.x) or (FHintPos.y <> HintInfo.HintPos.y) then FHintPos := HintInfo.HintPos else begin

                Regards,

                Hamilton

                #48829
                Support
                Keymaster

                  Hello!

                  Yes, this code will be changed, thanks 🙂

                Viewing 7 posts - 1 through 7 (of 7 total)
                • You must be logged in to reply to this topic.