pb中如何获得当前控件焦点

pb中如何获得当前控件焦点,第1张

GraphicObject which_control

DataWindow ldw_object

which_control = GetFocus()

If TypeOf(which_control) = datawindow! Then

ldw_object = which_control

ldw_objectInsertRow(0)

End If

需要这么两步:

第一,在XML中控件属性中加上以下这么两项属性

Android:focusable="true"

android:focusableInTouchMode="true"

第二,在代码中用调用requestFocus()方法,这样就可以顺利的将焦点主动的设置到该控件上了。

QT控件获得焦点问题高手帮个忙啊,,,主窗口是QWidget 主窗口中有多个 QLineEdit 当点击QLineEdit d出虚拟键盘但是QLineEdit被重写了,, void LineEdit::focusInEvent(QFocusEvent event){

不行吧,因为登陆的话,应该点击登陆按钮,然后焦点就跑到按钮上了,我觉得你应该判断哪个Textbox没有输入或是输入错误,然后提示这个输入错误,再让它获得焦点,没必要像你说的那样吧。我也新手,一起进步~

用Focused属性判断

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

if (textBox1Focused)

{

MessageBoxShow("123");

}

}

UserControl本身是没有输入焦点的,也就是说,激活这类控件不代表有输入焦点,因此Focused肯定是false只有Textbox才有输入焦点你可以覆盖原来的Focused属性,让返回值返回textbox的Focused属性C# codepublicoverrideboolFocused{get{returntextbox1Focused;}}这好像于控件的Focused无关,获得焦点也不会有那个效果如果要想有那个效果的话你可以:private void UserControl1_MouseDown(object sender, MouseEventArgs e){thisBorderStyle = BorderStyleFixedSingle;}然后在失去焦点的时候,你再

给你写一段简单的Demo吧。(窗体中一个timer,两个label)

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Declare Function GetForegroundWindow Lib "user32" () As Long

Private Declare Function GetFocus Lib "user32" () As Long

Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long

Private Type POINTAPI

x As Long

y As Long

End Type

Private Sub Form_Load()

SetWindowPos Mehwnd, -1, 0, 0, 240, 100, conSwpNoActivate Or conSwpShowWindow

End Sub

Private Sub Timer1_Timer()

Dim xy As POINTAPI

Dim ahwnd As Long

GetCursorPos xy

ahwnd = WindowFromPointXY(xyx, xyy)

Label1Caption = "鼠标所在的控件类型:" & ClassName(ahwnd)

Label2Caption = "获得焦点的控件类型:" & ClassName(GetHwnd)

End Sub

Public Function GetHwnd() As Long

Dim hwnd As Long

Dim PID As Long

Dim TID As Long

Dim hWndFocus As Long

hwnd = GetForegroundWindow

If hwnd Then

TID = GetWindowThreadProcessId(hwnd, PID)

AttachThreadInput AppThreadID, TID, True

GetHwnd = GetFocus

AttachThreadInput AppThreadID, TID, False

End If

End Function

Private Function ClassName(nHwnd As Long) As String

Dim str As String

str = Space(255)

GetClassName nHwnd, str, 255

ClassName = str

End Function

自己再扩展下就可以了。

以上就是关于pb中如何获得当前控件焦点全部的内容,包括:pb中如何获得当前控件焦点、如何让一个控件能主动获取到焦点、VC 控件 是否获得焦点等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9288818.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存