1、单击picturebox时如何获得鼠标所指处的颜色!
2、当picturebox的大小发生变化时,图片也随之变化!
哪位给解决一下,谢谢。
2、当picturebox的大小发生变化时,图片也随之变化!
哪位给解决一下,谢谢。
解决方案 »
- VB 5.0的report控件在6里可以用什么控件代替
- 请问运算这题的具体是怎样的?使用VB中断功能仍然有些不明白的地方
- 如何在媒体播放器程序中计算视频或音频的播放时间和文件大小
- 为什么保存工程时,出现的对话框"保存类型"栏出现中文乱码?并且”文件名“栏不能转成中文输入法输入中文,有什么解决办法没有?
- MSHFlexGrid数据格式问题
- 数据库的书签到底是怎样一个变量?
- 如何同时把一个窗体及其上的某一个控件作为参数传递?!
- 这个程序很有意义!!! 关于VB中引用EXCEL
- 初学者:我看不懂英文,怎么办?
- 使用VBA语句实现根据条件判断弹出提示框功能
- ACCESS会不会丢失记录??
- ListView 的行高有没办法调整?
'获得鼠标所指的颜色:
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Sub Picture1_Click()
Static lX As Long, lY As Long
On Local Error Resume Next
Dim P As POINTAPI, h As Long, hD As Long, c As Long
Dim R As Long, G As Long, B As Long
GetCursorPos P
If P.x = lX And P.y = lY Then Exit Sub
lX = P.x: lY = P.y
h = WindowFromPoint(lX, lY)
hD = GetDC(h)
ScreenToClient h, P c = GetPixel(hD, P.x, P.y) R = c And &HFF
G = (c And &HFF00&) / &H100&
B = (c And &HFF0000) / &H10000
Me.BackColor = RGB(R, G, B)
End Sub
Point 方法
按照长整数,返回在 Form 或 PictureBox 上所指定磅的红-绿-蓝 (RGB) 颜色。不支持命名参数。语法object.Point(x, y)Point 方法的语法包含下列部分:部分 描述
object 可选的。一个对象表达式,其值为“应用于”列表中的一个对象。如果省略 object,带有焦点的 Form 象缺省为 object.
x, y 必需的。均为单精度值,指示 Form 或 PictureBox 的 ScaleMode 属性中该点的水平(x-轴)和垂直(y-轴)坐标。必须用括号包括这些值。
说明如果由 x 和 y 坐标所引用的点位于 object 之外,Point 方法将返回 -1。
Point 方法示例
本示例使用 Point 方法来确定一个窗体上的一个指定点的颜色。要检验此示例,可将本例代码粘贴到一个窗体的声明部分,然后按 F5 键并单击该窗体。Private Sub Form_Click ()
Dim LeftColor, MidColor, Msg, RightColor ' 声明变量。
AutoRedraw = -1 ' 打开AutoRedraw。
Height = 3 * 1440 ' 将高度设置为 3 英寸。
Width = 5 * 1440 ' 将宽度设置为 5 英寸。
BackColor = QBColor(1) ' 将背景设置为蓝色。
ForeColor = QBColor(4) ' 将前景设置为红色。
Line (0, 0)-(Width / 3, Height), , BF ' 红框。
ForeColor = QBColor(15) ' 将前景设置为白色。
Line (Width / 3, 0)-((Width / 3) * 2, Height), , BF
LeftColor = Point(0, 0) ' 查找左框颜色,,
MidColor = Point(Width / 2, Height / 2) ' 中框, 和
RightColor = Point(Width, Height) ' 右框。
Msg = "The color number for the red box on the left side of "
Msg = Msg & "the form is " & LeftColor & ". The "
Msg = Msg & "color of the white box in the center is "
Msg = Msg & MidColor & ". The color of the blue "
Msg = Msg & "box on the right is " & RightColor & "."
MsgBox Msg ' 显示信息。
End Sub
算出picturebox的大小变化的比率,然后用PaintPicture重画图像
long = picture1.point(100,100)'获取坐标为100,100的颜色
picure1.paint(loadicture(path),0,0,piture1.scalewidth,picture1.scaleheight)
'使图片筐重画
用picture1.paintpicture LoadPicture(filename), 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight来调整图片大小
x,y通过picture1的MouseDown与MouseUp事件都可取得zdcwin(赵大成)说得对,就这么简单!paintpicture方法可放在Picture1_Resize事件中并不是什么都用API好,GetPixel取一个点的颜色更适于对付外部进程,用在自己程序内部并不会比point快,反会绕个大圈子。