Location for dialog box

hi ....

I have create a UserControl (ColorPicker) that have a button that when it clicked it will create form and use it as dialog box

everything work fine but my problem is am trying to set the location of dialog box

I try to change the parent of dialog box and I have no luck on it

also I try to set the location and it's did not accepted

Public Class ColorPicker

Private Frm As New Windows.Forms.Form

Private Sub ColorPicker_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

With Frm

.Size = New Drawing.Size(189, 197)

.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog

.ControlBox = False

.AutoSize = True : .AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink

.Location = New Drawing.Point(X, Y)

End With

End Sub

Private Sub ColorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorButton.Click, ColorBox.Click

Frm.ShowDialog()

End Sub

End Class

I need to set X, Y location under the buttom location



Answer this question

Location for dialog box

  • SureshGubba

    Set the location when the button is clicked, not when the Load event runs. That's too early and you'll use the location where the form was originally located, not where it is now located.


  • i-code-4-fun

    Thanks nobugz

    it's work like what you said


  • IRANEW

    This worked for me:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim frm As New Form
    With frm
    .Location = Me.PointToScreen(New Point(Button1.Left, Button1.Bottom))
    .StartPosition = FormStartPosition.Manual
    .Size = New Size(189, 197)
    .FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
    .ControlBox = False
    .ShowDialog()
    End With
    End Sub



  • Mike Hildner

    It,s work when I start the application and click the button but when I start the application and move it and then click the button it's show in the first position of the button before the application moved
  • Location for dialog box