Windows Forms Alt key dilemma

  • Thread starter Thread starter Rod Gill
  • Start date Start date
R

Rod Gill

Hi,

I'm learning VB.Net (VS 2003) and have built what I think is a simple
application. It consists of a base form and a Main menu form that inherits
from it. The menu form has three buttons added, each one of which when
clicked should display a message stating the name of the button. Like I
said, easy, eh?

Problem: I build, the menu form displays and I click one of the three
buttons added to the Menu Form. I get a beep then nothing. As soon as I
press the Alt key, the expected message appears!@##!

The code for the button is trivial (Enterprise of course is the name of the
button):
Private Sub Enterprise_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Enterprise.Click
System.Windows.Forms.MessageBox.Show("Enterprise Form")
End Sub

Any idea why Alt needs pressing to get the message to display? I have looked
thru all the system generated code and cannot see any reason for this,
however my background from way back is assembler programming and for the
last 10 years part-time VBA coding so I'm sure I'm missing something simple.

Failing that is there an easy way to import existing forms into a new
Project?

Many Thanks,
 
I cant reproduce this. Try working backwards. re-config your project to work
of the base form and see if this happens, if so, remove the menu, does it
still happen, if so remove the buttons and create a new one, does it still
happen ? If so, create a new form and see if a new button also does this.

If this all fails, and actually you could try this first thinking about it.
Create a new project and put one button with your message in it, and try and
re-create it.

I suspect you have set some property along the way, but I cant think what
right now.
 
Rod,

I did not see that Terry already answered your problem, I started typing and
saw he did and that I had the same idea as Terry.

However I was also tackled by this part of your message.

I'm learning VB.Net (VS 2003) and have built what I think is a simple
application. It consists of a base form and a Main menu form that inherits
from it. The menu form has three buttons added, each one of which when
clicked should display a message stating the name of the button. Like I
said, easy, eh?

Can you show something more about this construction?

Cor
 
Hi

I started a new Windows application & added a MainMenu named mnuMain to the project

I then added 3 menu items (Item1, Item2, Item3 respectively) & double-clicked each one

Then added a MessageBox message to each item:

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

MessageBox.Show("Item1")

End Sub

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click

MessageBox.Show("Item2")

End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click

MessageBox.Show("Item3")

End Sub

I ran the project & clicked each one in turn & everything works perfectly.

I have attached the VB.NET 2003 project to this thread

Crouchie1998
BA (HONS) MCP MCSE
 
Hi,

This is the designer generated code for one of the buttons, the other two
are the same except for the name:

'
'ProgramCenter
'
Me.ProgramCenter.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.ProgramCenter.Font = New System.Drawing.Font("Microsoft Sans Serif",
12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
Me.ProgramCenter.ForeColor = System.Drawing.Color.White
Me.ProgramCenter.Location = New System.Drawing.Point(72, 224)
Me.ProgramCenter.Name = "ProgramCenter"
Me.ProgramCenter.Size = New System.Drawing.Size(192, 56)
Me.ProgramCenter.TabIndex = 3
Me.ProgramCenter.Text = "Program Center"

This is the base form's load code. The result is a rectangle shape with
rounded corners:
Private Sub BaseForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Draw Form
Me.FormBorderStyle = FormBorderStyle.None
Dim p As New System.Drawing.Drawing2D.GraphicsPath
Dim CurveSize As Int32 = 250
p.StartFigure()
p.AddArc(New Rectangle(0, 0, CurveSize, CurveSize), 180, 90)
p.AddLine(CurveSize, 0, Me.Width - CurveSize, 0)
p.AddArc(New Rectangle(Me.Width - CurveSize, 0, CurveSize, CurveSize), -90,
90)
p.AddLine(Me.Width, CurveSize, Me.Width, Me.Height - CurveSize)
p.AddArc(New Rectangle(Me.Width - CurveSize, Me.Height - CurveSize,
CurveSize, CurveSize), 0, 90)
p.AddLine(Me.Width - 40, Me.Height, 40, Me.Height)
p.AddArc(New Rectangle(0, Me.Height - CurveSize, CurveSize, CurveSize), 90,
90)
p.CloseFigure()
Me.Region = New Region(p)
Me.BackColor = Color.Teal
p.Dispose()
End Sub

Anything else you want to see?
 
Rod,

I tested this and it works completly as I think that it should.
(I would not know why not, however to be absolute sure).

I would try Terry's advice.

You will not be the first where because of an unexpected orphan in by
instance the RESX or the designer code a program does not works as expected.

By the way, your button is not nice in the middle.
(and adding a label with a cross and for that a click event and in that
me.close makes debugging easier)

:-)

Cor
 
Hi,

Thanks. I'm not using the built in menu system because I've decided on a
shaped form and the normal menus don't work with it. My menu form simply has
different buttons to call up different parts of the system.

--

Rod Gill
Project MVP


Hi

I started a new Windows application & added a MainMenu named mnuMain to the
project

I then added 3 menu items (Item1, Item2, Item3 respectively) &
double-clicked each one

Then added a MessageBox message to each item:

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click
MessageBox.Show("Item1")
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click
MessageBox.Show("Item2")
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem3.Click
MessageBox.Show("Item3")
End Sub
I ran the project & clicked each one in turn & everything works perfectly.
I have attached the VB.NET 2003 project to this thread
Crouchie1998
BA (HONS) MCP MCSE
 

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

Back
Top