vb.net中的画线 [英] Drawing line in vb.net

查看:327
本文介绍了vb.net中的画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am trying to use the following code in a button. I want to call DrawLineFloat. I tried call DrawLineFloat() but it did not work. What do I need to enter in ()?

Thanks





Public Sub DrawLineFloat(ByVal e As PaintEventArgs)
    '' Create pen.
    Dim blackPen As New Pen(Color.Black, 3)
    '' Create coordinates of points that define line.
    Dim x1 As Single = 100.0F
    Dim y1 As Single = 100.0F
    Dim x2 As Single = 500.0F
    Dim y2 As Single = 100.0F
    '' Draw line to screen.
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
End Sub

推荐答案

在没有看到更多代码的情况下,很难看到出错的地方.

基本上,您将需要处理按钮的"Paint"事件.当您执行此操作时,就可以绘制文本,边框等.作为下面的示例,此简单的按钮将处理Paint事件,并调用例程.


Without seeing more of your code, it''s hard to see where you''re going wrong.

Basically, you''re going to need to handle the "Paint" event for your button. When you do that, you''ll be able to paint your text, borders, etc. As an example below, this simple button will handle the Paint event, and call your routine.


Public Class MyButton
    Inherits Button

    Private Sub MyButton_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        DrawLineFloat(e)
    End Sub

    Public Sub DrawLineFloat(ByVal e As PaintEventArgs)
        ' Create pen.
        Dim blackPen As New Pen(Color.Black, 3)
        ' Create coordinates of points that define line.
        Dim x1 As Single = 100.0F
        Dim y1 As Single = 100.0F
        Dim x2 As Single = 500.0F
        Dim y2 As Single = 100.0F
        ' Draw line to screen.
        e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)
    End Sub
End Class


这篇关于vb.net中的画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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