How do I use the Graphics.Drawline function in the middle of another function on my form.
What I want to do is just draw an X across part of my form, but where, and what size changes.
I think my problem is in creating the graphics object. What I did was create a global graphics variable called '_graphics' and in the myBase.Paint event I set that global variable to the forms graphics object:
Then in my function I create a pen, and try to draw my two lines:VB Code:
Private Sub Panel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint _graphics = e.Graphics End Sub
When it gets to the first _graphics.DrawLine(...) I get an error stating "Invalid Paramater Used".VB Code:
Private Sub DrawBlock(ByVal Cir As Circuit) Dim pen As Pen = New Pen(Color.Black, 1) Dim _Left As Integer = Cir.Left Dim _Right As Integer = Cir.Left + Cir.Width Dim _Top As Integer = Cir.Top Dim _Bottom As Integer = Cir.Top + Cir.Height _graphics.DrawLine(pen, _Left, _Top, _Right, _Bottom) _graphics.DrawLine(pen, _Left, _Bottom, _Right, _Top) End Sub
Any Ideas? I'm likely just using the graphics class wrong.




Reply With Quote