![]() ![]() / This treeview can mix bold and normal text Since we need the exact result (in order to draw the next text just after the previous one), we can use the following trick: we measure the length of the text and the length of the text duplicated: since in both cases the extra pixels are added, the difference will be the exact length. It happens that when using the function Graphics.MeasureCharacterRanges to measure drawn strings, some pixels are added to the exact result. To do this, we need to know the length of each portion in pixels, to set the coordinate X of the next portion, and we need a very accurate measure to avoid "holes" between two portions. To draw the text of a node, which mixes bold and non-bold portions, we need to draw the initial non-bold portion, the bold portion, and the final non-bold portion.Therefore, the TreeView control can receive the WM_NOTIFY message sent to its parent window using the following code in its own WndProc procedure:Ĭopy Code Protected Overrides Sub WndProc( ByRef m As )ĭim iResult As Integer Dim bHandled As Boolean = False If m.Msg = (&H2000 Or WM_NOTIFY) Then ' It is the reflected WM_NOTIFY message sent to the parent If m.WParam.Equals( Me.Handle) ThenīHandled = True End If End If If Not bHandled Then MyBase.WndProc(m) NET Framework adds the value 0x2000 to the value of the WM_NOTIFY message and sends it to the control. ![]() NET Framework allows controls to receive that message "reflected". So, we would need to intercept that message in the parent window, outside of our treeview control, which breaks the encapsulation rules. Windows Common Controls send NM_CUSTOMDRAW notifications through WM_NOTIFY messages to the parent window.There are some points of interest in the source code: ObjRootTreeNodeEx = AddNodeToTreeView(m_ctlTreeViewEx.Nodes, _ĪddNodeToTreeView(objRootTreeNodeEx.Nodes, " The second node", 4, 6)ĪddNodeToTreeView(objRootTreeNodeEx.Nodes, " Third node", 0, 5)ĪddNodeToTreeView(objRootTreeNodeEx.Nodes, " Node 4", 5, 1)ĪddNodeToTreeView(objRootTreeNodeEx.Nodes, " Last node", -1, 0) Object, _īyVal e As System.EventArgs) Handles MyBase.Load Private Sub Form1_Load( ByVal sender As System. Copy Code Private m_ctlTreeViewEx As TreeViewEx
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |