将所有表单/文件保存在vb.net中 [英] Saving all of a form/file in vb.net

查看:87
本文介绍了将所有表单/文件保存在vb.net中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用另存为保存表单.我正在使用msdn中的代码,但是在保存表单时遇到了问题.当我单击保存为"菜单时,它会保存一个副本,但它是空白的.我相信我的问题在于无法将Form写入Windows.
SaveAsToolStripMenuItem_Click(问题区域)

I would like to save a form using save as. I am using a code from msdn but am having problems getting the form to save. When I click on save as the menu is there and it saves a copy but it is blank. I believe my problem is in not being able to get the Form to write to windows.
SaveAsToolStripMenuItem_Click (problem area)

If (myStream IsNot Nothing) Then
       Form1 = saveFileDialog1.FileName ' Code to write the stream goes here this is where I believe the problem is.
       myStream.Close()
   End If

完整代码如下.

伙计们,我是新手,并且希望尽可能简单.一切工作正常,但另存为,我真的不希望更改其余代码,即使它很笨拙也仍然可以工作.我已经尝试了几种解决方案,但是没有用.如果可以更好地解释Microsoft发布的代码,这将对您有所帮助,但我感到很遗憾地缺少它们.如果有人可以帮助我,我将永远感激不已. PS.这是很难获得任何文档的主题.


''下面的完整代码

Full Code is below.

Guys I am a novice and would like to keep this as simple as possable. everything works fine but the save as and I really have no wish to change the rest of the code even if it is clumsy it still works. I have tried several solutions the I googled but to no avail. If the codes that microsoft post were better explained that would be a help but I find them sorrily lacking. If someone can help I would be eternally grateful. PS. This is a hard subject to get any documentation on.


''FULL CODE BELOW

Imports System.Drawing.Printing
Imports System.IO

Public Class FMCommision
    Inherits System.Windows.Forms.Form

    Private Sub FMCommision_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub btnInternal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInternal.Click
        Dim dblHomePrice, dblCommissionRate, dblCommission
        Dim dblHST, dblTotalCommission, dblHeldinTrust, dblAmountDue, dblCloseCommission
        dblCommission = lblC.Text
        dblCommissionRate = txtCR.Text
        lblE1.Text = ""
        If IsNumeric(txtSalePrice.Text) Then      
            If IsNumeric(txtCR.Text) Then
                If IsNumeric(txtTrust.Text) Then

                    
                    dblHomePrice = Convert.ToDouble(txtSalePrice.Text)
                    dblHeldinTrust = Convert.ToDouble(txtTrust.Text)

                
                    dblCommission = dblHomePrice * dblCommissionRate / 100
                    dblHST = dblCommission * 0.15
                    dblTotalCommission = dblHST + dblCommission
                    dblAmountDue = dblTotalCommission - dblHeldinTrust
                    dblCloseCommission = dblAmountDue + dblHeldinTrust

                   
                    lblC.Text = Format(dblCommission, "Currency")
                    lblHC.Text = Format(dblHST, "Currency")
                    lblTC.Text = Format(dblTotalCommission, "Currency")
                    lblAD.Text = Format(dblAmountDue, "Currency")
                    lblT1.Text = Format(dblAmountDue, "Currency")
                  

                Else
                    MsgBox("Use Default Value 0.00 if no Deposit Held)", CType(MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, MsgBoxStyle), "Data Entry Error!")
                    txtTrust.Focus()                                  
                    txtTrust.SelectAll()                             
                End If
            Else
                MsgBox("Enter Percent Value (Format 1 or 1.1)", CType(MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, MsgBoxStyle), "Data Entry Error!")
                txtCR.Focus()                                  
                txtCR.SelectAll()                               
            End If

        Else
            MsgBox("Enter Sale Price (Format 1000.00)", CType(MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, MsgBoxStyle), "Data Entry Error!")
            txtSalePrice.Focus()                                 the error occurred
            txtSalePrice.SelectAll()                               
        End If

    End Sub
                                   'SAVE AS CODE BELOW
 ------------------------------------------------------------------------------------- 

   Private Sub SaveAsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
 
        Dim myStream As Stream
        Dim saveFileDialog1 As New SaveFileDialog()
        Dim Form1 As String
 
        saveFileDialog1.Filter = "txt files (*.txt)|*.txt|Word Document (*.docx)|*.docx|Word 97 Doc (*.doc)|*.doc|OpenDocument Text (*.odt )|* .odt|PDF (*.pdf)|*.pdf|Rich Text Format (*.rtf)|*.rtf|Word Perfect (*.wpd)|*.wpd|All files (*.*)|*.*"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True
 
        If saveFileDialog1.ShowDialog() = DialogResult.OK Then
            myStream = saveFileDialog1.OpenFile()
            If (myStream IsNot Nothing) Then
                Form1 = saveFileDialog1.FileName ' Code to write the stream goes here this is where I believe the problem is.
                myStream.Close()
            End If
        End If
    End Sub
 
 -------------------------------------------------------------------------------------  

     Private Sub PrintToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        PrintForm1.Print()
    End Sub
 
 
    Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
 
End Class

与我保持谦虚

推荐答案

问题是您没有执行任何操作来保存数据.
到目前为止,您所要做的就是将一些代码放在一起,并寄予希望.

就像一个非常聪明的比利时人曾经说过的那样:在软件中,希望和祈祷不是可行的策略." (Luc Pattyn)

您需要查看要尝试做的事情,并在简单的阶段中确定所需的内容.
您已完成阶段1:获取文件名.
现在,您需要编写一个实际使用它的方法.


顺便说一句:除非您真的在寻找一些辛苦的工作,否则请不要选择另存为两种类型的Word文档:PDF,Perfect Perfect,ODT等.目前只关注一种类型-可能是文本或二进制.并且不要以易于保存"的方式工作,而是将其计划为易于加载"-因为如果您无法读取文件,那完全是浪费时间!

这可能看起来很苛刻,但是您自己做会比期望我们为您做的要学到更多.
The problem is that you have done nothing to save the data.
All you have done so far is throw a few bits of code together, and hope.

As a very intelligent Belgian once said: "In software, hope and pray is not a viable strategy." (Luc Pattyn)

You need to look at what you are trying to do and work out what you need in easy stages.
You have done stage 1: Get the file name.
Now, you need to write a method that actually uses it.


BTW: Unless you are really looking for some hard work, get rid of the options to save as two types of Word document, PDF, word perfect, ODT, etc. Concentrate on a single type for the moment - probably text or binary. And work not as "easy to save" but plan it to be "easy to load" instead - because if you can''t read your file, it is a complete waste of time!

This may seem harsh, but you will learn a lot more by doing it yourself than expecting us to do it for you.


好的,现在您必须打开文件,必须获取要保存的表单中的数据,将其格式化为某种格式,以便稍后在加载数据并将格式的数据写出到流中时进行解析.

您可能需要查看StreamWriter类上的文档,以获取可以调用以将数据写入文件的各种方法.
OK, now that you have to file open, you have to get the data from the form that you want to save, format it into somethign that you can parse later on when you load the data and write the formatted data out to the stream.

You might want to look at the documentation on the StreamWriter class for various methods you can call to write data to a file.


这篇关于将所有表单/文件保存在vb.net中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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