VB中的可拖动对象 [英] Dragable object in VB

查看:112
本文介绍了VB中的可拖动对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一头牛的照片。我想把她拖到窗户周围。我拖着她的时候想见她。我不想跟她一起拖动整个矩形的背景颜色。



在Windows Forms应用程序中,有没有办法在Visual Basic中的任何地方执行此操作?

I have a picture of a cow. I want to drag her around the window. I want to see her while I drag her. I do not want to drag a whole rectangle of background color with her.

Is there any way to do this anywhere in Visual Basic in Windows Forms application?

推荐答案

这是一个带有真实透明背景的自定义PictureBox。



This is a customized PictureBox with a "real" transparent Background.

Public Class customPictureBox
    Inherits PictureBox


    Public Sub New()

        Me.SetStyle(ControlStyles.Opaque, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
        Me.SetStyle(ControlStyles.ResizeRedraw, True)

    End Sub

    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or &H20  ' Turn on WS_EX_TRANSPARENT
            Return cp
        End Get
    End Property

    Protected Overrides Sub OnPaint(pe As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(pe)

        If MyBase.BackgroundImage IsNot Nothing Then
            pe.Graphics.DrawImage(MyBase.BackgroundImage, 0, 0)
        End If

    End Sub

End Class

< br $> b $ b

不幸的是,由于覆盖了OnPaint方法,所有想要的绘画作品现在必须由你自己完成 - 这包括绘画的图像。在我的例子中,我用它的原始大小绘制图像 - 但当然也可以进行缩放(调整大小)等等 - 但现在手动...... :(



Unfortunately, because of overiding the OnPaint-method, all wanted painting work now must be done by yourself - this includes the painting of the image. In my example I draw the image in it's original size - but certainly it is possible to do also scaling (resizing) and so on - but now manually ... :(


这篇关于VB中的可拖动对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆