Smart Device Framework ButtonEx Problem

J

Jeff

Hi -

I'm trying to use the OpenNetCF ButtonEx control (part of their Smart
Device Framework), and I'm having a problem with the Click event. The
event fires once, but doesn't fire on any subsequent click. What am I
doing wrong??

I've coded a simple VB.NET app, with two buttons on a form. Button1 is
a normal CF button; Button2 is the ButtonEx control. The Click event
for each button shows a messagebox.

The messagebox displays as intended when I click Button2 the first
time, but nothing happens (the click event doesn't fire) when I click
Button2 again. This problem doesn't occur with Button1.

The Form Imports OpenNETCF.Windows.Forms.

In the Declarations section for the form, I've added:
Friend WithEvents Button2 As ButtonEx

My code for Form.Paint and the Button Click events is:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Try

Button2 = New ButtonEx

Button2.Bounds = New Rectangle(80, 224, 72, 20)
Button2.Font = New System.Drawing.Font("Tahoma", 9.0!,
System.Drawing.FontStyle.Regular)
Button2.BackColor = Color.Cyan
Button2.Text = "Button2"

Me.Controls.Add(Me.Button2)

Catch ex As Exception
MessageBox.Show(ex.ToString)

End Try

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MessageBox.Show("Button 1 Clicked")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
MessageBox.Show("Button 2 Clicked")
End Sub

Thanks for any help/suggestions.
 
A

Alex Yakhnin [MVP]

Remove your initalize code from Form_Paint event and place in the Form_Load
and see if this works.
 
J

Jeff

Thanks guys, that did the trick. (I knew I was missing something pretty basic!)

- Jeff
 

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

Top