⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spin control.txt

📁 VC中的小控件的使用
💻 TXT
字号:
定义spin   button   control的一个Control类型变量m_ctlSpin   
  m_ctlSpin.SetBuddy(GetDlgItem(IDC_EDIT));//IDC_EDIT是你要关联的       
                                //Editbox   
  m_ctlSpin.SetRange(2,100);   
  

ctrl+d,设置tab顺序,edit下一个spin控件与edit绑定在一起。   
初始化时,spin1.setrange(0,100);

首先,要让Spin Control的Tap Order紧跟着Edit Control(就是说,Spin Control的Tap Order是Edit Control的Tap Order加1)。
然后,设置Spin Control的Auto Buddy和Set Buddy Integer属性为True。



ON_NOTIFY(UDN_DELTAPOS,   IDC_SPIN1,   OnDeltaposSpin1)   
  注意要设置*pResult = 1;   
    
  void   CYourDlg::OnDeltaposSpin1(NMHDR*   pNMHDR,   LRESULT*   pResult)     
  {   
  NM_UPDOWN*   pNMUpDown =(NM_UPDOWN*)pNMHDR;   
  //   TODO:   Add   your   control   notification   handler   code   here   
  TCHAR   szText[MAX_INPUT];   
  GetDlgItemText(IDC_EDIT,szText,MAX_INPUT);   
  sprintf(szText,"%.1f",atof(szText)+   0.1   *   pNMUpDown->iDelta);   
  SetDlgItemText(IDC_EDIT,szText);   
  *pResult   =   1;   
  }


 OnLButtonDown函数:
      void CMySpinButtonCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
      {
       // TODO: Add your message handler code here and/or call default
       int nRow;
       int nUpper;
       CMySpinButtonCtrl::GetRange(nRow, nUpper);
        /*
         *判断编辑框中的输入是否合法
        */
        CString strNum;
        CMySpinButtonCtrl::GetBuddy()->GetWindowText(strNum);
        if ( g_IsNumber(strNum) ==FALSE )
        {
         MessageBox("请输入合法的数字");
         return;
        }
        else
        {
         CRect Rect;
         CMySpinButtonCtrl::GetWindowRect (&Rect);
         if( strNum.Find('.') > 0 )
         {
          int nDotpos = strNum.Find('.');
          int nLength = strNum.GetLength();
          strNum = strNum.Left(nDotpos+1);
          int pos  = atoi(strNum);
          if(point.y <((Rect.bottom-Rect.top)/2))
          {
           CMySpinButtonCtrl::SetPos(pos);
          }
          else
          {
           CMySpinButtonCtrl::SetPos(pos + 1);   
          }
         }
         else
         {
          int pos = atoi(strNum);
          CMySpinButtonCtrl::SetPos(pos);
         }
        }
       CSpinButtonCtrl::OnLButtonDown(nFlags, point);
      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -