need help in solving code error

zack

Well-known member
Joined
Jun 9, 2005
Messages
65
Programming Experience
Beginner
does not display GUI

Well, thanks jmcilhinney for your previous help. I've worked out the codes and they are fine now. But a new problem occurred, after i started to run the application, the GUI shown was totally blank. Do do know what are the reasons behind this? I've put the bitmap pictures in my projects folder under the bin directory, in the images folder.


Imports
System.IO
Imports System.Windows.Forms
Public Class FrmPictureBox
Inherits Form
Private imageNumber As Integer = -1

'instructions display label
Friend WithEvents lblPrompt As System.Windows.Forms.Label

'image display area
Friend WithEvents picImage As System.Windows.Forms.PictureBox
'Visual Studio .NET generated code

'replace image in picImage
Private Sub picImage_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles picImage.Click

'imageNumeber from 0 to 2
imageNumber = (imageNumber + 1) Mod 3

'create Image object from file, display in PictureBox
picImage.Image = Image.FromFile _
(Directory.GetCurrentDirectory & "\images\image" & _
imageNumber & ".bmp")

End Sub 'picImage_Click
End Class 'FrmPictureBox
 
Last edited:
3. The Directory class is a member of the System.IO namespace. You must import the System.IO namespace at the top of your class file or qualify the class name when you use it.

4. System.EventArgs rather than System.EventsArgs. It is best not to write these event handlers yourself, if you have. In code view, select an object form the drop-down list at the top left and an event from the top right and an event handler stub will be created for you.

The other two are difficult to discern as things look OK. PLEASE use code tags to make your code easier to read. I cannot actually type them here because the system will interpret them as code, but they look like the following without the dots: [CO.DE]Your code here gets displayed more readably[/CO.DE]
You can type them in manually and then paste your code directly from the IDE. Otherwise you can use the advanced editor to select text and then click the button with the # symbol.

Also, I think you want to use Application.StartupPath rather than Directory.CurrentDirectory. The current directory is a system-wide setting that can change. The startup path of your app is constant.
 
GUI does not show anything

Thanks jmcilhinney for your previous help, I've worked out the codes and they are working fine now. But a new problem occurred. That is after i run the application, the GUI shown was totally blank. Do you know what are the possible reasons behind this? I've placed my bitmap pictures in my project folder, under the bin directory, in the images folder.

Imports System.IO
Imports System.Windows.Forms

Public
Class FrmPictureBox
Inherits Form
Private imageNumber As Integer = -1

'instructions display label
Friend WithEvents lblPrompt As System.Windows.Forms.Label

'image display area
Friend WithEvents picImage As System.Windows.Forms.PictureBox
'Visual Studio .NET generated code

'replace image in picImage
Private Sub picImage_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles picImage.Click

'imageNumeber from 0 to 2
imageNumber = (imageNumber + 1) Mod 3

'create Image object from file, display in PictureBox
picImage.Image = Image.FromFile _
(Directory.GetCurrentDirectory & "\images\image" & _
imageNumber & ".bmp")

End Sub 'picImage_Click
End Class 'FrmPictureBox
 
There's no constructor....
Any reason for trying to do all this by hand? There's a lot more to building the form than the code you have.....

Tg
 
help

er... ok... Is it possible for you to show me? How do you write the codes? Cuz i'm still a newbie with vb.net... Thanx
 
Well.... if you are using VStudio.... it should be creating it for you.... if you aren't..... might want to consider doing so.... let me look and see if I've got something that might help in this case.

Tg
 
If you want to add a form to your project you should do it by right-clicking on your project and selecting Add -> Add Windows Form. This creates a lot of code for you automatically and it allows you to use the designer to create your form layout, including controls, visually. The designer automatically generates the code to create the controls, set their properties and add them to the form. It is quite possible to do all this yourself in code, but it is a lot of trouble and much more error-prone.

I'm sorry if past comments of mine may have led you to believe that the section of code designated as "Windows Form Designer generated code" was not necessary. I meant that it was not necessary to include it in your post, but it is very necessary to include it in your class file. It includes the form's constructor as well as the constructors and initialisation code for all the controls on the form.

As an example, you have declared a variable in your form of type Label. To have this label appear on the form you would have to include code like the following, which the designer does for you automatically:
VB.NET:
	    Me.lblPrompt.Text = "Prompt:"
		Me.lblPrompt.Size = New Size(100, 25)
		Me.lblPrompt.Location = New Point(25, 50)
		Me.Controls.Add(Me.lblPrompt)
 
Back
Top