首页 > 编程 > .NET > 正文

走近VB.Net(一),VB中的族,类,对象(摘录部分MSDN)

2024-07-10 13:01:18
字体:
来源:转载
供稿:网友
走近vb.net(一),vb中的族,类,对象
vb.net是面向对象(object-oriented)的,又称为物件(object)导向(oriented)。在vb.net中所有的变量类型都是基于object,而不是variantdim x as variant 会被升级为 dim as object。如果你不理解对象,暂时你可以把他理解为一段数据,他是实际存在于内存的,所以对象以称为实例(instance)而类(class)就是类别,他定义一群对象,是一个对象的群体,并定义方法成员。所以类只是一个定义,只有在被声明为实例的对象(object instance)时才能具体 的调用。 你在调用其他的类成员时,弹出错误的对话框要求“object instace”,是因为没有声明一个实例的对象,你用类似声明变量的方法声明他们。如:dim formn as new form2 调用form2的成员方法new建立了一个对象的实例。你添加了一个窗体而并不能在程序中显示出来,是作为一个类,它并不实际存在。而现在使用formn.visible=true 就可以象以前一样调用,所以条条大路通北京。只是一个概念的转变,vb在幕后还是以前的vb。这个可能有人会反驳我反vb的变量称为对象,如果你把变量作为一个指针,不如把他看作一个变量 如:dim s as string :dim in as integer :in=123:s=in.tostring(注意vb用“:” 示换行)。in是一个变量,在基于integer的类中已定义了tostring的方法。在现在的vb中所有的方法都以这种方式内嵌于不同的类。甚至包括所有的api。虽然vb仍然支持象以前一样地使用api,除了常用的32位数据类型long应被换为integer(msdn中称32位是最快的 )。你会感觉不方便,甚至不能达到目的。这是因为vb.net认为你不可能再使用api,而只有形式上的支持。
在vb.net中引入了“族”的的术语,即namespace,一般译为名称空间,思考了几个小时,我个人认为在net中应该译为族比较合适,名字的集合示意在于对象的空间,族适用于任何对象的空间,在万事万物皆比族而分,在人亦如此。故有“非我族类,其心必异” 之语。族不离类,类不离族,族居类之上。大家可以斟酌一下,看是不是有些道理。
在vb.net中把父类定义为族 ,已定义的族有很多,如system是最常用的族,system中包含的类几乎包容了系统的方方面面,而system较常用的子族有winforms(窗体),drawing(图形). 待定义的如一个工程,新建一个工程,工程名就是族名。
因为winforms.form类,drawing.bitmap类是最常用的,而vs7中查找的速度实在太慢,我把他摘录在下面:当然如果你的英文很好,可以到msdn中去查找,因为是集成的ide,如果谁能把vb的帮助整理出来就好了,我对运用成员的方法作了一些初步的探索,我希望有英文好一点的把下面的一段英文译出来,如果这样的话,任何一个初学者,即使不懂英文,看了我的系列文章。对照下面的winforms.form成员表,drawing.bitmap成员表,能力强的一定可以在几天的内初步掌握vb.net。.新建一个工程,默认的就会有对winforms.form与 drawing.bitmap的声明。这个也是实现windows的图形界面的最重要的图径。


一。system.winforms.form 的成员(form members)

[注:
1.凡注明“to be supplied”是msdn准备在将来提供的空的文档(大部分文档都是空缺的),所以没有翻译
2.我只能翻译一些常用项目,不是我懒,我没有任何中文的参考,如果弄错了就不太好
3.凡注明“instance”的是要求对象实例,在拙作《vb.net问题集》有详细的解释
4.其他如共享定义,基本语法等在我的系列文章中有详细的介绍,这是就不必要重复了
.................]

(一)。静态共享的属性[public static (shared) properties]

activeform:返回当前的活动窗体( gets the currently active form for this application.)

(二)。对象构造器(public instance constructors)

form constructor:初始化一个新的实例( initializes a new instance of the form class.)

(三)。公用的对象(实例)属性(public instance properties)

acceptbutton: indicates the button control on the form that when clicked, performs an action equivalent to when the user presses the enter key.

accessibilityobject: (inherited from richcontrol) [to be supplied.]

accessibledefaultactiondescription: (inherited from richcontrol) the default action description of the control

accessibledescription: (inherited from richcontrol) the accessible description of the control

accessiblename: (inherited from richcontrol) the accessible name of the control

accessiblerole: (inherited from richcontrol) the accessible role of the control

activecontrol: (inherited from containercontrol) indicates the active control on the container control.

activemdichild: gets the active multiple document interface (mdi) child window.

allowdrop: (inherited from richcontrol) the allowdrop property. if allowdrop is set to true then this control will allow drag and drop operations and events to be used.

allowtransparency: (inherited from richcontrol) [to be supplied.]

anchor: (inherited from richcontrol) the current value of the anchor property. the anchor property determines which edges of the control are anchored to the container's edges.

autoscale: gets or sets a value indicating whether the form adjusts its size and scale its control to fit the height of the font used on the form.

autoscroll: gets or sets a value indicating whether the form implements autoscrolling.

autoscrollmargin: (inherited from scrollablecontrol) gets or sets the size of the auto-scroll margin.

autoscrollminsize: (inherited from scrollablecontrol) gets or sets the mimimum size of the auto-scroll.

autoscrollposition: (inherited from scrollablecontrol) gets or sets the location of the auto-scroll position.

backcolor: the background color of this control. this is an ambient property and will always return a non-null value.
backcolor设置窗体的背景色。

backgroundimage: (inherited from richcontrol) the background image of the control.
backgroundimage设置窗体的背景图片

bindingmanager: (inherited from richcontrol) [to be supplied.]

bindings: (inherited from richcontrol) retrieves the bindings for this control.

borderstyle: gets or sets the border style of the form.
borderstyle设置窗体的外观(边框,标题栏)

bottom: (inherited from control) the bottom coordinate of this control.

bounds: (inherited from control) the bounds of this control. this is the window coordinates of the control in parent client coordinates.

cancelbutton: gets or sets the button control that when clicked, performs an action equivalent to when the user presses the esc key.这个是设定哪一个button按钮响应esc键

canfocus: (inherited from control) indicates whether the control can receive focus. this property is read-only. 指定控件是否可以接受焦点,read-only表示他是只读的。不能在运行期间修改。

canselect: (inherited from control) indicates whether the control can be selected. this property is read-only.
指定控件是否可以被选定,read-only表示他是只读的。不能在运行期间修改。

capture: (inherited from control) indicates whether the control has captured the mouse.

这个返回一个布尔值,指定是否捕获鼠标。通常我们要移动一个无标题栏的窗体,需要在按下鼠标的时候放鼠标捕获

如:me.capture=false. 他的作用跟vb6的api 函数---releasecapture 。不过用起来方便得多

causesvalidation: (inherited from control) indicates whether entering the control causes validation on the controls requiring validation.

clientrectangle: (inherited from control) the client rect of the control.
用户界面属性

clientsize: gets or sets the size of the client area of the form.
用户界面尺寸

companyname: (inherited from richcontrol) retrieves the company name of this specific component.

containsfocus: (inherited from control) indicates whether the control or one of its children currently has the system focus. this property is read-only.

contextmenu: (inherited from richcontrol) the contextmenu associated with this control. the contextmenu will be shown when the user right clicks the mouse on the control.
指定在右键弹击时弹出那一个菜单,一般可以在属性窗口的下拉列表中选定

controlbox: gets or sets a value indicating whether a control box is displayed in the title bar of the form.

controls: (inherited from control) collection of child controls.

created: (inherited from control) indicates whether the control has been created. this property is read-only.

cursor: (inherited from richcontrol) retrieves the cursor that will be displayed when the mouse is over this
control. 自定义光标。

定义当鼠标在控件上方的光标样式

desktopbounds: gets or sets the size and location of the form on the windows desktop.
返回或设置窗体在桌面的范围

desktoplocation: gets or sets the location of the form on the windows desktop.
返回或设置窗体在桌面的位置

dialogresult: gets or sets the dialog result for the form.

displayrectangle: (inherited from control) returns the client rect of the display area of the control. for the base control class, this is identical to getclientrect. however, inheriting controls may want to change this if their client area differs from their display area.
窗体显示区块

disposed: (inherited from control) indicates whether the control has been disposed. this property is read-only.是否这个控件已被清除


disposing: (inherited from control) indicates whether the control is in the process of being disposed. this property is read-only.

dock: (inherited from richcontrol) the dock property. the dock property controls to which edge of the container this control is docked to. for example, when docked to the top of the container, the control will be displayed flush at the top of the container, extending the length of the container.

dockpadding: (inherited from scrollablecontrol) gets the dock padding settings for all edges of the control.

enabled: (inherited from control) indicates whether the control is currently enabled.

focused: (inherited from control) indicates whether the control has focus. this property is read-only.
窗体是否已失去焦点

font: (inherited from richcontrol) retrieves the current font for this control. this will be the font used by default for painting and text in the control.
字体

forecolor: (inherited from richcontrol) the foreground color of the control.
前景色(字体颜色)

handle: (inherited from control) the hwnd handle that this control is bound to. if the handle has not yet been created, this will force handle creation.

handle 返回控件的句柄

height: (inherited from control) the height of this control
窗体高度

helpbutton: gets or sets a value indicating whether a help button is displayed in the title bar of the form.

icon gets or sets the icon for the form.

imemode: (inherited from richcontrol) specifies a value that determines the ime (input method editor) status of the object when that object is selected.
指定一个控件被用户选定时默认活动的输入法

invokerequired: (inherited from richcontrol) [to be supplied.]

isaccessible: (inherited from richcontrol) indicates whether or not this control is an accessible control i.e. whether it should be visible to accessibility applications.

ishandlecreated: (inherited from control) whether or not this control has a handle associated with it.

ismdichild: gets a value indicating whether the form is a multiple document interface (mdi) child form.

ismdicontainer: gets or sets a value indicating whether the form is a container for multiple document interface (mdi) child forms.

keypreview: gets or sets a value indicating whether the form receives key events before the event is passed to the control that has focus.这个与vb6的样,返回或设置一个值,指定是否在控件键盘事件发生前执行窗体的键盘事件

left: (inherited from control) the left coordinate of this control.

控件左边的坐标距离

location: (inherited from control) the location of this control.
位置

maximizebox: gets or sets a value indicating whether the maximize button is displayed in the title bar of the form.

mdichildren: gets an array of forms that represent the multiple document interface (mdi) child forms that are parented by this form.

mdiparent: indicates the multiple document interface (mdi) parent form of this form.

menu: gets or sets the mainmenu that is displayed in the form.
设置窗体使用哪一个主菜单

mergedmenu gets the merged menu for the form.

minimizebox gets or sets a value indicating whether the minimize button is displayed in the title bar of the form.

modal gets a value indicating whether this form is displayed modally.
是否一个窗体是模态窗体。

opacity: (inherited from richcontrol) [to be supplied.]

opacity的作用不小,设置窗体的透明程度,如me.opacity=0.68

ownedforms gets an array of form objects that represents all forms that are owned by this form.

owner gets or sets the form that owns this form.

parent (inherited from control) the parent of this control.

parentform the form that is the parent of this form.

productname (inherited from richcontrol) retrieves the product name of this specific component.

productversion (inherited from richcontrol) retrieves the product version of this specific component.

recreatinghandle (inherited from control) indicates whether the control is currently recreating its handle. this property is read-only.

region (inherited from richcontrol) the region associated with this control. (defines the outline/silhouette/boundary of control)

region 是构造窗体的外观了,这在我的文章《走近vb.net(十一)随心所欲窗体外观中》有具体的用法

right (inherited from control) the right coordinate of the control.
窗体右坐标

righttoleft (inherited from richcontrol) this is used for international applications where the language is written from righttoleft. when this property is true, control placement and text will be from right to left.

showfocuscues (inherited from control) indicates whether the user interface is in a state to show or hide focus rectangles. this property is read-only.

showintaskbar indicates whether a form is displayed in the windows taskbar.
设置是否显示在windows的任务栏

showkeyboardcues (inherited from control) indicates whether the user interface is in a state to show or hide keyboard accelerators. this property is read-only.

site (inherited from marshalbyrefcomponent) gets or sets the site of the component.

size gets or sets the size of the form.

sizegripstyle gets or sets the style of sizing handle to display in the lower-right corner of the form.

startposition gets or sets the initial position of the form at run time.
返回或设置窗体启动时的位置

tabindex (inherited from control) the tab index of this control.
tab键的排序

tabstop (inherited from control) indicates whether the user can give the focus to this control using the tab key. this property is read-only.
是否接受tab键的焦点,这也是一个只读属性

text (inherited from control) the current text associated with this control.
所显示的文本内容

top (inherited from control) top coordinate of this control
顶点坐标.

toplevel gets or sets a value indicating whether to display the form as a top-level window.

toplevelcontrol (inherited from control) the top level control that contains this control. this doesn't have to be the same as the value returned from getform since forms can be parented to other controls.

topmost gets or sets a value indicating whether the form is displayed as the top-most form of your application.
topmost定义是否使一个窗体是否始终在最前面显示

transparencykey gets or sets the color that represents transparent areas on the form.

visible gets or sets a value indicating whether the form is visible.
返回或设置一个控件是否可见。

width (inherited from control) the width of this control.
控件的宽度

windowstate gets or sets the form's window state.
返回或设置窗体当前状态

(四)公用的对象(实例)方法(public instance methods)

activate activates the form and gives it focus.
激活窗体

activatecontrol (inherited from containercontrol) activates a specified control.
激活指定的控件

addownedform adds an owned form to this form.

begininvoke (inherited from richcontrol) overloaded. [to be supplied.]

bringtofront (inherited from control) brings this control to the front of the zorder.

callwndproc (inherited from control) dispatch the method to this window's wndproc directly.

close closes the form.
关闭这个窗体

contains (inherited from control) verifies if a control is a child of this control.

createcontrol (inherited from control) forces the creation of the control. this includes the creation of the handle, and any child controls.

creategraphics (inherited from richcontrol) overloaded. [to be supplied.]


dispose (inherited from containercontrol) disposes of the resources (other than memory) used by the containercontrol.释放占用的资源

dodragdrop (inherited from richcontrol) begins a drag operation. the allowedeffects determine which drag operations can occur. if the drag operation needs to interop with applications in another process, data should either be a base managed class (string, bitmap, or metafile) or some object that implements system.componentmodel.ipersistable. data can also be any object that implements system.winforms.idataobject.

endinvoke (inherited from richcontrol) retrieves the return value of the asynchronous operation represented by the iasyncresult interface passed. if the async operation has not been completed, this function will block until the result is available.

equals (inherited from object) determines whether the specified object is the same instance as the current object.

findform (inherited from richcontrol) retrieves the form that this control is on. the control's parent may not be the same as the form.

focus (inherited from control) sets focus to the control. attempts to set focus to this control.

设置控件的焦点,不要告诉我知道!

getchildatpoint (inherited from control) retrieves the child control that is located at the specified client coordinates.

getcontainer (inherited from marshalbyrefcomponent) gets the container for the component.

getcontainercontrol (inherited from control) returns the closest containercontrol in the control's chain of parent controls and forms.

getdesignmode (inherited from marshalbyrefcomponent) gets a value indicating whether the component is currently in design mode.

gethashcode (inherited from object) serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

getlifetimeservice (inherited from marshalbyrefobject) this method is used return a lifetime service object that is used to control the lifetime policy to the object. for the default lifetime service this will be an object of type ilease.

getnextcontrol (inherited from control) retrieves the next control in the tab order of child controls.

getserviceobject (inherited from marshalbyrefcomponent) gets the implementer of the iserviceobjectprovider.

gettype (inherited from object) gets the type of the object.
返回一对象的类

hide (inherited from control) hides the control by setting the visible property to false;
隐藏一控件

initializelifetimeservice (inherited from marshalbyrefobject) object can provide their own lease and so control their own lifetime. they do this by overriding the initializelifetimeservice method provided on marshalbyrefobject

invalidate (inherited from control) overloaded. [to be supplied.]

invoke (inherited from richcontrol) overloaded. [to be supplied.]

layoutmdi arranges the multiple document interface (mdi) child forms of this form.

performlayout (inherited from control) overloaded. [to be supplied.]

pointtoclient gets the client coordinates for a specified location.
返回一个用户界面的坐标

pointtoscreen gets the screen coordinates for a specified location.

返回一个屏幕坐标

preprocessmessage (inherited from control) called by the application's message loop to pre-process input messages before they are dispatched.

rectangletoclient gets the client coordinates and size of a specified rectangle.
返回一个矩形的用户界面坐标

rectangletoscreen gets the client coordinates and size for a specified rectangle.
返回一个一个矩形的屏幕坐标

refresh (inherited from control) forces the control to invalidate and immediately repaint itself and any children. 重画窗体

removeownedform removes a form from the list of owned forms. also sets the owner of the removed form to a null reference (in visual basic nothing).

resetbackcolor (inherited from richcontrol) resets the back color to be based on the parent's back color.

resetbindings (inherited from richcontrol) [to be supplied.]

resetcursor (inherited from richcontrol) [to be supplied.]

resetfont (inherited from richcontrol) resets the font to be based on the parent's font.

resetforecolor (inherited from richcontrol) resets the fore color to be based on the parent's fore color.

resetrighttoleft (inherited from richcontrol) resets the righttoleft to be the default.

resettext (inherited from control) resets the text to it's default value.

resumelayout (inherited from control) overloaded. resumes normal layout logic.

scale (inherited from control) overloaded. scales the control and any child controls.

select (inherited from control) activates this control.

selectnextcontrol (inherited from control) selects the next control following ctl.

sendmessage (inherited from control) overloaded. sends a win32 message to the control.

sendtoback (inherited from control) sends this control to the back of the z-order

setautoscrollmargin (inherited from scrollablecontrol) sets the size of the auto-scroll margins.

setbounds (inherited from control) overloaded. sets the bounds of the control.

setclientsize (inherited from control) sets the height and width of the client area of the control.

setdesktopbounds sets the bounds of the form in desktop coordinates.

setdesktoplocation sets the location of the form in desktop coordinates.

setlocation (inherited from control) sets the location of this control.

setnewcontrols arranges an array of controls on a form.

setsize (inherited from control) sets the size of this control.

shouldpersistautoscrollmargin (inherited from scrollablecontrol) indicates whether the autoscrollmargin property should be persisted.

shouldpersistautoscrollminsize (inherited from scrollablecontrol) indicates whether the autoscrollminsize property should be persisted.

shouldpersistautoscrollposition (inherited from scrollablecontrol) indicates whether the autoscrollposition property should be persisted.

shouldpersistbackcolor indicates whether the backcolor property should be persisted.

shouldpersistbindings (inherited from richcontrol) [to be supplied.]

shouldpersistcursor (inherited from richcontrol) returns true if the cursor should be persisted in code gen.

shouldpersistfont (inherited from richcontrol) returns true if the font should be persisted in code gen.

shouldpersistforecolor indicates whether the forecolor property should be persisted.

shouldpersisticon indicates whether the icon property should be persisted.

shouldpersistlocation (inherited from control) determines if the location property needs to be persisted.

shouldpersistrighttoleft (inherited from richcontrol) returns true if the righttoleft should be persisted in code gen.

shouldpersistsize (inherited from control) determines if the size property needs to be persisted.

shouldpersisttext (inherited from control) determines if the text property needs to be persisted.

shouldpersisttransparencykey indicates whether the transparencykey property should be persisted.

show (inherited from control) makes the control display by setting the visible property to true

showdialog overloaded. displays this form as a modal dialog box.

suspendlayout (inherited from control) suspends the layout logic for the control.

tostring (inherited from object) returns a string that represents the current object.

update (inherited from control) forces the control to paint any currently invalid areas.

validate (inherited from containercontrol) validates the last unvalidated control and it's ancestors up through, but not including, the current control.

(五)公用的对象(实例)事件(public instance events):

千万不要跟我说不懂什么是事件(用户操作,如单击-click,鼠标离开mouseleave,请参考vb6 资料)

不过象mouseleave以前是没有的,还有参数也不同,我的相关文章写得很清楚,这一节就跳过

activated occurs when the form is activated in code or by the user.

changeuicues (inherited from control) occurs when focus or keyboard or both cues have changed.

click (inherited from control) occurs when the control is clicked.

closed occurs when the form is closed.

closing occurs when the form is closing.

controladded (inherited from control) occurs when a new control is added.

controlremoved (inherited from control) occurs when a control is removed.

deactivate occurs when the form loses focus and is not the active form.

doubleclick (inherited from control) occurs when the control is double clicked.

dragdrop (inherited from richcontrol) [to be supplied.]

dragenter (inherited from richcontrol) [to be supplied.]

dragleave (inherited from richcontrol) [to be supplied.]

dragover (inherited from richcontrol) [to be supplied.]

enter (inherited from control) occurs when the control is entered.

givefeedback (inherited from richcontrol) [to be supplied.]

gotfocus (inherited from control) occurs when the control receives focus.

handlecreated (inherited from control) occurs when a handle is created for the control.

handledestroyed (inherited from control) occurs when the control's handle is destroyed.

helprequested (inherited from richcontrol) [to be supplied.]

inputlangchange occurs after the input language of the form has changed.

inputlangchangerequest occurs when the the user attempts to change the input language for the form.

invalidated (inherited from richcontrol) [to be supplied.]

keydown (inherited from control) occurs when a key is pressed down while the control has focus.

keypress (inherited from control) occurs when a key is pressed while the control has focus.

keyup (inherited from control) occurs when a key is released while the control has focus.

layout (inherited from control) occurs when a control's layout properties have been changed.

leave (inherited from control) occurs when the control is left.

lostfocus (inherited from control) occurs when the control loses focus.

mdichildactivate occurs when a multiple document interface (mdi) child form is activated or closed within an mdi application.

menucomplete occurs when a menu in a form loses focus.

menustart occurs when a menu in a form receives focus.

mousedown (inherited from control) occurs when the mouse pointer is over the control and a mouse button is pressed.

mouseenter (inherited from control) occurs when the mouse pointer enters the control.

mousehover (inherited from control) occurs when the mouse pointer hovers over the contro.

mouseleave (inherited from control) occurs when the mouse pointer leaves the control.

mousemove (inherited from control) occurs when the mouse pointer is moved over the control.

mouseup (inherited from control) occurs when the mouse pointer is over the control and a mouse button is released.

mousewheel (inherited from control) occurs when the mouse wheel moves while the control has focus.

move (inherited from control) occurs when the control is moved.

paint (inherited from richcontrol) [to be supplied.]

propertychanged (inherited from control) occurs when a property of the control has changed.

queryaccessibilityhelp (inherited from richcontrol) [to be supplied.]

querycontinuedrag (inherited from richcontrol) [to be supplied.]

resize (inherited from control) occurs when the control is resized.

validated (inherited from control) occurs when the control is done validating.

validating (inherited from control) occurs when the control is validating.

(六)族内共享属性(protected instance properties)

简单的说一个大类包括两个小类,这个大类就是一个族,小类就是成员了。

canraiseevents (inherited from richcontrol) [to be supplied.]

createparams (inherited from richcontrol) returns the createparams used to create the handle for this control. inheriting classes should call base.createparams in the manor below:

events (inherited from marshalbyrefcomponent) gets the list of event handlers that are attached to this component.

fontheight (inherited from richcontrol) [to be supplied.]

hscroll (inherited from scrollablecontrol) gets or sets a value indicating whether the horizontal scroll bar is visible.

internalhandle (inherited from control) returns the current value of the handle. this may be zero if the handle has not been created.

maximizedbounds gets the size of the form when it is maximized.

maxtracksize gets the maximum size to which the form can be resized.

mintracksize gets the minimum size the form can be resized to.

renderrighttoleft (inherited from richcontrol) [to be supplied.]

vscroll (inherited from scrollablecontrol) gets or sets a value indicating whether the vertical scroll bar is visible.

windowtext (inherited from control) indicates the current text of the window.

族内共享的对象(实例)属性(protected instance methods)

adjustformscrollbars (inherited from scrollablecontrol) adjusts the auto-scroll bars on the container based on the current control positions and the control currently selected.

assignparent (inherited from richcontrol) assigns a new parent control. sends out the appropriate property change notifications for properties that are affected by the change of parent.

createaccessibilityinstance (inherited from richcontrol) constructs the new instance of the accessibility object for this control. subclasses should not call base.createaccessibilityobject.

createcontrolsinstance (inherited from richcontrol) constructs the new instance of the controls collection objects. subclasses should not call base.createcontrolsinstance.

createhandle (inherited from control) creates a handle for this control. this method is called by the .net framework, this should not be called. inheriting classes should always call base.createhandle when overriding this method.

defwndproc (inherited from control) sends the message to the default window proc.

destroyhandle (inherited from richcontrol) [to be supplied.]

finalize (inherited from object) allows an object to attempt to free resources and perform other cleanup operations before the object is reclaimed by the garbage collector (gc). this method may be ignored by the common language runtime; therefore, necessary cleanup operations should be done elsewhere.

getstyle (inherited from control) retrieves the current value of the specified bit in the control's style. note: this is control style, not the win32 style of the hwnd.

initlayout (inherited from richcontrol) called after the control has been added to another container.

invokegotfocus (inherited from control) raises the gotfocus event.

invokelostfocus (inherited from control) raises the lostfocus event.

invokeonclick (inherited from control) raises the click event.

invokepaint (inherited from richcontrol) [to be supplied.]

invokepaintbackground (inherited from richcontrol) [to be supplied.]

isinputchar (inherited from control) determines if charcode is an input character that the control wants.

isinputkey (inherited from control) determines if keydata is an input key that the control wants.

memberwiseclone (inherited from object) creates a shallow copy of the current object.

notifyinvalidate (inherited from richcontrol) [to be supplied.]

onactivated raises the activated event.

onchangeuicues (inherited from control) raises the changeuicues event.

onclick (inherited from control) raises the click event.

onclosed raises the closed event.

onclosing raises the closing event.

oncontroladded (inherited from control) raises the controladded event.

oncontrolremoved (inherited from control) raises the controlremoved event.

oncreatecontrol (inherited from control) called when the control is first created.

ondeactivate raises the deactivate event.

ondoubleclick (inherited from control) raises the doubleclick event.

ondragdrop (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.ondragdrop to send this event to any registered event listeners.

ondragenter (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.ondragenter to send this event to any registered event listeners.

ondragleave (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.ondragleave to send this event to any registered event listeners.

ondragover (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.ondragover to send this event to any registered event listeners.

onenter (inherited from control) raises the enter event.

ongivefeedback (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.ongivefeedback to send this event to any registered event listeners.

ongotfocus (inherited from richcontrol) [to be supplied.]

onhandlecreated (inherited from richcontrol) inheriting classes should override this method to find out when the handle has been created. call base.onhandlecreated first.

onhandledestroyed (inherited from richcontrol) inheriting classes should override this method to find out when the handle is about to be destroyed. call base.onhandledestroyed last.

onhelprequested (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.onhelp to send this event to any registered event listeners.

oninputlangchange raises the inputlangchange event.

oninputlangchangerequest raises the inputlangchangerequest event.

oninvalidated (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.oninvalidate to send this event to any registered event listeners.

onkeydown (inherited from control) raises the keydown event.

onkeypress (inherited from control) raises the keypress event.

onkeyup (inherited from control) raises the keyup event.

onlayout (inherited from richcontrol) core layout logic. inheriting controls should override this function to do any custom layout logic. it is not neccessary to call base.layoutcore, however for normal docking and anchoring functions to work, base.layoutcore must be called.

onleave (inherited from control) raises the leave event.

onlostfocus (inherited from richcontrol) [to be supplied.]

onmdichildactivate overloaded. [to be supplied.]

onmenucomplete raises the menucomplete event.

onmenustart raises the menustart event.

onmousedown (inherited from control) raises the mousedown event.

onmouseenter (inherited from control) raises the mouseenter event.

onmousehover (inherited from control) raises the mousehover event.

onmouseleave (inherited from control) raises the mouseleave event.

onmousemove (inherited from control) raises the mousemove event.

onmouseup (inherited from control) raises the mouseup event.

onmousewheel (inherited from control) raises the mousewheel event.

onmove (inherited from control) raises the move event.

onpaint (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.onpaint to send this event to any registered event listeners.

onpaintbackground (inherited from richcontrol) inheriting classes should override this method to handle the erase background request from windows. it is not necessary to call base.onpaintbackground, however if you do not want the default windows behavior you must set event.handled to true.

onparentpropertychanged (inherited from richcontrol) this method is called by the parent control when any property changes on the parent. this can be overriden by inheriting classes, however they must call base.onparentpropertychanged.

onpropertychanged (inherited from richcontrol) [to be supplied.]

onquerycontinuedrag (inherited from richcontrol) inheriting classes should override this method to handle this event. call base.onquerycontinuedrag to send this event to any registered event listeners.

onresize (inherited from control) raises the resize event.

onvalidated (inherited from control) raises the validated event.

onvalidating (inherited from control) raises the validating event.

parentchanged (inherited from control) called by the .net framework after a control's parent changes. this allows (for example) child controls to automatically hook events on their parent, giving better encapsulation.

processcmdkey (inherited from richcontrol) [to be supplied.]

processdialogchar (inherited from control) processes a dialog character.

processdialogkey (inherited from control) processes a dialog key.

processkeyeventargs (inherited from control) processes a key message.

processkeypreview (inherited from control) previews a keyboard message.

processmnemonic (inherited from control) processes a mnemonic character.

processtabkey (inherited from containercontrol) selects the next available control and makes it the active control.

raisedrageventargs (inherited from richcontrol) raises the event associated with key with the event data of e and a sender of this control.

raisekeyeventargs (inherited from control) raises the event associated with key with the event data of e and a sender of this control.

raisemouseeventargs (inherited from control) raises the event associated with key with the event data of e and a sender of this control.

raisepainteventargs (inherited from richcontrol) raises the event associated with key with the event data of e and a sender of this control.

raisepropertychangedevent (inherited from control) raises the property changed event. this creates the needed event data and then calls onpropertychanged.

recreatehandle (inherited from control) forces the recreation of the handle for this control. inheriting controls must call base.recreatehandle.

resumelayout (inherited from control) overloaded. resumes normal layout logic.

rtltranslatealignment (inherited from richcontrol) overloaded. [to be supplied.]

rtltranslatecontent (inherited from richcontrol) [to be supplied.]

rtltranslatehorizontal (inherited from richcontrol) [to be supplied.]

rtltranslateleftright (inherited from richcontrol) [to be supplied.]

scalecore (inherited from control) performs the work of scaling the entire control and any child controls.

sendmessage (inherited from control) overloaded. sends a win32 message to the control.

这是vb6中最有名的api消息函数了,我把这个api的中文帮助附录于下,只要第一个参数不byval hwnd as long不用就是了

declare function sendmessage& lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any)


说明
调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。sendmessagebynum, sendmessagebystring是该函数的“类型安全”声明形式
返回值
long,由具体的消息决定
参数表
参数 类型及说明
hwnd long,要接收消息的那个窗口的句柄
wmsg long,消息的标识符
wparam long,具体取决于消息
lparam any,具体取决于消息

使用如下:me.sendmessage( byval wmsg as long, byval wparam as long, lparam as any)

至如如何设定参数,就参考vb6.的一些源代码了,下面是一个拖动无标题栏窗体的用法:

private sub form1_mousedown(byval eventsender as object, byval e as system.winforms.mouseeventargs)

'mousedown的事件中窗体中的下拉列表是找不到的,自己写一个吧,加上(byval eventsender as object, byval e as system.winforms.mouseeventargs)即可

'下面的代码使窗体可以拖动

me.capture() = false '释放鼠标捕获,等同于api的releasecapture()

me.sendmessage(&ha1s, 2, 0) '唔,这个就是哪个sendmessage的api了,只是第一个句柄参数不再用了。

end sub

我们继续往下看:


setboundscore (inherited from richcontrol) [to be supplied.]

setclientsizecore (inherited from control) performs the work of setting the size of the client area of the control.

setstyle (inherited from control) sets the current value of the specified bit in the control's style. note: this is control style, not the win32 style of the hwnd.

updatebounds (inherited from control) overloaded. updates the bounds of the control.

updatestyles (inherited from control) forces styles to be reapplied to the handle. this function will call createparams to get the styles to apply.

updatezorder (inherited from control) updates this control in it's parent's zorder.

wndproc [to be supplied.]

wndprocexception (inherited from richcontrol) [to be supplied.]









二。system.drawing.bitmap的成员(bitmap members)

[注:
1.凡注明“to be supplied”是msdn准备在将来提供的空的文档,所以不翻译
2.我只能翻译一些常用项目,不是我懒,我没有任何中文的参考,如果弄错了就不太好
3.凡注明“instance”的是要求对象实例,在拙作《vb.net问题集》有详细的解释
4.其他如共享定义,基本语法等在我的系列文章中有详细的介绍,这是就不必要重复了
.................]

(一)。静态共享方法

fromhicon: creates a bitmap from a windows handle to an icon.
从一个图标的句柄构建一个bitmap对象
在vb.net中在方法中经常使用from-前缀代表从一个源得到,而使用to-前缀到一个目的对象

fromresource: [to be supplied.]

(二)对象构造器(public instance constructors)

bitmap constructor overloaded. 初始化一个新的实例(initializes a new instance of the bitmap class.)

(三)公用的对象(实例)属性(public instance properties)

flags (inherited from image) gets attribute flags for this image.

framedimensionslist (inherited from image) gets an array of guids that represent the dimensions of frames within this image.

height (inherited from image) gets the height of this image.
返回图片的高度

horizontalresolution (inherited from image) gets the horizontal resolution, in pixels-per-inch, of this image.

palette (inherited from image) gets or sets the color palette used for this image.

physicaldimension (inherited from image) gets the width and height of this image.

pixelformat (inherited from image) gets the pixel format for this image.

propertyidlist (inherited from image) gets an array of the property ids stored in this image.

propertyitems (inherited from image) gets an array of propertyitem objects that describe this image.

rawformat (inherited from image) gets the format of this image.

size (inherited from image) gets the width and height of this image.
返回图片的尺寸

verticalresolution (inherited from image) gets the vertical resolution, in pixels-per-inch, of this image.

width (inherited from image) gets the width of this imaege.
返回图片的宽度

(四)公用的对象(实例)方法

clone: (inherited from image) creates an exact copy of this image.

dispose: (inherited from image) cleans up windows resources for this image.
这个真有一点象vb6的unload,不过dispose的用处大多了,再说一篇就是清除资源占用。

equals: (inherited from object) determines whether the specified object is the same instance as the current object.

getbounds: (inherited from image) gets a bounding rectangle in the specified units for this image.

getencoderparameterlist: (inherited from image) returns information about the codecs used for this image.

getframecount: (inherited from image) returns the number of frames of the given dimension.

gethashcode: (inherited from object) serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

gethbitmap: overloaded. creates a win32 hbitmap out of the image. you are responsible for de-allocating the hbitmap with windows.deleteobject(handle). if the image uses transparency, the background will be filled with the specified background color.
得到位图句柄,这个用起来有点麻烦,好在我的文章中有了

gethicon: returns the handle to an icon
得到图标句柄

getlifetimeservice: (inherited from marshalbyrefobject) this method is used return a lifetime service object that is used to control the lifetime policy to the object. for the default lifetime service this will be an object of type ilease.

getpixel: gets the color of the specified pixel in this bitmap.
得到一个像素的color值,这个东东作用不小,不要轻看了他。

getpropertyitem: (inherited from image) gets the specified property item from this image.

getthumbnailimage (inherited from image) returns the thumbnail for this image.

gettype (inherited from object) gets the type of the object.
返回对象的类

initializelifetimeservice (inherited from marshalbyrefobject) object can provide their own lease and so control their own lifetime. they do this by overriding the initializelifetimeservice method provided on marshalbyrefobject

lockbits locks a bitmap into system memory.

maketransparent overloaded. makes a color transparent for this bitmap.

removepropertyitem (inherited from image) removes the specified property item from this image.

save (inherited from image) overloaded. saves this image to a file.
保存图片到文件

saveadd (inherited from image) overloaded. adds an encoderparameters to this image.

selectactiveframe (inherited from image) selects the frame specified by the given dimension and index.

setpixel sets the color of the specified pixel in this bitmap.
设置一个像素的color值

setpropertyitem (inherited from image) sets the specified property item to the specified value.

setresolution sets the resolution for this bitmap.

tostring (inherited from object) returns a string that represents the current object.
转到字符类

unlockbits unlocks this bitmap from system memory.

(五)族内共享的对象(实例)属性:(protected instance methods)

finalize (inherited from image) cleans up windows resources for this image.

memberwiseclone (inherited from object) creates a shallow copy of the current object.


下面使用举例说明如何使用:

新建一个工程,你会看到以下代码:

imports system.componentmodel

imports system.drawing

imports system.winforms

说明:imports(引用族名) 在c#中为using, 在c++中为namespace,作用是一样的,这仅仅是一个语法,并不是必要的调用,你完全可以不使用这个关键字,仍旧可以使用所有的族。

只是system.drawing,bitmap在使用了imports system.drawing以后你可以简写为bitmap。当然你仍旧可以写为system.drawing.bitmap

public class form1

inherits system.winforms.form

说明:inherits 是继承的意思,这样你可以象使用system.winforms.form一样使用form已有的成员

你可以这样:me.backcolor = system.drawing.color.black

me.backcolor是system.winforms.form的成员,因为继承,form1也得到了这个成员,但是因为他返回的值是色彩,而色彩是属于图形的,你应该在system.draw

中去找,结果你找到了system.drawing.color,所以me.backcolor的值的数据是system.draw.color。在color后面打点,出现提示,有你想要的色彩,与调用,修改

色彩的方法,函数。black就是黑色了,这个总比以前的十六进制要直观得多吧。如果你想声明一个变量保存这个值,一定要声明为:

dim colorval as system.drawing.color 而不是 dim colorval as string,

所有的类都可以这样声明。至于如何调用其他的一些不能直接调用的函数的问题,可以参考我的文章《vb.net问题集》

下面是一个例子:

1. 新建一个工程,可以参考我的文章《vb.net图解入门》

2. 添加picturebox控件在属性栏的backgroundimage属性中引入一幅背景图,拖动他使他比图片小一点点,

3. 设置窗体的标题栏borderstyle为0,窗体的大小与picturebox一样大

4. 请在代码开始处写入option strict off,关闭option strict使背景图片(system.drawing.image)可以使用system.drawing.bitmap类

5. 写代码如下:


protected sub picturebox1_click(byval sender as object, byval e as system.eventargs)

dim pcolor as system.drawing.color

dim strpc as string

pcolor = getpixel

strpc = pcolor.tostring

‘tostring的作用是丛system.drawing.color的数据类型转换为string类型

system.winforms.messagebox.show("当前像素的rgb" & strpc, "我的第一个vb.net程序", messagebox.ok bitor messagebox.iconasterisk)

‘messagebox是winforms的一个子类,主对话框的调用messagebox的成员凡以icom为前缀的是图标的调用

end sub

public function getpixel() as system.drawing.color

dim pm as system.drawing.bitmap

pm = picturebox1.backgroundimage

‘如果这里出错是因为没有使用option strict off

return pm.getpixel(pixx, pixy)

end function


public sub picturebox1_mousemove(byval sender as object, byval e as system.winforms.mouseeventargs) handles picturebox1.mousemove

pixx = e.x

pixy = e.y

将以上代码粘贴到#region " windows form designer generated code "到#end region这段代码的后面

按f5运行一下,这么一点代码就可以捕获图片任何一点的色彩。

如果有时vb没有能响应键盘的有些键,请重新启动,这大概是beta版的bug吧。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表