打印本文 打印本文 关闭窗口 关闭窗口
用vb.net实现类似写字板程序的部分源代码
作者:武汉SEO闵涛  文章来源:敏韬网  点击数7898  更新时间:2009/4/23 19:01:52  文章录入:mintao  责任编辑:mintao
.Style)
        End If
    End Sub

    ''''下面这个SetFontFamily函数是用来设置字体的变化
    Public Sub SetFontFamily(ByVal rtb As RichTextBox, ByVal fontName As String)
        Dim fontFam As New System.Drawing.FontFamily(fontName)
        Dim style As System.Drawing.FontStyle


        If rtb.SelectionLength > 0 Then
            Dim selStart As Integer = rtb.SelectionStart
            Dim selLength As Integer = rtb.SelectionLength

            Dim i As Integer
            For i = 0 To selLength - 1

                rtb.Select(selStart + i, 1)

                style = GetSafeStyleForFontFamily(fontFam, rtb.SelectionFont.Style)

                rtb.SelectionFont = New Font(fontFam, rtb.SelectionFont.Size, style)
            Next

            rtb.Select(selStart, selLength)
        Else

            style = GetSafeStyleForFontFamily(fontFam, rtb.SelectionFont.Style)

            rtb.SelectionFont = New Font(fontFam, rtb.SelectionFont.Size, style)
        End If
    End Sub

    ''''************************************************************************************

    ''''下面这个函数是用来新建文件
    Private Sub newfile()
        Dim flag As Integer
        ''''如果文本已经被保存,则清空rtbox内容,所有变量重置以新建文本
        If bSave Then
            rtbox.Clear()
            SaveFileDialog1.FileName = ""
            bSave = True
        Else
            ''''如果文本没有保存,则提示是否要保存
            flag = MessageBox.Show("文件内容已更改,想保存文件吗??", "info", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)
            Select Case flag
                ''''case 6是当用户选择了“保存”,则执行保存文件的操作
            Case 6
                    ''''如果没有选择要保存的文件名,则弹出保存对话框,由用户选择要保存的文件名后保存文本
                    If SaveFileDialog1.FileName = "" Then
                        If SaveFileDialog1.ShowDialog Then
                            rtbox.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
                        End If
                    Else
                        ''''如果已经选择了要保存的文件名,则保存文本到文件中
                        rtbox.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
                    End If
                    ''''然后就是清空rtbox的内容,重置变量以新建文本
                    bSave = True
                    rtbox.Clear()
                    SaveFileDialog1.FileName = ""

                    ''''case 7就是当用户选择了no也就是不保存时,立即清空rtbox内容,重置变量以新建文本
                Case 7
                    rtbox.Clear()
                    SaveFileDialog1.FileName = ""
                    bSave = True

                    ''''case else就是当用户选择了取消,则取消新建操作,也就是Do Nothing
                Case Else
            End Select
        End If
    End Sub

    ''''下面这个函数是用来打开文件
    Private Sub openfile()
        Dim flag As Integer
        ''''如果文本内容没有保存,询问用户是否保存
        If Not bSave Then
            flag = MessageBox.Show("文件内容已更改,想保存文件吗??", "info", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)
            Select Case flag
                ''''case 6是当用户选择了“保存”,则执行保存文件的操作
            Case 6
                    ''''如果没有选择要保存的文件名,则弹出保存对话框,由用户选择要保存的文件名后保存文本
                    If SaveFileDialog1.FileName = "" Then
                        If SaveFileDialog1.ShowDialog Then
                            rtbox.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
                        End If
                    Else
                        ''''如果已经选择了要保存的文件名,则保存文本到文件中
                        rtbox.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
                    End If
                    ''''弹出打开文件对话框,执行打开文件操作
                    bSave = True
                    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                        rtbox.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
                    End If

                    ''''case 7的意思是如果用户选择了“不保存”,则直接执行打开文件操作
                Case 7
                    If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
&n

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  下一页

打印本文 打印本文 关闭窗口 关闭窗口