Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlight selected custom control with C# WinForms
    primarykey
    data
    text
    <p>I have created a custom control (the control is used for drag and drop) and I want to add focus and selected events to the control. Both need to be visually distinct. So I plan to implement a windows style for both of these events. For focus I have the control drawing a solid and a dotted line around the control using the following code in the Paint event.</p> <pre><code> if (Image != null) { if (ContainsFocus) { // Draw a dotted line inside the client rectangle Rectangle insideRectangle = ClientRectangle; insideRectangle.Inflate(-2, -2); insideRectangle.Width--; insideRectangle.Height--; Pen p = new Pen(Color.Black, 1); p.DashStyle = DashStyle.Dot; g.DrawRectangle(p, insideRectangle); // Draw a solid line on the edge of the client rectangle Rectangle outsideRectangle = ClientRectangle; outsideRectangle.Width--; outsideRectangle.Height--; p.DashStyle = DashStyle.Solid; g.DrawRectangle(p, outsideRectangle); Color transparentLightBlue = Color.FromArgb(100, Color.LightBlue); Brush solidBrush = new SolidBrush(transparentLightBlue); g.FillRectangle(solidBrush, ClientRectangle); } } </code></pre> <p>For the Focus event I want just the image to be highlighted (similar to windows explorer). My first attempt at this was to add the following code.</p> <pre><code>Color transparentLightBlue = Color.FromArgb(100, Color.LightBlue); Brush solidBrush = new SolidBrush(transparentLightBlue); g.FillRectangle(solidBrush, ClientRectangle); </code></pre> <p>This works filling in the rectangle however I would like to just highlight the image itself instead of the entire rectangle. I've had the idea of using two different images, however the image is supplied to me and I'm not storing them. </p> <p>So my question: How is the best way to get just the image of the control that has focus to highlight?</p> <p>Thank you in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload