我如何称呼我的私人子 [英] How Do I Call My This Private Sub

查看:139
本文介绍了我如何称呼我的私人子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

这里我使用数据网格视图行post post为我的datagridview设置行图标,例如:





Hi all
here i use data grid view row post paint to set a row icons for my datagridview , for example:


Private Sub DataGridView1_RowPostPaintRed( _
    ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) _
    Handles DataGridView1.RowPostPaint




For Each row As DataGridViewRow In DataGridView1.Rows




Dim myBitmap As New Bitmap(ImageList1.Images(0))
            Dim myIcon As Icon = Icon.FromHandle(myBitmap.GetHicon())
            Dim graphics As Graphics = e.Graphics
            Dim iconHeight As Integer = 14
            Dim iconWidth As Integer = 14
            Dim xPosition As Integer = e.RowBounds.X + (DataGridView1.RowHeadersWidth \ 2)
            Dim yPosition As Integer = e.RowBounds.Y + ((DataGridView1.Rows(e.RowIndex).Height - iconHeight) \ 2)
            Dim rectangle As New Rectangle(xPosition, yPosition, iconWidth, iconHeight)
            graphics.DrawIcon(myIcon, rectangle)





在这个私人子目录中我使用我的第一张图片列表(红色)





我的问题是:

我如何在这个子中使用私人潜艇:



in this private sub i use my 1st image from image list (Red)


My question is :
how can i use that private subs in this sub :

Private Sub myUpdate(ByVal str As String)
        Dim jo As JObject = JObject.Parse(str), temp As String, val As String
        For Each row As DataGridViewRow In DataGridView1.Rows
            temp = row.Cells(0).Value.ToString
            val = jo(temp)
            If row.Cells(1).Value < val Then
                '--
            Else
                ' call red private sub (above)

            End If
            row.Cells(1).Value = val
            row.Cells(2).Value = fractionPart(2, val)
        Next
    End Sub

推荐答案

您通常不直接调用事件处理程序subs - 您将创建一个两个subs调用的方法。但在这种情况下,您无法轻松完成此操作,因为您的代码使用Graphics上下文来进行绘制。虽然您可以自己创建上下文(并在完成或者讨厌的事情开始发生时将其公开),但使用此方法进行复制的最佳方法是使系统引发事件:调用DataGridView.Invalidate方法并强制重新启动-paint,这将导致引发绘制后的行事件并自动执行代码。
You don't normally call event handler subs directly - you would create a method which both subs call instead. In this case though, you can't easily do that because your code uses the Graphics context in order to do the drawing. While you could create the context yourself (and Dispose it when you have finished or nasty things start happening) the best way to copy with this is to cause the system to raise the event: call the DataGridView.Invalidate method and it will force a re-paint, which will result in the row post-paint event being raised and your code executed automatically.


这篇关于我如何称呼我的私人子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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