
把窗体本身或者控件传入这个类(或者做为参数传给这个类的方法),看你的需要了,比如说你在form1里创建的这个类叫myclass,把这个mycalss的构造方法改成
public class myclass
{
form1 frm;
public myclass(form1 frm)
{
thisfrm=frm;
}
}
这样你在form1中创建这个myclass的时候就可以是
myclass mc=new myclass(this);
当然也可以直接传窗体或者控件给类中的方法,比如mycalss中有
public void msg(EditText txt)
或者
public void msg(form1 frm)
其它方法也很多,看你需要了。
new出这个窗体的时候,获取主窗体的坐标,thisLocationX,thisLocationY;
当新窗体show之后,你说可以移动,没问题的,有一个locationChanged事件,这时把新窗体的坐标获取出来就可以了,再和之前主窗体的坐标可以比较了。
首先 你要定义下列的两个函数原形到模块中:
要在模块里定义:
Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function FindWindowa Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
然后在要获取句柄的地方 输入下列代码:
Dim hwnd As Long
Dim str1 As String, len1 As Long
hwnd = FindWindowA("[这个窗口的类名(定义于RegisterClass中)]", "[要获取句柄的标题栏名称]")
str1 = Space(255) '定义接收字串
GetWindowText hwnd, str1, 1024
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
len1 = GetWindowText(hwnd, str1, Len(str1))
If (InStr(1, str1, "API", 1) > 0) Then
Exit Do
End If
Loop
SetWindowText hwnd, "我把API阅读器的标题改变了"
hwnd = GetNextWindow(hwnd, 5) '5表示子窗口
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
GetWindowText hwnd, str1, Len(str1)
SetWindowText hwnd, "我改变了改钮2"
Loop
以上就是关于C#一个普通的类,怎么获取窗体里控件的属性全部的内容,包括:C#一个普通的类,怎么获取窗体里控件的属性、C# 请问如何获取当前窗体(可以拖动)的位置,从而去确定它所调用的窗体之间的相对位置。、如何获取窗体句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)