向面板添加内容 [英] Adding contents to a panel

查看:75
本文介绍了向面板添加内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我是vb.net的新手.我想向面板添加内容.用户将浏览一个文件,该文件将出现在面板中.我该如何进行?我的意思是可以在面板中输入内容吗?
请帮我.
Thnx

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

推荐答案

由于您尚未指定是使用Web还是Windows,因此无法提供真正有用的解决方案.答案会因环境而异.

至于文件将出现在面板中",我假设您的意思是文件的内容将在面板中呈现.同样,这取决于环境和文件类型.如果您是指图像文件,则在Windows中,您可以将PictureBox添加到面板的控件库中,然后将其指向图像.对于网络,您需要下载文件并将其存储在服务器上,然后将图像控件添加到面板中以获取其位置,或者以某种方式将图像渲染到输出流中.
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.


如果您正在使用Windows(因此,您不在使用Web),则可以使用主要控件:PictureBox;以及一些辅助控件:三个按钮(用于启动,暂停和停止音频/视频),工具提示(如果要在按钮下添加小描述)和OpenFileDialog.

设置openfile对话框的属性(名称:ofdFile),检查用户是否已使用以下代码选择了图像,音频文件或视频文件:(请阅读注释,因为它很重要!

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!

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



然后,您必须使用VB代码添加PictureBox控件:
您必须在项目窗口中添加对
的引用 Microsoft.DirectX
Microsoft.DirectX.AudioVideoPlayback




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


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.


这篇关于向面板添加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆