i have written small programs which draws the rectangle on the picture box
here i m using two forms
form1 for drawing
form2 for toolbox for rectangle
first problem is that how can i get background color of picColor bcoz when select color so rectangle should be in that color so i m using this code
for drawing button
Code:
Dim LocX, LocY As Integer
    Dim width, height As Integer
    Dim color As ColorDialog
    Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
        Dim brush As Pen
        Dim g As Graphics
        LocX = nudX.Value
        LocY = nudY.Value
        width = nudWidth.Value
        height = nudHeight.Value

        Dim rect As New Rectangle(LocX, LocY, width, height)
        g = frmDrawing.picDrawing.CreateGraphics
        g.DrawRectangle(Pens.Brown, rect)
    End Sub

Private Sub picColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picColor.Click
        If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            picColor.BackColor = ColorDialog1.Color
        End If
    End Sub
so second problem is that as long i changes values in numeric up down control so it shows strange behaviour
rectangle should be moved as i change value but here rectangle is filling
and similary when i change height and width, the problem is same
this is the code here
Code:
Private Sub nudX_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudX.ValueChanged
        Dim brush As Pen
        Dim g As Graphics
        LocX = nudX.Value
        LocY = nudY.Value
        width = nudWidth.Value
        height = nudHeight.Value

        Dim rect As New Rectangle(LocX, LocY, width, height)
        g = frmDrawing.picDrawing.CreateGraphics
        g.DrawRectangle(Pens.Brown, rect)
    End Sub

    Private Sub nudY_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudY.ValueChanged
        Dim brush As Pen
        Dim g As Graphics
        LocX = nudX.Value
        LocY = nudY.Value
        width = nudWidth.Value
        height = nudHeight.Value

        Dim rect As New Rectangle(LocX, LocY, width, height)
        g = frmDrawing.picDrawing.CreateGraphics
        g.DrawRectangle(Pens.Brown, rect)
    End Sub

    Private Sub nudWidth_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudWidth.ValueChanged
        Dim brush As Pen
        Dim g As Graphics
        LocX = nudX.Value
        LocY = nudY.Value
        width = nudWidth.Value
        height = nudHeight.Value

        Dim rect As New Rectangle(LocX, LocY, width, height)
        g = frmDrawing.picDrawing.CreateGraphics
        g.DrawRectangle(Pens.Brown, rect)
    End Sub
third problem is that as long i move toolbox over drawn shapes,these are erased
when i first run my program and changes values in numeric up down control so nothing is done and if i once click on draw then these values are changed
how can i solve these problems
thanks