`
呼延浩云
  • 浏览: 81805 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
69e5c1d2-1364-320a-a0f2-0de5143310d8
互联网的那点事
浏览量:10515
社区版块
存档分类
最新评论

垂直滚动文本框(动画Aboutbox)

阅读更多

需要能够控制垂直滚动文本。我需要一个关于表格提出一些学分。由作者的一篇文章,名为保罗·皮克特,行星源code.com的页面上,我发现了一个基本的解决方案。目前我的要求改变一个我不得不增强的特点,基本解决。

请被语言错误patined的,因为英语不是我的母语。 

使用代码 

我喜欢平摊到部分文章。第1部分解释由开发者的控制的使用。第2部分的代码结构和背后的基础知识。

第1部分:“控制使用” 

属性设置: 

现在,你准备好来设置属性。在除了已知属性的用户控件,您可能会发现2个新的属性“消息”“MessageTimer” 他们也可能被发现在新旅馆类型“扩展属性”属性页。 

这两个属性是代表两个用户控件的子控件。“ 消息 “标签控制和的” MessageTimer “的一个标准定时器控制。使用属性childcontrolsUserControl的主要性能的本到设计您的animatedTexbox控制。

Message.Text: 持有的滚动文本,线条可能会跌由vbCRlf Message.TextAlign:滚动文本对齐 

MessageTimer.Interval 滚动以毫秒为单位的时间间隔。50ms的应该是不错的。MessageTimer.Enabled:启动/停止scolling 
 

这就是一切!
准备承载该控件的Windows窗体:

现在我们就来当父窗体加载初始化控制。我们这样做是在负载范围内活动的形式,看到代码列表区域。

// Private Sub frmAbout_Load(sender As Object, e As EventArgs) Handles MyBase.Load
// ‘ define the text for the message. Use vbCrlf for carriage return/new line
// Dim strMessage As String = “Copyright fremde Programm Controls:” & vbCrLf
// strMessage = strMessage & “(Taken form codeproject.com)” & vbCrLf & vbCrLf
// strMessage = strMessage & “ImageView Control by Jordy Ruiter” & vbCrLf
// strMessage = strMessage & “MultiColCombobox by Gismo” & vbCrLf
// strMessage = strMessage & “CustValidatorTextbox by Vivek Bhatnagar” & vbCrLf
// ‘ ini the control property values
// animTextBox1.Message.Text = strMessage ‘ set the message text
// ‘ set no TextAlign to use the default center alignment
// ‘ set no timer interval to use the default value of 50 milliseconds
// animTextBox1.MessageTimer.Enabled = True ‘start animation
// End Sub

第2部分:“监控守则”

 

  1. 去创建一个新的项目,选择的VisualBasic语言和类型的Windows用户控件。
  2. 重命名为的usercontrol的名称,并给它起名叫一个nimTextbox的这个名字每亩使用,否则你将不得不使用助手类的工具箱图标(详见followes)的冲突。  
  3. 创建16×16像素的位图(BMP)工具箱项的位图和地方项目文件夹中的文件。
    名称必须是animToolbox.bmp。
  4. 在设计器中打开UserControl的。
  5. 拖动面板控制它,其Dock属性设置来填补。将它命名为Panel1的。 
  6. 一个标签控件拖动到面板控制面板的页脚设置其位置,它命名为labelMessage。  
  7. 打开用户控件的代码窗口中。

 

 我除以代码成reagions更好的可读性。 

在UserControl的代码头,我们必须定义参考导入System.ComponentModel。我们需要进口定义扩展的UserControl属性。 

// ‘ ### neccessary Imports
// Imports System.ComponentModel

接下来,我们必须定义工具箱图标的代码。此代码是联系在一起的开幕类语句。
代码referencies的两个班,你必须连接到用户控件项目这个helper类是用来显示正确的图标在Visual Studio工具箱。请使用它们的。类的内容在这篇文章中没有解释,因为他们只是辅助类。   

// ‘ set the Toolbox Bitmap Icon
// ‘ this done by the classes classToolboxIcon and clsTypeConverter
// <ToolboxItem(True)> <ToolboxBitmap(GetType(animTextBoxToolboxitem), “animTextBox.bmp”)> _
// Public Class animTextBox

下一行下开幕类语句,我们定义一些全局变量和动画,我们需要一个计时器对象。

// #Region “INI Variables, objects, events” ‘ ################
// ‘ ## Property variables
// Private _Msg As Label = LabelMessage
// Private _TMR As Timer
// ‘ ## other variables
// Private intPosition = 0
// ‘ ## Private objects
// Private WithEvents objTimer1 As New Timer ‘ use withevents to get timer tick event
// #End Region

将定义_msg_TMR变量作为对照组。这个简单的技巧,为我们提供了可能性,使这个控件的属性透明透过UserControl的。由于这个原因,控制用户能够以modifiy属性的。如果我们不这样做UserControl的只显示了其自身的属性。

现在我们可以集中定义一些额外的性能提升的用户控件的标准属性:

// #Region “extended usercontrol properties” ‘ ###########
//
// ‘ public all label object properties to be able to change them
// <Browsable(True), Description(“Textlabel of the message to hold the message text”) _
// , Category(“extended Properties”)> _
// Public Property Message As Label
// Get
// Return LabelMessage
// End Get
// Set(value As Label)
// _Msg = value
// End Set
// End Property
//
// ‘ public all timer object properties to be able to change them
// <Browsable(True), Description(“Timer for animation of the message”) _
// , Category(“extended Properties”)> _
// Public Property MessageTimer As Timer
// Get
// Return objTimer1
// End Get
// Set(value As Timer)
// _TMR = value
// End Set
// End Property
// #End Region

第一物业信息  持有用户控件的子控件对象“ labelMessage “和物业MessageTimer  内部定时器对象。 

下一个步骤是定义的控制事件:

的Load事件中,我们将poulate的物业的变量_msg和_TMR 
至少我们调用内部函数“ALignText()”,使舒尔的scorlled文本对齐的要求与控制。.. 

// #Region “Control events” ‘#########################
// ‘ Event control loads
// ‘ set startup values
// Private Sub animTextBox_Load(sender As Object, e As EventArgs) Handles Me.Load
// intPosition = Panel1.Height + 25 ‘ set initial start position
// _TMR = objTimer1 ‘ load property value with timer object
// _Msg = LabelMessage ‘ load property value with label object
// ‘ 50 (Milliseconds) should be a good timer.interval value for a smooth
// ‘ animation
// objTimer1.Interval = 50
// ALignText() ‘ reset text alignment
// End Sub

管理动画的文字中,我们使用的计时器滴答事件,
动画/滚动文本,我们开始设置labelMessage.Top位置外(下同)的Panel1的控制。因此,在开始时是不可见的。

每个定时器打勾我们从顶部位置值减去1强制升abelMessage控制重绘高1点的顶部Panel1的控制。这看起来像一个向上滚动。我们这样做,只要完整labelMessage控制之外(以上)的Panel1的 控制。因此labelMessage控制是不可见的。

如果我们达到这一点,我们的labelMessage控制复位位置到IST开始值。这mimicks无休止的滚动文本。 

至少我们调用Application.DoEvents版本更新保持在定时器tikc任务可能会在所有悬而未决的应用任务。 

// ‘ Event timer tick = next animation step
// Private Sub objTimer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
// Handles objTimer1.Tick
// On Error Resume Next
// ‘ if there is no message text stop timer
// If LabelMessage.Text = “” Then
// objTimer1.Enabled = False
// Else
// ‘ increase/scroll label top point
// intPosition = intPosition – 1
// ‘ check if label is completly scrolled
// ‘ if yes reset label top position below panel to restart animation
// If intPosition = (LabelMessage.Height + 25) * -1 Then
// LabelMessage.Top = Me.Height + 25
// intPosition = LabelMessage.Top
// End If
// ‘ show label at new postion
// LabelMessage.Top = intPosition
// End If
// ALignText() ‘ make shure text alignment
// Application.DoEvents() ‘ give other app tasks a chance to work
// End Sub

为了给用户的应用程序,我们为他提供的机会可能停止滚动静态文本阅读的可能性都是这样做UserControl的区域用鼠标光标指向。要定义这一点,我们使用的Mose.Enter和鼠标。 / /’事件光标输入/面板/控制区域内离开事件,   Panel1的控制。 

// ‘ stop the animation and set text to top
// Private Sub Panel1_MouseEnter(sender As Object, e As EventArgs) Handles Panel1.MouseEnter
// ‘ stop the timer and set the label.top position to the top of the panel
// objTimer1.Enabled = False
// LabelMessage.Top = Me.Height – 50
// ALignText()
// End Sub
//
// ‘ Event cursor is leaving panel/control area
// ‘ restart the animation
// Private Sub Panel1_MouseLeave(sender As Object, e As EventArgs) Handles Panel1.MouseLeave
// ‘ reset the label.top position below the panel to restart animation
// LabelMessage.Top = Me.Height + 25
// intPosition = LabelMessage.Top
// objTimer1.Enabled = True
// End Sub
// #End Region

UFF,我们即将剩下的所有工作。我们必须定义的功能AlignText() 这将会把labelMessage控制的左边框在Panel1的控制(左对齐)或中心。 

// #Region “Private Functions/Subs” ‘#################
// ‘ Align the Textposition
// Sub ALignText()
// On Error Resume Next
// ‘ if the TextAlign property of the text label is set to left
// ‘ put the text label control to the left border of its parent (panel)
// If LabelMessage.TextAlign = ContentAlignment.TopLeft Then
// LabelMessage.Left = 1
// Else ‘ if not always center the text label (panel dock property is set to fill)
// Dim intW As Integer = Int(Me.Width / 2)
// Dim intW1 As Integer = Int(LabelMessage.Width / 2)
// Dim intDiff = intW – intW1
// If intDiff < 0 Then intDiff = 0 ‘ avoid negativ values
// LabelMessage.Left = intDiff
// End If
// End Sub
// #End Region
<span style=”font-size: 9pt;”>// end class </span>

编译该项目,并在你的下一个项目使用所创建的(控制animTextbox)DLL。

1
0
分享到:
评论

相关推荐

    自定义AboutBox 自定义AboutBox

    自定义AboutBox 自定义AboutBox 自定义AboutBox 自定义AboutBox 自定义AboutBox 自定义AboutBox

    C#资源库-AboutBox

    用C#写的aboutbox,用起来相当简单。

    AboutBox.rar_aboutbox

    又一个“关于”窗体的程序 让我们好好学下about窗体的写法

    AboutBox.rar_aboutb_aboutbox_渐变

    很漂亮的About对话框,带渐变由下而上滚动,很像电影序幕效果,这个对话框很适合做你的软件的“关于”对话框,会使你的软件更有品味哦!

    Aboutbox.xml

    aboutbox android移动应用

    特效关于对话框[AboutBox.rar]-精品源代码

    特效关于对话框[AboutBox.rar]-精品源代码

    aboutbox_demo-net2.zip_DEMO_对话框

    程序关于对话框控件 程序关于对话框控件

    VC++编的随机数产生器简单版

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    模式识别作业,C均值聚类和感知器代码

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = ...

    滑块对话框程序(Vc++ 实现代码)

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    班级查询系统,可以完成录入查询你删除

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    C++截图、抓屏程序

    #define IDM_ABOUTBOX 0x0010 #define IDD_ABOUTBOX 100 #define IDS_ABOUTBOX 101 #define IDD_TESTBMPCP_DIALOG 102 #define IDR_MAINFRAME 128 #define IDC_BUTTON1 1000 #define IDC_EDIT1 1001 #define IDC_...

    中国象棋.zip

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    多小球碰撞

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    显示我的文档路径

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    VC++访问ACCESS数据库

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    VC编写的聊天程序

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    vc++ADOX创建数据库

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    词法分析器

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX ); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_...

    圣诞节快到了,用C语言制作一个圣诞表白程序-供大家学习研究参考

    enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) ...

Global site tag (gtag.js) - Google Analytics