Re: wxGrid, is there any way to get the DC?
Tony Kennedy <[email protected]>
| Newsgroups | gmane.comp.lib.wxwindows.general |
|---|---|
| Message-ID | <[email protected]> |
Works perfectly, here is some code in case it's useful for someone else.
void MyTableWindow::OnLabelDoubleClick(wxGridEvent& e)
{
wxWindow *pGridWindow = m_pGrid->GetGridWindow();
if (pGridWindow != NULL)
{
int nCol = e.GetCol();
int nRow = e.GetRow();
wxString strText = m_pGrid->GetColLabelValue(nCol); //Or strText =
m_pGrid->GetRowLabelValue(nRow);
wxClientDC dc(pGridWindow);
dc.SetFont(m_pGrid->GetCellFont(nRow, nCol));
wxArrayInt widths;
bool bResult = dc.GetPartialTextExtents(strText, widths);
}
}
On Wednesday, 6 September 2023 at 16:36:35 UTC+1 Tony Kennedy wrote:
> Brilliant, thanks for that. I'll give it a go tomorrow.
>
> On Wednesday, 6 September 2023 at 13:24:57 UTC+1 Vadim Zeitlin wrote:
>
>> On Wed, 6 Sep 2023 00:48:55 -0700 (PDT) Tony Kennedy wrote:
>>
>> TK> I've got a grid, and in the label, I've got something like
>> TK>
>> TK> some text[a,b,c,d]
>> TK>
>> TK> What I need to do is find the exact character a user clicks on when
>> they
>> TK> click in a label cell.
>> TK>
>> TK> I know I can do a hittest to get the exact point, but I cannot seem
>> to find
>> TK> a way to get the wxDC of the grid so that I can use
>> GetPartialTextExtents.
>>
>> You can use wxClientDC for wxGrid::GetGridWindow() to do what you want.
>> This is one of the cases where using wxClientDC is (and will continue to
>> be) supported, unlike actually drawing on it.
>>
>> Regards,
>> VZ
>>
>> --
>> TT-Solutions: wxWidgets consultancy and technical support
>> https://www.tt-solutions.com/
>>
>
--
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
---
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/84db9471-fbf5-42d0-a53b-1d533b8b0ec3n%40googlegroups.com.