English 中文(简体)
如果在凌驾于OnRenderButtonBackground时,该 mo超越了工具StripButton,那么如何去做。
原标题:How to work out if the mouse is over a ToolStripButton when overriding OnRenderButtonBackground

我凌驾于<代码>之上。 On RenderButtonBackground 为了使用习俗彩色的方法,但我想知道,该 mo是否目前位于纽特州。

我试图获得母体控制(工具组合)和母体形式,并增加所有协调机构,但这不正确:

Private Class MyRenderer
    Inherits ToolStripProfessionalRenderer
    Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
        Dim btn = TryCast(e.Item, ToolStripButton)
        If Not btn Is Nothing AndAlso btn.Checked Then

            Dim bounds As New Rectangle(Point.Empty, e.Item.Size)
            Dim ts As ToolStrip = e.Item.GetCurrentParent
            Dim f As Form = CType(e.Item.GetCurrentParent.GetContainerControl, Form)
            Dim btnRect As New Rectangle(f.Location.X + ts.Location.X + e.Item.Bounds.X, f.Location.Y + ts.Location.Y + e.Item.Bounds.Y, e.Item.Bounds.Width, e.Item.Bounds.Height)

            If btnRect.Contains(MousePosition) Then
                 doesn t reach this path...
                e.Graphics.FillRectangle(New SolidBrush(Color.Blue), bounds)
            Else
                e.Graphics.FillRectangle(New SolidBrush(Color.Red), bounds)
            End If
        Else
            MyBase.OnRenderButtonBackground(e)
        End If
    End Sub
End Class

我确信,这样做必须有更简单的方式?

最佳回答

我不认为你需要为此使用<条码>。

相反:

If e.Item.Selected Then
  e.Graphics.FillRectangle(Brushes.Blue, bounds)
Else
  e.Graphics.FillRectangle(Brushes.Red, bounds)
End If

注:你 t忙。 ry . .

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签