Click here to Skip to main content
15,909,829 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi.
I am new to vb.net. I want to add contents to a panel. The user will browse for a file and the file will appear in the panel. How can i proceed? i mean is it possible to input contents in a panel?
Plz help me out.
Thnx
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jan-12 23:54pm    
What is "file appear". Help with what?
--SA
DiiR 16-Jan-12 2:04am    
i mean when the user chooses a file ( a video, sound or image), the file chosen will show in the panel.
please see this as example:

http://i40.tinypic.com/voo8jn.jpg

the different file format are separated under video, audio and image headings.


Since you have not specified whether you are working with web or Windows a truly useful solution can't be provided; the answer will vary depending the environment.

As for "the file will appear in the panel" I will assume you mean the contents of the file will be rendered in the panel. Again, this is dependent on the environment, and the type of file. If you mean an image file then in Windows you can add a PictureBox to the panel's controls library and point it to the image. For the web you would need to download the file and store it on the server then either add an Image control to the panel for it's location or render the image into the output stream in some fashion.
 
Share this answer
 
Comments
[no name] 15-Jan-12 13:29pm    
You still have not answered the question. WHAT ENVIRONMENT!?!
DiiR 15-Jan-12 13:36pm    
Windows
If you are working with Windows (so, you are not working with web), then, you can use a pricipal control: a PictureBox; and some secondary controls: three buttons (for starting, pausing and stopping audio/video), a tooltip (if you want to add a small description under the buttons) and a OpenFileDialog.

Set the properties of the openfiledialog (name: ofdFile), check if the users has selected an Image or an audio file or a video file with this code: (read the comment becuase it is important!

VB
Public enum TypeFile As Byte
    Audio
    Video
    Image
End Enum
Public Function FileType(FileName As String) As TypeFile
    Select case mid(FileName,Filename.lenght-3,3)
        Case "jpg"
            return TypeFile.Image
'You have to add to this Select case the format that you want that your application supports. You have to bear in mind that the picturebox supports jpg,png,bmp and gif format; and the audio and video controls supports the audio and the video that your computer supports (if you don't know if a video or audio file is supported by your computer, you can open it with windows media player. IT IS IMPORTANT TO OPEN IT WITH WINDOWS MEDIA PLAYER AND NOT WITH OTHER MEDIA PLAYER!!!!
'...
    End select
End sub


Then you have to add the PictureBox control with VB code:
You have to add in project window the references to
Microsoft.DirectX
Microsoft.DirectX.AudioVideoPlayback


VB
Imports Microsoft.DirectX
Imports Microsoft.DirectX.AudioVideoPlayback
Public class Form1
Dim audio1 As Audio
Dim video As Video
Dim imm As System.Drawing.Image
Public sub AfterSelectFile(FileName As String)
Dim TP As TypeFile'the type of the file

TP = FileType(FileName)
Select Case TP
    Case 0
        'so this is an audio file and we have to add only the buttons
        'You can add the buttons with form designer and after, you can
        'Make them invisible with Visible property and then make them 
        'visibles with this routine
        Me.Button1.Visible = true
        Me.button2.Visible = true
        Me.Button3.Visible = true
        try
            audio1 = new Audio(FileName)
        Catch ex As Exception
            MsgBox("ERROR!")
            'maybe format not supported or an other error that usually come the first time you use the AudioVideoPlayback, but I can't help you with this error. I solved it much time ago and I don't remember how to solve it. I only know that is very easy. Make a search on Google.
        End Try
        'and you control the audio with the three buttons with audio1.play, audio1.pause and audio1.stop. You have to write the Click event of all buttons.

    Case 1
        'so this is a video file. You can add the PictureBox with form designer and make it visible with this code:
        me.PictureBox1.Visible = true
        Me.Button1V.Visible = true
        Me.button2V.Visible = true
        Me.Button3V.Visible = true
        try
            Video = new video(FileName)
            video.owner = me.picturebox1
        Catch ex As Exception
            MsgBox("ERROR!")
            'maybe format not supported or an other error that usually come the first time you use the AudioVideoPlayback, but I can't help you with this error. I solved it much time ago and I don't remember how to solve it. I only know that is very easy. Make a search on Google.
        End Try
    Case 2
        'so this is an Image. You can add the PictureBox over the panel with form designer and make it visible with this code.
        Me.PictureBox1.Visible = true
        image = new image(Filename)
        me.picturebox1.image = image
End Select
'IMPORTANT: YOU HAVE TO MAKE INVISIBLE THE CONTROLS THAT VOU HAVE MAKE VISIBLE AFTER THIS ROUTINE IF YOU WANT THAT ALL WORKS CORRETCLY.


I hope that on your computer works all correcty, because on mine, the first time I tried to make a similar program, I had a lot of problems.
 
Share this answer
 
Comments
DiiR 16-Jan-12 11:56am    
iv got some problems but luckily ws able 2solve it..ur codes help a lot..i tried to put a panel then if the file ws jpg i created a picturebox and the file appeared it in..
thnx 4helping me out..
LLLLGGGG 16-Jan-12 13:16pm    
I'd like to add a small tip: the video object works on all controls.
If you set the property Owner (video.owner) as a button, or a picturebox you will have a video in a button or in a picturebox.

I forgot that yesterday, but you can also use the picturebox to see video files.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900