Rather than multi-post, I'd like to refer you to a question I posted regarding discovering controls beneath a rectangle I draw in code here:
Loading
Rather than multi-post, I'd like to refer you to a question I posted regarding discovering controls beneath a rectangle I draw in code here:
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
FroglegPosted May 2, 2012, 3:42 PM
Clay ShannonPosted May 2, 2012, 6:07 PM
Based on frogleg's sampel app, I was able to get the pseudo-highlighting of the controls working. Here's the pertinent code:
// Declare a rectangle and a point:
Rectangle describedRect;
Point startingPoint;
private bool _IsSelecting = false; // <- already had this
// In the MouseDown event:
_IsSelecting = true;
startingPoint = e.Location;
// In the MouseMove event:
if (!_IsSelecting)
return;
describedRect = Rectangle.FromLTRB(startingPoint.X, startingPoint.Y, e.X, e.Y);
// In the MouseUp event:
if (!_IsSelecting)
return;
HighlightAllTextBoxValsBetweenPoints();
_IsSelecting = false;
private void HighlightAllTextBoxValsBetweenPoints() {
foreach (Control ctrl in tableLayoutPanelGreatGooglyMoogly.Controls) {
var tb = ctrl as TextBox;
if (tb == null)
continue;
if (describedRect.IntersectsWith(tb.Bounds)) {
tb.BackColor = PSEUDO_HIGHLIGHT_COLOR;
}
}
}
Clay ShannonPosted May 2, 2012, 5:03 PM