Click here to Skip to main content
15,671,597 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
SQL
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
Posted

1 solution

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.


VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900