2013-10-08 49 views
2

我想我的問題很簡單,但我沒有找到任何答案。在用戶控件中繪製一條簡單的線

我有一個帶有MainForm和Button的按鈕(btn1)和一個UserControl(uc1)的vb.Net項目。

我想要的全部是當我點擊btn1時使用graphics類的簡單線條uc1。 謝謝。

回答

3

在你的用戶控件創建一個方法來畫線:

Public Class MyUserControl 
    Public Sub DrawLine() 
     Using g As Graphics = Me.CreateGraphics 
      g.DrawLine(Pens.Blue, New Point(10, 10), New Point(100, 50)) 
     End Using 
    End Sub 
End Class 

然後從你點擊按鈕調用此:

Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click 
    MyUserControl1.DrawLine() 
End Sub 

這是一個簡單的解決方案,但你可能要do all your drawing in the paint event of the usercontrol

+0

乾杯!非常非常感謝你。 –

+0

不客氣 - 不要忘記註冊答案和/或接受適當的答案(如果可以的話) –