تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] معرفة الفورم الذي تم وضع عليه الاداة
#1
السلام عليكمورحمة الله
عند صناعة اداة جديدة اريد ان اعرف الفورم الذي تم وضع الاداة عليه لاقوم بعمل تغيرات به
عند صناعة UserControl كنت استخدم ParentForm
انما لو انا بعمل كمبو بوكس مثلا لم اجد ParentForm
وجزاكم الله خيرا


قمة الاستعباط ومحدش يضحك عليا

كود :
Public Class Class1

    Inherits ComboBox

    Private _ParentForm As Form
    Public Property ParentForm() As Form
        Get
            Return _ParentForm
        End Get
        Set(ByVal value As Form)
            _ParentForm = value
        End Set
    End Property


    Public WithEvents dd As New UserControl

    Public Sub New()
        With dd
            .Visible = False
            .Size = New Size(0, 0)
            .Show()
        End With
        Me.Controls.Add(dd)
    End Sub

    Private Sub dd_Load(sender As Object, e As EventArgs) Handles dd.Load
        Me.ParentForm = dd.ParentForm
    End Sub

End Class

الموضع كده بقي حكاية

كود :
Public Class Class1

    Inherits ComboBox

    Private _ParentForm As Form
    ''' <summary>الفورم الذي تم وضع الاداة عليه</summary>
    Public Property ParentForm() As Form
        Get
            Return _ParentForm
        End Get
        Set(ByVal value As Form)
            _ParentForm = value
        End Set
    End Property


    Private WithEvents UserContro As New UserControl With {.Size = New Size(0, 0), .Visible = False}

    Public Sub New()
        UserContro.Show()
        Me.Controls.Add(UserContro)
    End Sub

    Private Sub UserContro_Load(sender As Object, e As EventArgs) Handles UserContro.Load
        Me.ParentForm = UserContro.ParentForm
    End Sub

End Class
الرد }}}
تم الشكر بواسطة:
#2
كود :
Dim cntrl as Control =  Me.Parent
        Do While(Not cntrl Is  Nothing)
            If typeof(cntrl) is Form Then
                exit do
            Else
                cntrl =  cntrl.Parent                
            End If
            
        loop
        if not cntrl is  nothing then MsgBox (cntrl.Name )
الرد }}}
تم الشكر بواسطة: ali.alfoly
#3
كود :
' This example uses the Parent property and the Find method of Control to set
    ' properties on the parent control of a Button and its Form. The example assumes
    ' that a Button control named button1 is located within a GroupBox control. The  
    ' example also assumes that the Click event of the Button control is connected to
    ' the event handler method defined in the example.
    Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        ' Get the control the Button control is located in. In this case a GroupBox.
        Dim control As Control = button1.Parent
        ' Set the text and backcolor of the parent control.
        control.Text = "My Groupbox"
        control.BackColor = Color.Blue
        ' Get the form that the Button control is contained within.
        Dim myForm As Form = button1.FindForm()
        ' Set the text and color of the form containing the Button.
        myForm.Text = "The Form of My Control"
        myForm.BackColor = Color.Red
    End Sub
الرد }}}
تم الشكر بواسطة:



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم