CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

关于Text的一个问题

楼主victorji(秋华)2003-09-01 23:36:37 在 VB / 基础类 提问

form1上有一TextBox1,当form1显示的时候就选中textbox1.text中的文本 问题点数:10、回复次数:7Top

1 楼rainstormmaster(暴风雨 v2.0)回复于 2003-09-02 01:29:26 得分 2

Option   Explicit  
   
  Private   Sub   Form_Load()  
          Text1.Text   =   "1234567"  
          Text1.SelStart   =   0  
          Text1.SelLength   =   Len(Text1.Text)  
          Me.Show  
          Text1.SetFocus  
  End   Sub  
  Top

2 楼chanet(牧师)回复于 2003-09-02 01:51:26 得分 1

Text1.SelStart   =   0  
          Text1.SelLength   =   Len(Text1.Text)  
  Top

3 楼callzjy((草魚))回复于 2003-09-02 02:46:29 得分 1

Private   Sub   Form_Load()  
          Text1.SelStart   =   0  
          Text1.SelLength   =   Len(Text1.Text)  
          Me.Show  
          Text1.SetFocus  
  End   SubTop

4 楼ch21st(www.blanksoft.com)回复于 2003-09-02 08:26:50 得分 3

楼主的问题大家说的都很明白了,不过我在补充一点其他的方法,就是用api  
  这个例子适合多行文本,选择任意文本块  
   
  Private   Declare   Function   SendMessage   Lib   "user32"   _  
          Alias   "SendMessageA"   _  
        (ByVal   hwnd   As   Long,   _  
          ByVal   wMsg   As   Long,   _  
          ByVal   wParam   As   Long,   _  
          lParam   As   Any)   As   Long  
   
  Private   Const   EM_GETSEL     As   Long   =   &HB0  
  Private   Const   EM_SETSEL     As   Long   =   &HB1  
  Private   Const   EM_GETLINECOUNT     As   Long   =   &HBA  
  Private   Const   EM_LINEINDEX     As   Long   =   &HBB  
  Private   Const   EM_LINELENGTH     As   Long   =   &HC1  
  Private   Const   EM_LINEFROMCHAR     As   Long   =   &HC9  
  Private   Const   EM_SCROLLCARET   As   Long   =   &HB7  
  Private   Const   WM_SETREDRAW     As   Long   =   &HB  
  Public   Function   GetBlockText(ctl   As   TextBox,   _  
                                                            passedLineStart   As   Long,   _  
                                                            passedLineEnd   As   Long)   As   String  
   
     
        Dim   copyStart   As   Long  
        Dim   copyEnd   As   Long  
        Dim   currLine   As   Long  
        Dim   lineCount   As   Long  
        Dim   success   As   Long  
        Dim   currCursorPos   As   Long  
   
        ctl.SetFocus  
         
        If   Check1.Value   =   1   Then  
         
              currCursorPos   =   ctl.SelStart  
              Call   SendMessage(ctl.hwnd,   WM_SETREDRAW,   False,   ByVal   0&)  
              DoEvents  
               
        End   If  
      '--------------------------------  
   
      'get   the   number   of   lines   in   the   textbox  
        lineCount   =   SendMessage(ctl.hwnd,   EM_GETLINECOUNT,   0,   ByVal   0&)  
                                                                 
     
        passedLineStart   =   passedLineStart   -   1  
       
      'proceeding   only   if   there   are   lines   to   work   with  
        If   lineCount   >   0   Then  
         
            'if   the   startline   greater   than   0  
              If   passedLineStart   >   0   Then  
                     
                  'get   the   number   of   chrs   up   to   the  
                  'end   of   the   desired   start   line  
                    copyStart   =   SendMessage(ctl.hwnd,   _  
                                                                    EM_LINEINDEX,   _  
                                                                    passedLineStart,   ByVal   0&)  
                                                                             
              Else:   'start   at   the   beginning  
                          'of   the   textbox  
                            copyStart   =   0  
               
              End   If  
               
            'if   the   lastline   greater   than   0   and  
            'less   then   the   number   of   lines   in   the  
            'control..  
              If   passedLineEnd   >   0   And   _  
                    passedLineEnd   <=   lineCount   Then  
                     
                    '..get   the   number   of   chrs   up   to   the  
                    'end   of   the   desired   last   line  
                      copyEnd   =   SendMessage(ctl.hwnd,   _  
                                                                  EM_LINEINDEX,   _  
                                                                  passedLineEnd,   ByVal   0&)  
     
              Else:   'copy   the   whole   thing  
                            copyEnd   =   Len(ctl)  
               
              End   If  
               
   
              success   =   SendMessage(ctl.hwnd,   _  
                                                          EM_SETSEL,   _  
                                                          copyStart,   _  
                                                          ByVal   copyEnd)  
                                                                 
              If   success   <>   -1   Then  
                  'return   the   selected   text  
                    GetBlockText   =   ctl.SelText  
              End   If  
               
        End   If  
   
      '-------------------------------  
      'optional:   used   to   end   transparent   action  
        If   Check1.Value   =   1   Then  
               
              ctl.SelStart   =   currCursorPos  
              Call   SendMessage(ctl.hwnd,   WM_SETREDRAW,   True,   ByVal   0&)  
               
        Else  
         
            'scroll   the   selected   item   into   view  
              Call   SendMessage(ctl.hwnd,   EM_SCROLLCARET,   0,   ByVal   0)  
         
        End   If  
      '--------------------------------  
   
  End   FunctionTop

5 楼cuizm(射天狼 http://www.j2soft.cn/)回复于 2003-09-02 08:35:59 得分 1

Text1.SelStart   =   0  
          Text1.SelLength   =   Len(Text1.Text)  
          Text1.TabIndex   =   0Top

6 楼chao778899(220330)回复于 2003-09-02 08:59:17 得分 1

Option   Explicit  
   
  Private   Sub   Form_Load()  
          Text1.Text   =   "1234567"  
          Text1.SelStart   =   0  
          Text1.SelLength   =   Len(Text1.Text)  
          Me.Show  
          Text1.SetFocus  
  End   Sub  
  Top

7 楼stonelang()回复于 2003-09-02 10:27:13 得分 1

if   form1.show   then   text1.setfocusTop

相关问题

  • text
  • _T,TEXT,_TEXT,L,etc.
  • text in row??
  • Text greater than 32k?????
  • text问题?
  • text问题?
  • 关于text型
  • Text问题
  • TEXT("...")的作用。
  • Text和Varchar??

关键词

  • 文本
  • me
  • selstart
  • sellength
  • setfocusend
  • ctl
  • const em
  • sendmessage
  • byval
  • len

得分解答快速导航

  • 帖主:victorji
  • rainstormmaster
  • chanet
  • callzjy
  • ch21st
  • cuizm
  • chao778899
  • stonelang

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo