vb.net owner drawn ToolStripMenu tooltips - update
LesHay
Are you still seeing my posts?
I have devised a way to display my own format tooltips for ToolStripMenuItem menu Items.
Please let me know if you are still around and I will explain (IF you want to hear it of course)
frankbrady-5895
Windows 10
-
Frank Brady • 21 Reputation points
2023-01-30T17:08:06.6866667+00:00 leshay
I'm not seeing any activity here on the web - but I see the email notifications and thanks - the drawing stuff is what I was having trouble with. Thanks
frankbrady-5895
-
Frank Brady • 21 Reputation points
2023-01-30T17:17:16.32+00:00 leshay
As I said before, I can view your posts only by clicking on "See the Comment" in the email notification. I do not see anything here on the web site - so I can't click the vote as to helpful. I can see my comments here on the web but that's all. I know I'm signed in or I wouldn't be able to post these comments. I will be trying to adapt your drawing code to my application. I don't see any need to create new projects and test your code. That doesn't help me update my application code.
Thanks again leshay and thanks to Reza Aghaei for telling me the proper tags to use in future question postings.
frankbrady-5895
-
LesHay • 7,136 Reputation points
2023-01-31T12:20:58.0666667+00:00 Hi
I have only just found this thread. You tagged it with Windows 10 so it didn't appear in my 'followed' list.
OK, of course you don't need to make a test project, that is entirely your choice. However, it is the better option to let you first of all decide if the result is what you need (or close enough), and, lets you adjust/modify/try out variations in a small self contained piece of code.
If you want to reply to this, please add the tag 'VB' so I can see it in my 'followed' list.
-
Frank Brady • 21 Reputation points
2023-01-31T18:02:10.93+00:00 LesHay et al
Once I've posted a question with the wrong tags, I guess I'm stuck with those tags. I guess the only way to correct the tags would be to start a new question. That doesn't seem to be a proper approach, because the question hasn't really changed - I'm just at a different place in the process of getting ToolStrip menu items tootips working.
Using ToolStrip_MouseEnter as the event driving me to display the tooltip works great, but I am displaying the tootip text in a textbox rather than drawing a box and sizing it to fit the amount of text. This was a big milestone for my project development.
Now I'm trying to adapt the code that I've always used for user drawn control tooltips to my ToolStrip_MouseEnter event handler so I can properly draw a variable size box to fix my tooltip text.
Included below is the code I use for normal user drawn tooltip processing.
I'm (almost) sure that the key to drawing a variable size rectangle container for my ToolStrip tooltips is in that code - I just don't know how to adapt it to my ToolStrip_MouseEnter event handler.
Private Sub ToolTip1_Draw(sender As Object, e As DrawToolTipEventArgs) Handles ToolTip1.Draw Dim r As Rectangle = e.Bounds Try e.DrawBackground() e.DrawBorder() Dim sf As StringFormat = New StringFormat sf.Alignment = StringAlignment.Near sf.LineAlignment = StringAlignment.Center Using br As New SolidBrush(ToolTip1.ForeColor) e.Graphics.DrawString(e.ToolTipText, ToolTip1font, br, RectangleF.op_Implicit(e.Bounds), sf) End Using Catch ex As Exception Dim errorMess As String = String.Format("(ToolTip1_Draw) error : {0}", ex.Message) LogIt(errorMess) Finally '(clean up code here if applicable) End Try End Sub 'end of ToolTip1_Draw Private Sub ToolTip1_Popup(sender As Object, e As PopupEventArgs) Handles ToolTip1.Popup Try Dim sz As Size = TextRenderer.MeasureText(WrapIt(ToolTip1.GetToolTip(e.AssociatedControl)), ToolTip1font) e.ToolTipSize = New Size(sz.Width + 30, sz.Height) Catch ex As Exception Dim errorMess As String = String.Format("(ToolTip1_Popup) error : {0}", ex.Message) LogIt(errorMess) Finally '(clean up code here if applicable) End Try End Sub 'end of ToolTip1_Popup Public Shared Function WrapIt(s As String) As String Dim fin As String = String.Empty Dim outS As String = String.Empty Dim inS = s.Split(New String() {" "c}, StringSplitOptions.RemoveEmptyEntries) Dim inStst = Split(s, vbCr) Try form1.ToolTipLines = UBound(inStst) + 1 For i As Integer = 0 To inS.Length - 1 If (outS & Trim(inS(i)) & " ").Length < form1.WrapLen Then outS &= Trim(inS(i)) & " " Else fin &= outS & vbCrLf outS = Trim(inS(i)) & " " End If If inS.Length = i + 1 Then fin &= outS End If Next Return Trim(fin) Catch ex As Exception Dim errorMess As String = String.Format("(WrapIt) error : {0}", ex.Message) form1.MyAlert(errorMess) WrapIt = "WrapIt error" Finally '(clean up code here if applicable) End Try End Function 'end of WrapIt
frankbrady-5895
-
Frank Brady • 21 Reputation points
2023-01-31T23:22:53.63+00:00 LesHay
After taking a closer look at your Form2, I realized it may be the code that I need to draw a container for my ToolStrip ToolTips. I'm trying to create that form in my project environment and then use my existing ToolStrip ToolTip event to show the form.
I can't get my version of your Form2 off the ground (renamed because I already have a Form2 in my Project. I created a module named "ToolStripMenuToolTipDraw" and I can't get it to have a "Load" subroutine. Am I incorrect to use "add module" to create my version of your Form2?
frankbrady-5895
-
Frank Brady • 21 Reputation points
2023-01-31T23:24:40.9666667+00:00 LesHay
After taking a closer look at your Form2, I realized it may be the code that I need to draw a container for my ToolStrip ToolTips.
I'm trying to create that form in my project environment and then use my existing ToolStrip ToolTip event to show the form.
I can't get my version of your Form2 off the ground (renamed because I already have a Form2 in my Project.
I created a module named "ToolStripMenuToolTipDraw" and I can't get it to have a "Load" subroutine.
Am I incorrect to use "add module" to create my version of your Form2?
frankbrady-5895
Sign in to comment