vb中Form位置怎么变的
1,运行Microsoft Visual Basic程序 。
2,选择右边的窗体布局,右键点击 窗体 ,弹出菜单。
3,选择 启动位置 ,可以选择:手工,所有者中心,屏幕中心,Windows缺省。
不能直接通过属性框修改按钮中文本的颜色
根本没有foreColor属性
下边是一个参考方法
首先请把要改的按钮的Style设置为1
在工程中添加以下模块(Module):
Module modExtButton.bas
Option Explicit
'==================================================================
' modExtButton.bas
'
' 本模块可让你改变命令按钮的文本颜色。
' 使用方法:
'
' - 在设计时将文本的Style设为Graphical.
'
' - 随意设定背景色和图象属性.
'
' - 在Form_Load中调用 SetButton :
' SetButton Command1.hWnd, vbBlue
' (你可以任意次的调用该过程甚至不必先调用 RemoveButton.)
'
' - 在Form_Unload中调用 RemoveButton :
' RemoveButton Command1.hWnd
'
'==================================================================
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Declare Function GetProp Lib "user32" Alias "GetPropA" _
(ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" _
(ByVal hWnd As Long, ByVal lpString As String, _
ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias _
"RemovePropA" (ByVal hWnd As Long, _
ByVal lpString As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
'Owner draw constants
Private Const ODT_BUTTON = 4
Private Const ODS_SELECTED = &H1
'Window messages we're using
Private Const WM_DESTROY = &H2
Private Const WM_DRAWITEM = &H2B
Private Type DRAWITEMSTRUCT
CtlType As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hDC As Long
rcItem As RECT
itemData As Long
End Type
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
'Various GDI painting-related functions
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, _
ByVal crColor As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, _
ByVal nBkMode As Long) As Long
Private Const TRANSPARENT = 1
Private Const DT_CENTER = &H1
Public Enum TextVAligns
DT_VCENTER = &H4
DT_BOTTOM = &H8
End Enum
Private Const DT_SINGLELINE = &H20
Private Sub DrawButton(ByVal hWnd As Long, ByVal hDC As Long, _
rct As RECT, ByVal nState As Long)
Dim s As String
Dim va As TextVAligns
va = GetProp(hWnd, "VBTVAlign")
'Prepare DC for drawing
SetBkMode hDC, TRANSPARENT
SetTextColor hDC, GetProp(hWnd, "VBTForeColor")
'Prepare a text buffer
s = String$(255, 0)
'What should we print on the button?
GetWindowText hWnd, s, 255
'Trim off nulls
s = Left$(s, InStr(s, Chr$(0)) - 1)
If va = DT_BOTTOM Then
'Adjust specially for VB's CommandButton control
rct.Bottom = rct.Bottom - 4
End If
If (nState And ODS_SELECTED) = ODS_SELECTED Then
'Button is in down state - offset
'the text
rct.Left = rct.Left + 1
rct.Right = rct.Right + 1
rct.Bottom = rct.Bottom + 1
rct.Top = rct.Top + 1
End If
DrawText hDC, s, Len(s), rct, DT_CENTER Or DT_SINGLELINE _
Or va
End Sub
Public Function ExtButtonProc(ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim lOldProc As Long
Dim di As DRAWITEMSTRUCT
lOldProc = GetProp(hWnd, "ExtBtnProc")
ExtButtonProc = CallWindowProc(lOldProc, hWnd, wMsg, wParam, lParam)
If wMsg = WM_DRAWITEM Then
CopyMemory di, ByVal lParam, Len(di)
If di.CtlType = ODT_BUTTON Then
If GetProp(di.hwndItem, "VBTCustom") = 1 Then
DrawButton di.hwndItem, di.hDC, di.rcItem, _
di.itemState
End If
End If
ElseIf wMsg = WM_DESTROY Then
ExtButtonUnSubclass hWnd
End If
End Function
Public Sub ExtButtonSubclass(hWndForm As Long)
Dim l As Long
l = GetProp(hWndForm, "ExtBtnProc")
If l 0 Then
'Already subclassed
Exit Sub
End If
SetProp hWndForm, "ExtBtnProc", _
GetWindowLong(hWndForm, GWL_WNDPROC)
SetWindowLong hWndForm, GWL_WNDPROC, AddressOf ExtButtonProc
End Sub
Public Sub ExtButtonUnSubclass(hWndForm As Long)
Dim l As Long
l = GetProp(hWndForm, "ExtBtnProc")
If l = 0 Then
'Isn't subclassed
Exit Sub
End If
SetWindowLong hWndForm, GWL_WNDPROC, l
RemoveProp hWndForm, "ExtBtnProc"
End Sub
Public Sub SetButton(ByVal hWnd As Long, _
ByVal lForeColor As Long, _
Optional ByVal VAlign As TextVAligns = DT_VCENTER)
Dim hWndParent As Long
hWndParent = GetParent(hWnd)
If GetProp(hWndParent, "ExtBtnProc") = 0 Then
ExtButtonSubclass hWndParent
End If
SetProp hWnd, "VBTCustom", 1
SetProp hWnd, "VBTForeColor", lForeColor
SetProp hWnd, "VBTVAlign", VAlign
End Sub
Public Sub RemoveButton(ByVal hWnd As Long)
RemoveProp hWnd, "VBTCustom"
RemoveProp hWnd, "VBTForeColor"
RemoveProp hWnd, "VBTVAlign"
End Sub
然后回到FORM中:
添加CommandButton,不必更改它们的名称,将它们的Style设为Graphical,给第3个按钮设置一幅图片。
CommandButton也可以放置在一个容器如PictureBox或Frame中,模块会判断,如果需要的话将CommandButton的容器也子类化。
在Form中的代码:
Private Sub Form_Load()
'Initialize each button color.
SetButton Command1.hWnd, vbRed
SetButton Command2.hWnd, &H8000& '深绿色
'Assign this one a DT_BOTTOM alignment because
SetButton Command3.hWnd, vbBlue, DT_BOTTOM '含有图片,将文本放置在按钮底部
SetButton Command4.hWnd, &H8080& '暗棕黄色
End Sub
Private Sub Form_Unload(Cancel As Integer)
'手动解除按钮的子类化
'这并不是必须的
RemoveButton Command1.hWnd
RemoveButton Command2.hWnd
RemoveButton Command3.hWnd
RemoveButton Command4.hWnd
End Sub
For m = 0 To 9
SetButton CmdNum(m).hWnd, vbBlue
Next
For n = 1 To 4
SetButton CmdCal(n).hWnd, vbRed
Next
For l = 2 To 4
SetButton CmdOth(l).hWnd, vbRed
Next
有,我们还可以使用Screen对象来控制窗口在屏幕上的位置,比如我们要设置窗口出现在屏幕的正中央,就可以使用语句form1.width=screen.width/2,form1.height=screen.height/2来实现,其中width属性返回整个屏幕的宽度,height属性返回整个屏幕的高度,它的好处就是可以根据数值来调整窗体,便于控制。
可能中毒了,杀毒吧.或者关机重启看看.
vb.net如何在form1中显示文字?
完善下上边仁兄的!!!Public Class Form1 '注意下边的事件是Paint,而不是Load!!Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim A As String = "文字"Dim B As Font B = New Font("simson", 30, FontStyle....
...A ,A中有一个按钮Btn, 单击 Btn 调用窗体B, 现在想做的是 关闭窗体...
关闭子窗体B的时候返回一个值给父窗体A,A接受到这个值就close,参考代码如下:A窗体btn的单击事件:private void Btn_Click(object sender, EventArgs e){ Form1 formB = new Form1();formB.ShowDialog();if (formB.DialogResult == DialogResult.Cancel){ this.Close();} } ...
form a和form b的区别
情况良好 shield form 与 keep form separate form 的区别? 先说separate A from B吧,这个有把一些东西从另一些东西中分开的含义,侧重于分开,区分,分离,意味着AB原来在一起,现在要把他们分开.例如:The single most important factor that separates ordinary photographs from good photographs is the...
jsp中有两个form,怎样在一个form中取另外一个form中的值
var oID=document.getElementById("id").value;\/\/拿到A_form中的id值 var oHID=document.getElementById("hid");\/\/拿到B_form中的隐藏域对象 oHID.value=oID;\/\/为隐藏域对象的value赋值 } <\/script><form action="" method="post" name="A_form"> ID:<input name="id" type="text" id="id" ...
form怎么读
Aftersixmonthstraining,thewholeteamisinsuperbform.全队经过六个月的训练竞技状态极佳。Judgingbyrecentform,heshouldeasilypasstheexam.从他最近的表现来看,他应该很容易考及格。What'stheformwhenyouapplyforaresearchgrant?申请科研补助金按常规应该怎么办?Aplanbegantoforminhishead.一项计划在他脑子中形成。Icannot...
什么是“副歌”?,怎么判断一首歌的副歌位置?
主歌可以说是内容,是每首音乐的主干。而 音乐的结构是有一特定型式的,此结构型式在乐理上称之为 Form。一般的歌曲 大多作 AA'BA' Form。A 代表主歌,而 B 段是副歌。亦即是说,通常一首歌的 构造就是由前奏,两段主歌,一段副歌,过门音乐,再来一次的副歌和主歌, 以及结尾音乐顺序地连接而...
什么叫副歌部分
一般的歌曲 大多作 AA'BA' Form。A 代表主歌,而 B 段是副歌。 就是说,通常一首歌的结构就是由前奏,两段主歌,一段副歌,过门音乐,再来一次的副歌和主歌, 以及结尾音乐顺序地连接而成的。 在很多歌曲中,副歌部分经常作一个感情的升华,是全词的画龙点睛之处。抒情的成分居多,概括性很强。 而副歌之...
form b是什么产地证?
Form B产地证是指出口商品需要提供的一种证明,用于证明该商品原产自中国境内。它是国际贸易中的重要文件,也是进口国海关对商品原产地的认定依据之一。Form B产地证是出口企业向所在地工商行政管理部门申请,由工商行政管理部门核发的一种证明文件。该证明文件主要用于向进口国海关证明出口商品的原产地为...
FORM B CO中origin criterion 项下的标准A、B...代表什么?
根据《亚太贸易协定》原产地规则第二条的规定,受惠产品必须是完全原产自出口成员国,若非出口成员国完全原产的产品,必须符合第三条或第四条。 1、完全原产品:在第8栏填写字母“A” 2、含有进口成份的产品:第八栏的填写方法如下: (1)符合第三条规定的原产地标准的产品,第8栏填写字母“B”...
form B (normally closed) contacts的英文缩写B是什么意思?
B,作为“form B (normally closed) contacts”的缩写,直译为“B型(常闭)触点”。这个英文术语在电子学领域中广泛应用,特别是在描述电路连接和开关操作时。它表示触点在正常情况下是闭合的,即未接通电源或信号。中文拼音为“xíng cháng bì chù diǎn”,B作为一个学术科学领域的缩写词,尤其在...
倚元儿康: 1,运行Microsoft Visual Basic程序 .2,选择右边的窗体布局,右键点击 窗体 ,弹出菜单.3,选择 启动位置 ,可以选择:手工,所有者中心,屏幕中心,Windows缺省.
西峰区17850135197: VB中怎么调整 Form的先后顺序 - ?
倚元儿康: 不太明白,因为单击任何窗体,该窗体就可以显示到前面来 当然也可以通过模式窗体位于XX窗体前 如在 Form1中使用 Form2.show vbModal,me 那么Form2会一直在Form1前,除非Form2关闭,否则无法切换到Form1 或者使用SetWindowsPos的API函数,可以设置窗体前后的排列顺序
西峰区17850135197: VB如何设置弹出窗口的位置? - ?
倚元儿康: 在程序里设置. form1.show form1.left=screen.width - form1.width form1.top = screen.height - form1.height
西峰区17850135197: vb form出现的先后顺序 - ?
倚元儿康: 按钮时在form1 上的 ? 窗体出现的代码是 form3.show 如果你在form3上加一个按钮,单击 form2.show 这样就可以了啊,如果是同时的,那么VB中代码的执行是从上至下的,在前面的代码会先执行,比如你写 form3.show form2.show 那么会先出现form3 然后出现form2 但是程序运行速度很快 你是看不出来的
西峰区17850135197: vb 一个简单的问题 form的位置 - ?
倚元儿康: Me.Top = 0 Me.Left = Screen.Width / 2 - Me.Width / 2
西峰区17850135197: vb中如何改变窗体的显示位置 - ?
倚元儿康: 你是想在运行中改变?还是要改变第一次加载时的位置?如果是第一种情况得...
西峰区17850135197: vb中如何更改窗体的位置 - ?
倚元儿康: Private Sub Form_Load() Me.Left = Screen.Width - Me.Width Me.Top = Screen.Height - Me.Height End Sub
西峰区17850135197: VB中如何让控件的位置随窗体大小变化而改变??
倚元儿康: Form有一个Resize事件 Private Sub Form_Resize()…… End Sub 里面添加窗体大小变化的时候控件的变化就行了. 当然,对于应该如何变化,就得自己先算好咯.
西峰区17850135197: 如何将VB程序中的标题栏“form1”任意更改?? - ?
倚元儿康: form1.caption="你需要改什么就改什么" 在窗口属性里也可以改
西峰区17850135197: VB.NET里怎么控制Form的位置 - ?
倚元儿康: 试过了~~这样行啊 但是不能分开设置 Location.X 和Location.Y 那是只读属性 一定要只设置为 .Location=New Point(0,0) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dd As ...