Paint event confusion, please help!!!

G

GatorBait

Good morning experts,

Here is what I'm trying to accomplish:

I have a form that has 8 panels spaced out so that they look like rows.
Inside each panel is a series of labels and when a user clicks any
label in the panel I am trying to have a thick border around the panel
to indicate that row has been selected. I was able to get it so that a
rectangle is drawn around the panel, but this is the problem I'm
running into. I have a modular level variable which I set to 0 or 3
for the selected row. I call the invalidate event of each panel so
that it will repaint. My problem is that I all of the rows are being
selected. Below is the code I am using (sorry the last Sub is ugly
looking):

Private Sub SelectRow(ByVal iRow As Integer, ByVal bSelected as
Boolean)
Dim x As Integer

'unselect all rows
m_iSize = 0
For x = 1 To 8
Me.Controls("pnlRow0" & CStr(x)).Invalidate()
Next

'draw border around selected border
If bSelected Then
m_iSize = 3
Me.Controls("pnlRow0" & CStr(iRow)).Invalidate()
End If
End Sub

Private Sub PaintBorder01(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles pnlRow01.Paint,
pnlRow02.Paint, pnlRow03.Paint, pnlRow04.Paint, pnlRow05.Paint,
pnlRow06.Paint, pnlRow07.Paint, pnlRow08.Paint
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle,
Color.Black, m_iSize, ButtonBorderStyle.Solid, Color.Black, m_iSize,
ButtonBorderStyle.Solid, Color.Black, m_iSize, ButtonBorderStyle.Solid,
Color.Black, m_iSize, ButtonBorderStyle.Solid)
End Sub
 
C

Chris

GatorBait said:
Good morning experts,

Here is what I'm trying to accomplish:

I have a form that has 8 panels spaced out so that they look like rows.
Inside each panel is a series of labels and when a user clicks any
label in the panel I am trying to have a thick border around the panel
to indicate that row has been selected. I was able to get it so that a
rectangle is drawn around the panel, but this is the problem I'm
running into. I have a modular level variable which I set to 0 or 3
for the selected row. I call the invalidate event of each panel so
that it will repaint. My problem is that I all of the rows are being
selected. Below is the code I am using (sorry the last Sub is ugly
looking):

Private Sub SelectRow(ByVal iRow As Integer, ByVal bSelected as
Boolean)
Dim x As Integer

'unselect all rows
m_iSize = 0
For x = 1 To 8
Me.Controls("pnlRow0" & CStr(x)).Invalidate()
Next

'draw border around selected border
If bSelected Then
m_iSize = 3
Me.Controls("pnlRow0" & CStr(iRow)).Invalidate()
End If
End Sub

Private Sub PaintBorder01(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles pnlRow01.Paint,
pnlRow02.Paint, pnlRow03.Paint, pnlRow04.Paint, pnlRow05.Paint,
pnlRow06.Paint, pnlRow07.Paint, pnlRow08.Paint
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle,
Color.Black, m_iSize, ButtonBorderStyle.Solid, Color.Black, m_iSize,
ButtonBorderStyle.Solid, Color.Black, m_iSize, ButtonBorderStyle.Solid,
Color.Black, m_iSize, ButtonBorderStyle.Solid)
End Sub

I don't see where in your code you tell it which panels are "selected"
and which aren't. Here's how I would do this:

'Note, this code isn't test, just the concept
public class FormattedPanel
inherits panel

private overrides sub OnPaint(...)
mybase.Onpaint(...)
if mSelected then
'Draw boarder
end if
end Sub

public property IsSelected as boolean
get
return mSelected
end get
set(value as boolean)
mSelected=value
end set
end property
End Class

This way you can just set the panel to selected or not selected and the
paint event takes care of drawing your border.

Hope this helps
Chris
 
G

GatorBait

Chris,

Thank you so much for your help...your second solution worked great!!!!
Thanks for also clearing up a bit about the inherited control.

Thank you again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Paint event of a panel 4

Top