Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 覆盖PaintBackground上的子对象(将值e作为PaintEventArgs) 将背景调暗为位图 将画布变暗为图形 如果Me.DrawParent.IsDrawing那么 Bg=新位图(宽度、高度) 画布=图形。从图像(Bg) 帆布。透明(颜色。番茄色) Canvas.DrawRectangle(Pens.Red,Me.DrawParent.DrawRect) Canvas.Dispose() e、 图形.绘图图像(背景、0、0、宽度、高度) Bg.Dispose() 其他的 MyBase.OnPaintBackground(e) 如果结束 端接头 末级_.net_Vb.net_Winforms_Parent - Fatal编程技术网

.net 覆盖PaintBackground上的子对象(将值e作为PaintEventArgs) 将背景调暗为位图 将画布变暗为图形 如果Me.DrawParent.IsDrawing那么 Bg=新位图(宽度、高度) 画布=图形。从图像(Bg) 帆布。透明(颜色。番茄色) Canvas.DrawRectangle(Pens.Red,Me.DrawParent.DrawRect) Canvas.Dispose() e、 图形.绘图图像(背景、0、0、宽度、高度) Bg.Dispose() 其他的 MyBase.OnPaintBackground(e) 如果结束 端接头 末级

.net 覆盖PaintBackground上的子对象(将值e作为PaintEventArgs) 将背景调暗为位图 将画布变暗为图形 如果Me.DrawParent.IsDrawing那么 Bg=新位图(宽度、高度) 画布=图形。从图像(Bg) 帆布。透明(颜色。番茄色) Canvas.DrawRectangle(Pens.Red,Me.DrawParent.DrawRect) Canvas.Dispose() e、 图形.绘图图像(背景、0、0、宽度、高度) Bg.Dispose() 其他的 MyBase.OnPaintBackground(e) 如果结束 端接头 末级,.net,vb.net,winforms,parent,.net,Vb.net,Winforms,Parent,我不会使用formdialog方法,要让它工作会有很多麻烦,formdialog会阻止执行并等待它关闭。但是有一个解决办法。。。我会使用回调。因此,首先定义一个委托: Public Delegate Sub RegionSelectedDelegate(Region As Rectangle) 然后在调用窗体、子窗体或函数中,因为使用将破坏窗体并更改它: Dim RegionRect As Rectangle = Rectangle.Empty Dim Working As Boolean =

我不会使用formdialog方法,要让它工作会有很多麻烦,formdialog会阻止执行并等待它关闭。但是有一个解决办法。。。我会使用回调。因此,首先定义一个委托:

Public Delegate Sub RegionSelectedDelegate(Region As Rectangle)
然后在调用窗体、子窗体或函数中,因为使用将破坏窗体并更改它:

Dim RegionRect As Rectangle = Rectangle.Empty
Dim Working As Boolean = False

Public Sub GetRectangle()
    Dim Callback As RegionSelectedDelegate
    Dim Selector As New RegionSelector

    If Working Then Exit Sub 'Only one selection at once!
    Working = True
    Callback = New RegionSelectedDelegate(AddressOf RectangleDrawn)

    With Selector
        .Callback = Callback
        .Show()
    End With
    ' Don't do any stuff here... do it in Rectangle Drawn...
End Sub

该委托将从onmouseup上的绘图表单调用(当绘制矩形时),并将由RegionSelector类接收。因此,将在RegionSelector类中定义一个新的属性回调,并在onmouseup事件处理程序中调用此委托:

''' <summary>
''' Selects a region on the Screen.
''' </summary>
Public Class RegionSelector : Inherits Form

#Region " Properties "

''' <summary>
''' Callback to be invoked when drawing is done...
''' </summary>
''' <value>Delegate of Region Selected</value>
Public Property Callback As RegionSelectedDelegate = Nothing


''' <summary>
''' Gets or sets the border size of the region selector.
''' </summary>
''' <value>The size of the border.</value>
Public Property BorderSize As Integer = 2

''' <summary>
''' Gets or sets the border color of the region selector.
''' </summary>
''' <value>The color of the border.</value>
Public Property BorderColor As Color = Color.Red

''' <summary>
''' Gets the rectangle that contains the selected region.
''' </summary>
Public ReadOnly Property SelectedRegion As Rectangle
    Get
        Return Me.DrawRect
    End Get
End Property

#End Region

#Region " Objects "

''' <summary>
''' Indicates the initial location when the mouse left button is clicked.
''' </summary>
Private InitialLocation As Point = Point.Empty

''' <summary>
''' The rectangle where to draw the region.
''' </summary>
Public DrawRect As Rectangle = Rectangle.Empty

''' <summary>
''' The Graphics object to draw on the screen.
''' </summary>
Private ScreenGraphic As Graphics = Graphics.FromHwnd(IntPtr.Zero)

Public IsDrawing As Boolean = False

Dim DrawSize As Size

Dim DrawForm As Form

#End Region

#Region " Constructors "

''' <summary>
''' Initializes a new instance of the <see cref="RegionSelector"/> class.
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Initializes a new instance of the <see cref="RegionSelector" /> class.
''' </summary>
''' <param name="BorderSize">Indicates the border size of the region selector.</param>
''' <param name="BorderColor">Indicates the border color of the region selector.</param>
Public Sub New(ByVal BorderSize As Integer,
               ByVal BorderColor As Color)

    Me.BorderSize = BorderSize
    Me.BorderColor = BorderColor

End Sub

#End Region

#Region " Event Handlers "

''' <summary>
''' Handles the Load event of the RegionSelector.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
Private Sub RegionSelector_Load(sender As Object, e As EventArgs) Handles Me.Load

    Me.SuspendLayout()

    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
    Me.BackColor = System.Drawing.Color.Black
    Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
    Me.CausesValidation = False
    Me.ClientSize = New System.Drawing.Size(0, 0)
    Me.ControlBox = False
    Me.Cursor = System.Windows.Forms.Cursors.Cross
    Me.DoubleBuffered = True
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "RegionSelector"
    Me.Opacity = 0.15R
    Me.ShowIcon = False
    Me.ShowInTaskbar = False
    Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.TopMost = False
    Me.WindowState = System.Windows.Forms.FormWindowState.Maximized

    Me.ResumeLayout(True)

    Me.DrawForm = New DrawingRegionClass(Me)
    With DrawForm
        .BackColor = Color.Tomato
        .TopLevel = True
        .TransparencyKey = Color.Tomato
        .TopMost = False
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .ControlBox = False
        .WindowState = FormWindowState.Maximized
    End With

    Me.AddOwnedForm(Me.DrawForm)
    Me.DrawForm.Show()

End Sub

''' <summary>
''' Raises the <see cref="E:System.Windows.Forms.Control.MouseDown" /> event.
''' </summary>
''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)

    If e.Button = MouseButtons.Left Then

        Me.InitialLocation = e.Location
        Me.IsDrawing = True

    End If

End Sub

''' <summary>
''' Raises the <see cref="E:System.Windows.Forms.Control.MouseUp" /> event.
''' </summary>
''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
    'Do the callback here!
    Me.IsDrawing = False
    Callback.Invoke(SelectedRegion)
    Me.Close() 'Must be called last.
End Sub

''' <summary>
''' Raises the <see cref="E:System.Windows.Forms.Control.MouseMove" /> event.
''' </summary>
''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)

    If Me.IsDrawing Then

        Me.DrawSize = New Size(e.X - Me.InitialLocation.X, e.Y - Me.InitialLocation.Y)
        Me.DrawRect = New Rectangle(Me.InitialLocation, Me.DrawSize)

        If Me.DrawRect.Height < 0 Then
            Me.DrawRect.Height = Math.Abs(Me.DrawRect.Height)
            Me.DrawRect.Y -= Me.DrawRect.Height
        End If

        If Me.DrawRect.Width < 0 Then
            Me.DrawRect.Width = Math.Abs(Me.DrawRect.Width)
            Me.DrawRect.X -= Me.DrawRect.Width
        End If

        Me.DrawForm.Invalidate()

    End If

End Sub

#End Region

End Class

Public Class DrawingRegionClass : Inherits Form

Private DrawParent As RegionSelector

Public Sub New(ByVal Parent As Form)

    Me.DrawParent = Parent

End Sub

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)

    Dim Bg As Bitmap
    Dim Canvas As Graphics

    If Me.DrawParent.IsDrawing Then

        Bg = New Bitmap(Width, Height)
        Canvas = Graphics.FromImage(Bg)
        Canvas.Clear(Color.Tomato)
        Canvas.DrawRectangle(Pens.Red, Me.DrawParent.DrawRect)
        Canvas.Dispose()
        e.Graphics.DrawImage(Bg, 0, 0, Width, Height)
        Bg.Dispose()

    Else
        MyBase.OnPaintBackground(e)
    End If

End Sub

End Class
“”
''在屏幕上选择一个区域。
''' 
公共类区域选择器:继承窗体
#区域“财产”
''' 
完成绘图时要调用的“”回调。。。
''' 
所选区域的“”代表
作为RegionSelectedDelegate的公共属性回调=无
''' 
''获取或设置区域选择器的边框大小。
''' 
“边界的大小。
公共属性边框大小为整数=2
''' 
''获取或设置区域选择器的边框颜色。
''' 
''边界的颜色。
公共属性边框颜色为Color=Color.Red
''' 
''获取包含选定区域的矩形。
''' 
公共只读属性SelectedRegion为矩形
得到
还给我,DrawRect
结束
端属性
#末端区域
#区域“对象”
''' 
''表示单击鼠标左键时的初始位置。
''' 
Private InitialLocation As Point=Point.Empty
''' 
''绘制区域的矩形。
''' 
公共DrawRect作为矩形=矩形。空
''' 
''要在屏幕上绘制的图形对象。
''' 
私有屏幕图形作为图形=Graphics.FromHwnd(IntPtr.Zero)
公共IsDrawing为布尔值=False
尺寸
作为一种形式
#末端区域
#地区“建设者”
''' 
''初始化类的新实例。
''' 
公共分新()
端接头
''' 
''初始化类的新实例。
''' 
''表示区域选择器的边框大小。
''表示区域选择器的边框颜色。
Public Sub New(ByVal BorderSize为整数,
ByVal BorderColor作为颜色)
Me.BorderSize=BorderSize
Me.BorderColor=BorderColor
端接头
#末端区域
#区域“事件处理程序”
''' 
''处理RegionSelector的加载事件。
''' 
''事件的源头。
''包含事件数据的实例。
Private Sub RegionSelector_Load(发送方作为对象,e作为事件参数)处理Me.Load
Me.SuspendLayout()
Me.AutoScaleMode=System.Windows.Forms.AutoScaleMode.None
Me.BackColor=System.Drawing.Color.Black
Me.BackgroundImageLayout=System.Windows.Forms.ImageLayout.None
Me.CausesValidation=False
Me.ClientSize=新系统.Drawing.Size(0,0)
Me.ControlBox=False
Me.Cursor=System.Windows.Forms.Cursors.Cross
Me.DoubleBuffered=True
Me.FormBorderStyle=System.Windows.Forms.FormBorderStyle.None
Me.ebox=错误
Me.ebox=错误
Me.Name=“RegionSelector”
Me.不透明度=0.15R
Me.ShowIcon=False
Me.ShowInTaskbar=False
Me.SizeGripStyle=System.Windows.Forms.SizeGripStyle.Hide
Me.StartPosition=System.Windows.Forms.FormStartPosition.CenterScreen
Me.top=False
Me.WindowState=System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(真)
Me.DrawForm=新DrawingRegionClass(Me)
带抽绳
.BackColor=Color.Tomato
.TopLevel=True
.TransparencyKey=Color.Tomato
.TopMost=False
.FormBorderStyle=Windows.Forms.FormBorderStyle.None
.ControlBox=False
.WindowsState=FormWindowsState.Maximized
以
Me.AddOwnedForm(Me.DrawForm)
Me.DrawForm.Show()
端接头
''' 
''引发事件。
''' 
''包含事件数据的。
MouseDown上的受保护覆盖子对象(以鼠标指针形式显示)
如果e.按钮=鼠标按钮。左,则
Me.InitialLocation=e.Location
Me.IsDrawing=真
如果结束
端接头
''' 
''引发事件。
''' 
''包含事件数据的。
MouseUp上的受保护覆盖子对象(以鼠标为对象)
“在这里回叫!
Me.IsDrawing=False
Callback.Invoke(SelectedRegion)
必须最后调用Me.Close()。
端接头
''' 
''引发事件。
''' 
''包含事件数据的。
MouseMove上的受保护覆盖子对象(以鼠标eventargs的形式显示)
如果我在画的话
Me.DrawSize=新尺寸(e.X-Me.InitialLocation.X,e.Y-Me.InitialLocation.Y)
Me.DrawRect=新矩形(Me.InitialLocation,Me.DrawSize)
如果Me.DrawRect.Height<0,则
Me.DrawRect.Height=Math.Abs(Me.DrawRect.Height)
Me.DrawRect.Y-=Me.DrawRect.Height
如果结束
如果Me.DrawRect.Width<0,则
Me.DrawRect.Width=Math.Abs(Me.DrawRect.Width)
Me.DrawRect.X-=Me.DrawRect.Width
如果结束
Me.DrawForm.Invalidate()
如果结束
端接头
#末端区域
末级
公共类DrawingRegionClass:继承表单
作为地区选民的私人提款父母
Public Sub New(ByVal Parent作为表单)
Me.DrawParent=父母
端接头
PaintBackground上受保护的覆盖子对象(由作为PaintEventArgs的值e)
将背景调暗为位图
将画布变暗为图形
如果Me.DrawParent.IsDrawing那么
Bg=新位图(宽度、高度)
画布=图形。从图像(Bg)
Canvas.Clear(Color.Toma
Dim RegionRect As Rectangle = Rectangle.Empty
Dim Working As Boolean = False

Public Sub GetRectangle()
    Dim Callback As RegionSelectedDelegate
    Dim Selector As New RegionSelector

    If Working Then Exit Sub 'Only one selection at once!
    Working = True
    Callback = New RegionSelectedDelegate(AddressOf RectangleDrawn)

    With Selector
        .Callback = Callback
        .Show()
    End With
    ' Don't do any stuff here... do it in Rectangle Drawn...
End Sub
Public Sub RectangleDrawn(Region as Rectangle)   
    Working = false 'Allow draw again.
    Me.RegionRect=Region
    MessageBox.Show("Do next steps!")
    ' Some stuff Here
End Sub
''' <summary>
''' Selects a region on the Screen.
''' </summary>
Public Class RegionSelector : Inherits Form

#Region " Properties "

''' <summary>
''' Callback to be invoked when drawing is done...
''' </summary>
''' <value>Delegate of Region Selected</value>
Public Property Callback As RegionSelectedDelegate = Nothing


''' <summary>
''' Gets or sets the border size of the region selector.
''' </summary>
''' <value>The size of the border.</value>
Public Property BorderSize As Integer = 2

''' <summary>
''' Gets or sets the border color of the region selector.
''' </summary>
''' <value>The color of the border.</value>
Public Property BorderColor As Color = Color.Red

''' <summary>
''' Gets the rectangle that contains the selected region.
''' </summary>
Public ReadOnly Property SelectedRegion As Rectangle
    Get
        Return Me.DrawRect
    End Get
End Property

#End Region

#Region " Objects "

''' <summary>
''' Indicates the initial location when the mouse left button is clicked.
''' </summary>
Private InitialLocation As Point = Point.Empty

''' <summary>
''' The rectangle where to draw the region.
''' </summary>
Public DrawRect As Rectangle = Rectangle.Empty

''' <summary>
''' The Graphics object to draw on the screen.
''' </summary>
Private ScreenGraphic As Graphics = Graphics.FromHwnd(IntPtr.Zero)

Public IsDrawing As Boolean = False

Dim DrawSize As Size

Dim DrawForm As Form

#End Region

#Region " Constructors "

''' <summary>
''' Initializes a new instance of the <see cref="RegionSelector"/> class.
''' </summary>
Public Sub New()
End Sub

''' <summary>
''' Initializes a new instance of the <see cref="RegionSelector" /> class.
''' </summary>
''' <param name="BorderSize">Indicates the border size of the region selector.</param>
''' <param name="BorderColor">Indicates the border color of the region selector.</param>
Public Sub New(ByVal BorderSize As Integer,
               ByVal BorderColor As Color)

    Me.BorderSize = BorderSize
    Me.BorderColor = BorderColor

End Sub

#End Region

#Region " Event Handlers "

''' <summary>
''' Handles the Load event of the RegionSelector.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
Private Sub RegionSelector_Load(sender As Object, e As EventArgs) Handles Me.Load

    Me.SuspendLayout()

    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
    Me.BackColor = System.Drawing.Color.Black
    Me.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None
    Me.CausesValidation = False
    Me.ClientSize = New System.Drawing.Size(0, 0)
    Me.ControlBox = False
    Me.Cursor = System.Windows.Forms.Cursors.Cross
    Me.DoubleBuffered = True
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "RegionSelector"
    Me.Opacity = 0.15R
    Me.ShowIcon = False
    Me.ShowInTaskbar = False
    Me.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.TopMost = False
    Me.WindowState = System.Windows.Forms.FormWindowState.Maximized

    Me.ResumeLayout(True)

    Me.DrawForm = New DrawingRegionClass(Me)
    With DrawForm
        .BackColor = Color.Tomato
        .TopLevel = True
        .TransparencyKey = Color.Tomato
        .TopMost = False
        .FormBorderStyle = Windows.Forms.FormBorderStyle.None
        .ControlBox = False
        .WindowState = FormWindowState.Maximized
    End With

    Me.AddOwnedForm(Me.DrawForm)
    Me.DrawForm.Show()

End Sub

''' <summary>
''' Raises the <see cref="E:System.Windows.Forms.Control.MouseDown" /> event.
''' </summary>
''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)

    If e.Button = MouseButtons.Left Then

        Me.InitialLocation = e.Location
        Me.IsDrawing = True

    End If

End Sub

''' <summary>
''' Raises the <see cref="E:System.Windows.Forms.Control.MouseUp" /> event.
''' </summary>
''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
    'Do the callback here!
    Me.IsDrawing = False
    Callback.Invoke(SelectedRegion)
    Me.Close() 'Must be called last.
End Sub

''' <summary>
''' Raises the <see cref="E:System.Windows.Forms.Control.MouseMove" /> event.
''' </summary>
''' <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs" /> that contains the event data.</param>
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)

    If Me.IsDrawing Then

        Me.DrawSize = New Size(e.X - Me.InitialLocation.X, e.Y - Me.InitialLocation.Y)
        Me.DrawRect = New Rectangle(Me.InitialLocation, Me.DrawSize)

        If Me.DrawRect.Height < 0 Then
            Me.DrawRect.Height = Math.Abs(Me.DrawRect.Height)
            Me.DrawRect.Y -= Me.DrawRect.Height
        End If

        If Me.DrawRect.Width < 0 Then
            Me.DrawRect.Width = Math.Abs(Me.DrawRect.Width)
            Me.DrawRect.X -= Me.DrawRect.Width
        End If

        Me.DrawForm.Invalidate()

    End If

End Sub

#End Region

End Class

Public Class DrawingRegionClass : Inherits Form

Private DrawParent As RegionSelector

Public Sub New(ByVal Parent As Form)

    Me.DrawParent = Parent

End Sub

Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)

    Dim Bg As Bitmap
    Dim Canvas As Graphics

    If Me.DrawParent.IsDrawing Then

        Bg = New Bitmap(Width, Height)
        Canvas = Graphics.FromImage(Bg)
        Canvas.Clear(Color.Tomato)
        Canvas.DrawRectangle(Pens.Red, Me.DrawParent.DrawRect)
        Canvas.Dispose()
        e.Graphics.DrawImage(Bg, 0, 0, Width, Height)
        Bg.Dispose()

    Else
        MyBase.OnPaintBackground(e)
    End If

End Sub

End Class