duilib Ip控件

直接上来贴码

头文件

#ifndef __UIIpAddress_H__
#define __UIIpAddress_H__

#pragma once

namespace DuiLib
{
	class  CIpAddressUI : public CHorizontalLayoutUI
	{
	  public:
		     CIpAddressUI();
		     virtual void Init();
			 virtual void DoInit();
			 virtual void SetPos(RECT rc);
			 virtual CDuiString GetText() const;
			 virtual void DoEvent(TEventUI& event);
			 virtual void SetText(LPCTSTR pstrText);
	  protected:
		    CEditUI *p;
		    CEditUI *p2;
		    CEditUI *p3;
		    CEditUI *p4;
	};
}
#endif // __UIEDIT_H__

源文件132845_AkEm_343244.png

#include "StdAfx.h"
#include "..\stdafx.h"
#include "UIIpAddress.h"
#include <string>
namespace DuiLib
{
	
	CIpAddressUI::CIpAddressUI() 
	{
		 p=NULL;
		 p2=NULL;
		 p3=NULL;
		 p4=NULL;
	}
	void CIpAddressUI::Init()
	{
		 this->SetAttribute(_T("inset"),"1,1,1,1");
		CHorizontalLayoutUI::Init();
		
		//p-
	}
	void CIpAddressUI::DoInit()
	{
	 
	    CHorizontalLayoutUI::DoInit();
		p=new CEditUI();
		int width=this->GetWidth()/3-4;
		p->SetName("p");
		p->SetAttribute("width","20");
		p->SetAttribute("bkcolor","#00000000");
	p->SetAttribute("texttype","integer");//扩展属性 见http://git.oschina.net/Qyerp/DuiLib
		p->SetAttribute("minvalue","0");//扩展属性
		p->SetAttribute("maxvalue","255");//扩展属性
		
		//p->SetPos(rcPos);
		this->Add(p);
		CLabelUI *dot1=new CLabelUI();
		dot1->SetText(".");
		dot1->SetAttribute("padding","1,0,2,0");
		dot1->SetAttribute("width","5");
		this->Add(dot1);

		p2=new CEditUI();
		p2->SetName("p2");
		p2->SetAttribute("width","20");
		p2->SetAttribute("bkcolor","#00000000");
		p2->SetAttribute("texttype","integer");
		p2->SetAttribute("minvalue","0");
		p2->SetAttribute("maxvalue","255");
		this->Add(p2);

		CLabelUI *dot2=new CLabelUI();
		dot2->SetText(".");
		dot2->SetAttribute("padding","1,0,2,0");
		dot2->SetAttribute("width","5");
		this->Add(dot2);

		p3=new CEditUI();
		p3->SetName("p3");
		p3->SetAttribute("width","20");
		p3->SetAttribute("bkcolor","#00000000");
		p3->SetAttribute("texttype","integer");
		p3->SetAttribute("minvalue","0");
		p3->SetAttribute("maxvalue","255");
		this->Add(p3);

		CLabelUI *dot3=new CLabelUI();
		dot3->SetText(".");
		dot3->SetAttribute("padding","1,0,2,0");
		dot3->SetAttribute("width","5");
		
		this->Add(dot3);
		
		p4=new CEditUI();
		p4->SetName("p4");
		p4->SetAttribute("width","20");
		p4->SetAttribute("bkcolor","#00000000");
		p4->SetAttribute("texttype","integer");
		p4->SetAttribute("minvalue","0");
		p4->SetAttribute("maxvalue","255");
		this->Add(p4);
	}
	void CIpAddressUI::SetPos(RECT rc)
	{
	     CHorizontalLayoutUI::SetPos(rc);
		 int width=this->GetWidth()/4-4;
		 char abc[100];
		 _stprintf_s(abc,"%d",width);
		 if(p!=NULL)
		 {
			 RECT rcCtrl = rc;
			 rcCtrl.right=rcCtrl.left+width;
			 p->SetPos(rcCtrl);
			 
			 rcCtrl.left=rcCtrl.right;
			 rcCtrl.right=rcCtrl.left+width;
			 p2->SetPos(rcCtrl);
		
			 rcCtrl.left=rcCtrl.right;
			 rcCtrl.right=rcCtrl.left+width;
			 p3->SetPos(rcCtrl);

			 rcCtrl.left=rcCtrl.right;
			 rcCtrl.right=rcCtrl.left+width;
			 p4->SetPos(rcCtrl);
			 //p3->SetAttribute("width",abc);
			 //p4->SetAttribute("width",abc);/**/
		 }
	}
	CDuiString CIpAddressUI::GetText() const
	{
		//m_sText=p->GetText()+_T(".")+p2->GetText()+p3->GetText()+p4->GetText();
		return m_sText;
	}
	void CIpAddressUI::SetText(LPCTSTR pstrText)
	{
		CHorizontalLayoutUI::SetText(pstrText);
		CDuiString one=pstrText;
		int pot=one.Find(".");
		if(p!=NULL)
		   p->SetText(one.Left(pot));
		one=one.Right(one.GetLength()-pot-1);
		
		pot=one.Find(".");
		if(p2!=NULL)
		   p2->SetText(one.Left(pot));
		one=one.Right(one.GetLength()-pot-1);	

		pot=one.Find(".");
		if(p3!=NULL)
		   p3->SetText(one.Left(pot));
		one=one.Right(one.GetLength()-pot-1);	
		
		//pot=one.Find(".");
		if(p4!=NULL)
		   p4->SetText(one);
		//one=one.Right(one.GetLength()-pot);	

	}
	void CIpAddressUI::DoEvent(TEventUI& e)
	{
		
		//char *pppp=(char*)e.pSender->GetClass();
		if(e.Type==UIEVENT__TEXTCHANGED)
		{
			if(_tcscmp(e.pSender->GetClass(),_T("EditUI"))==0)
			{
				 CDuiString one=p->GetText();
		         CDuiString two=p2->GetText();
				 CDuiString three=p3->GetText();
		         CDuiString f=p4->GetText();
				 CDuiString dot=_T(".");
				 CDuiString fff=one+dot+two+dot+three+dot+f;
				 m_sText=fff.GetData();
			}
		}
		if(e.Type==UIEVENT_KEYDOWN)
		{
			if((e.wParam==VK_TAB||e.wParam==VK_RIGHT))
			{
				if(_tcscmp(e.pSender->GetName(),_T("p"))==0)
				{
					p2->SetFocus();
				}

				if(_tcscmp(e.pSender->GetName(),_T("p2"))==0)
				{
					p3->SetFocus();
				}
				if(_tcscmp(e.pSender->GetName(),_T("p3"))==0)
				{
					p4->SetFocus();
				}
				if(_tcscmp(e.pSender->GetName(),_T("p4"))==0)
				{
					p->SetFocus();
				}
			}
			if(e.wParam==VK_LEFT )
			{
			     if(_tcscmp(e.pSender->GetName(),_T("p"))==0)
				{
					p4->SetFocus();
				}

				if(_tcscmp(e.pSender->GetName(),_T("p2"))==0)
				{
					p->SetFocus();
				}
				if(_tcscmp(e.pSender->GetName(),_T("p3"))==0)
				{
					p2->SetFocus();
				}
				if(_tcscmp(e.pSender->GetName(),_T("p4"))==0)
				{
					p3->SetFocus();
				}
			}
		}
	}
}


转载于:https://my.oschina.net/u/343244/blog/470600

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值