本文介绍了如何在vb.net的初始屏幕中显示更改的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在初始屏幕中显示更改的文本,例如在专业初始屏幕中..诸如加载组件...连接到数据库等之类的东西显示...我该怎么做?我使用的是Visual Basic ...预先感谢

How can I show changing texts in splash screen e.g in professional splash screens .. things like loading components...coneecting to database etc show up... how can i do that? I am using visual basic...Thanks in advance

推荐答案

Public Class Splash

    Public barwidth As Integer = 200
    Private Sub Splash_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim hfont As New Font("Arial", 12, FontStyle.Bold)
        Dim font As New Font("Arial", 10, FontStyle.Regular)

        e.Graphics.DrawString("Some Static Text", hfont, New SolidBrush(Color.Black), 33, 100)
        e.Graphics.DrawString("More Static Text", font, New SolidBrush(Color.Black), 33, 120)

        e.Graphics.DrawString("Loading..", font, New SolidBrush(Color.Gray), 33, 181)

        ShowProgress(0, "Loading..")
    End Sub
    Public Sub ShowProgress(ByVal percentage As Integer, ByVal operation As String)
        Dim font As New Font("Arial", 8, FontStyle.Regular)
        Dim gr As Graphics = CreateGraphics()
        gr.DrawRectangle(New Pen(Color.Black), New Rectangle(142, 202, barwidth, 19))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(255, 0, 0)), New Rectangle(143, 203, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(240, 0, 0)), New Rectangle(143, 204, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(230, 0, 0)), New Rectangle(143, 205, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(220, 0, 0)), New Rectangle(143, 206, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(210, 0, 0)), New Rectangle(143, 207, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(200, 0, 0)), New Rectangle(143, 208, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(195, 0, 0)), New Rectangle(143, 209, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(190, 0, 0)), New Rectangle(143, 210, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(185, 0, 0)), New Rectangle(143, 211, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(180, 0, 0)), New Rectangle(143, 212, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(175, 0, 0)), New Rectangle(143, 213, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(170, 0, 0)), New Rectangle(143, 214, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(165, 0, 0)), New Rectangle(143, 215, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(160, 0, 0)), New Rectangle(143, 216, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(155, 0, 0)), New Rectangle(143, 217, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(150, 0, 0)), New Rectangle(143, 218, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(145, 0, 0)), New Rectangle(143, 219, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(140, 0, 0)), New Rectangle(143, 220, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.FromArgb(135, 0, 0)), New Rectangle(143, 221, (barwidth * percentage) / 100, 1))
        gr.FillRectangle(New SolidBrush(Color.IndianRed), New Rectangle(0, 250, 485, 50))
        gr.DrawString(operation, font, New SolidBrush(Color.WhiteSmoke), 5, 250)
    End Sub
End Class




这就是启动屏幕的背面.

条形大小几乎等于您希望条形的宽度.

这就是我的主要形式.




That is what is in the back of the splash screen.

Barsize is pretty much how many pixels wide you want the bar to be.

This is what I have in my main form.

Imports System.Threading

Public Class Form1
    Dim splashForm As Splash
    Public Sub New()
        Me.Enabled = False
        splashForm = New Splash()
        splashForm.Owner = Me
        splashForm.Show()
        Application.DoEvents()

        'simulate work!
        Thread.Sleep(1000)
        splashForm.ShowProgress(10, "Describe what you are loading here.....")
        Thread.Sleep(1000)
        splashForm.ShowProgress(25, "More description of loading here.....")
        Thread.Sleep(1000)
        splashForm.ShowProgress(70, "Bit more")
        Thread.Sleep(1000)
        splashForm.ShowProgress(100, "Finished!")
        Thread.Sleep(1000)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Enabled = True
        Me.Visible = True
        splashForm.Close()

    End Sub
End Class




我在紧凑的框架环境中使用了此功能,因为我希望在初始屏幕上使用渐变进度栏.

可能有很多更好的方法可以实现,但是这种方法确实有效.

只需稍微调整一下坐标即可!

祝你好运!




I used this in a compact framework environment because I wanted a gradient progress bar on the splash screen.

There are probably loads of much better ways of doing it, but this method does work.

Just takes a bit of tweaking of coordinates!

Good luck!


这篇关于如何在vb.net的初始屏幕中显示更改的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:04
查看更多