Re: Paint event confusion, please help!!!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



GatorBait wrote:
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
.



Relevant Pages

  • Re: how to add several HTML elements to the web page dynamically using
    ... Protected Sub Button1_Click ... Dim Textbox1 As New TextBox ... is there a way to read the state of de website which controls should be "active" ... The controls, I supoose can be added via the contenttemplate of the update panel, but what about the script can it be added to the page at runtime? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: newbie syntax question: adding event handler for button not workin
    ... You say that 'most of my buttons are on a panel' which implies that you have ... Private Sub MainForm_Load ... If TypeOf FlagCtl Is Button AndAlso FlagCtl.Tag = "Filter" Then ... For Each FlagCtl As Control In Me.FlagPanel.Controls ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Factory sub box resonates too much
    ... could take the interior panel off, fiberglass a new enclosure inside the ... panel, put the mounting ring into the panel, and replace the interior panel ... In a effort to improve bass I experimented with swapping the factory 6.5 ... I am using a alpine 450 w mon sub amp to run it. ...
    (rec.audio.car)
  • Re: Nearest point to the mouse cursor?
    ... a panel and it looks good. ... scroll the panel using autoscroll ... > Private Sub Form1_Load(ByVal sender As System.Object, ... > Dim rgnCircle As Region ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Help with drawing?
    ... content of the panel to a bitmap (for double buffering so it doesn't ... > I have the following code which is supposed to draw a grid in a panel ... > and activate the autoscroll feature, however I cant get it to scroll ... > Public Sub New ...
    (microsoft.public.dotnet.languages.vb)